How Does Ordered Deployment Work in StatefulSets?
By default, StatefulSets create Pods sequentially in ascending ordinal order (0, 1, 2...) and terminate them in reverse order (2, 1, 0). Each Pod must be Running and Ready before the next is created. This ordering guarantees safe initialization for clustered applications.
Detailed Answer
Ordered deployment is one of the defining features of StatefulSets. It ensures that Pods are created, updated, and deleted in a predictable sequence, which is essential for applications that have initialization dependencies.
The Default Behavior: OrderedReady
When you create a StatefulSet with replicas: 3, Kubernetes does not launch all three Pods at once. Instead:
- Pod-0 is created first
- Kubernetes waits until Pod-0 is Running and Ready (all readiness probes pass)
- Pod-1 is created
- Kubernetes waits until Pod-1 is Running and Ready
- Pod-2 is created
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: etcd
spec:
serviceName: "etcd-headless"
replicas: 3
podManagementPolicy: OrderedReady # This is the default
selector:
matchLabels:
app: etcd
template:
metadata:
labels:
app: etcd
spec:
containers:
- name: etcd
image: quay.io/coreos/etcd:v3.5.12
ports:
- containerPort: 2379
name: client
- containerPort: 2380
name: peer
readinessProbe:
httpGet:
path: /health
port: 2379
initialDelaySeconds: 10
periodSeconds: 5
resources:
requests:
cpu: "500m"
memory: "512Mi"
limits:
cpu: "1"
memory: "1Gi"
Why Ordering Matters
Consider an etcd cluster:
etcd-0starts and initializes a new cluster as the sole memberetcd-1starts and joins the cluster by contactingetcd-0etcd-2starts and joins by contacting the existing members
If all three started simultaneously, they might each try to form their own cluster, leading to a split-brain scenario.
Termination Order
Deletion happens in reverse ordinal order:
etcd-2is terminated first- Once fully stopped,
etcd-1is terminated - Finally,
etcd-0is terminated
This protects the primary/leader (typically ordinal 0) by ensuring it is the last to go, giving the cluster time to handle member removal gracefully.
Scaling Behavior
The same ordering applies to scaling:
Scale up (3 → 5):
- Pod-3 is created and must be Ready before Pod-4 is created
Scale down (5 → 3):
- Pod-4 is terminated and must fully stop before Pod-3 is terminated
# Scale up — Pods are added in order
kubectl scale statefulset etcd --replicas=5
# Watch the ordered creation
kubectl get pods -l app=etcd -w
# etcd-3 0/1 Pending 0 0s
# etcd-3 1/1 Running 0 15s
# etcd-4 0/1 Pending 0 0s
# etcd-4 1/1 Running 0 12s
When a Pod Gets Stuck
If Pod-1 fails to become Ready during initial creation or scaling:
- Pod-2 is never created
- The StatefulSet reports a condition indicating the blocked state
- Manual intervention is required (fix the Pod, check probes, examine logs)
# Check why a Pod is not Ready
kubectl describe pod etcd-1
kubectl logs etcd-1
# Check StatefulSet status
kubectl get statefulset etcd -o yaml | grep -A 5 conditions
Overriding the Order
If your application does not need ordered deployment, you can use Parallel pod management policy (covered in the related question on pod management policies). This is useful for workloads that need stable identity and storage but not ordered startup — like some cache clusters.
Why Interviewers Ask This
Interviewers ask this to confirm you understand why ordering matters for stateful workloads and how it affects deployment speed and reliability.
Common Follow-Up Questions
Key Takeaways
- OrderedReady is the default pod management policy — Pods are created one by one in order.
- Termination happens in reverse ordinal order to safely drain secondary replicas first.
- A single stuck Pod blocks the entire rollout, which is intentional for safety.