Ordered Creation and Deletion

Learn how StatefulSets start and stop Pods in a controlled and ordered way.

We'll cover the following

A critical difference between StatefulSets and Deployments is the way they create Pods.

  • StatefulSets create one Pod at a time and wait for it to be running and ready before starting the next.

  • Deployments use a ReplicaSet controller to start all Pods at the same time, which can result in race conditions.

If we assume the previous YAML again, tkb-sts-0 will be started first and must be running and ready before the StatefulSet controller starts tkb-sts-1. The same applies to subsequent Pods — tkb-sts-1 needs to be running and ready before tkb-sts-2 starts etc. Let's have a look at the following figure:

Get hands-on with 1400+ tech skills courses.