Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Start one pod at a time when replica is greater than one

Is there a way to ensure that pods are scaled one at a time when setting replica greater than one?

Example: Replica set to 3

  1. Pod 1 - Initializing , pod 2 - Waiting, pod 3 - Waiting
  2. Pod 1 - Running , pod 2 - Initializing, pod 3 - Waiting
  3. Pod 1 - Running , pod 2 - Running, pod 3 - Initializing
  4. Pod 1 - Running , pod 2 - Running, pod 3 - Running
like image 268
TruBlu Avatar asked Oct 29 '25 15:10

TruBlu


1 Answers

You can acomplish this behavior using StatefulSets. As it goes from Kubernetes docs

  • For a StatefulSet with N replicas, when Pods are being deployed, they are created sequentially, in order from {0..N-1}.
  • When Pods are being deleted, they are terminated in reverse order, from {N-1..0}.
  • Before a scaling operation is applied to a Pod, all of its predecessors must be Running and Ready.
  • Before a Pod is terminated, all of its successors must be completely shutdown.

So, as you can see here, new pod is not booted up until previous one is initializing.

Note: this behavior is guranteed by Kubernetes when OrderedReady pod management policy is used (which is default).

like image 50
geobreze Avatar answered Oct 31 '25 13:10

geobreze



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!