How to schedule the first replica of a statefulset to a specific node

4/23/2021

I have a StatefulSet with several replicas, for example 3 and multiple kubernetes Node in two zones.

I want to place the FIRST replica in the selected zone and the rest in the others zones.

  • mysts-0-0 < main_zone
  • mysts-0-1 < back_zone
  • mysts-0-2 < back_zone

Why the first one? Each pod is a database instance. Replication is configured between them. And by default the first node is master.

So I want to be able to influence where the first node is installed.

-- jesmart
kubernetes
kubernetes-pod
kubernetes-statefulset

1 Answer

4/23/2021

This is not supported in StatefulSet, as the Pod-template is identical for each replica.

You might be able to achieve this by writing a custom scheduler. For inspiration, see this article for a custom scheduler for CockroachDB: A Custom Kubernetes Scheduler to Orchestrate Highly Available Applications

-- Jonas
Source: StackOverflow