Deployment vs StatefulSet
Compare the Kubernetes controllers for stateless and stateful workloads.
| Dimension | Deployment | StatefulSet | What it means in practice |
|---|---|---|---|
| Pod identity | Random Pod names; Pods are interchangeable. | Stable names <name>-0, <name>-1. | Use StatefulSets when members must know each other by name. |
| Storage | Shared or no PVCs; all replicas use the same claim if any. | One PVC per Pod from volumeClaimTemplates. | StatefulSet PVCs are kept when Pods or the set are deleted. |
| Ordering | Pods start and stop in parallel. | Ordered start, stop and update (by default). | Ordered rollouts are slower but safer for clustered databases. |
| Network identity | Reached through a normal Service. | Headless Service gives per-Pod DNS names. | Per-Pod DNS is <pod>.<service>.<ns>.svc.cluster.local. |
| Scaling | Fast; any Pod can be removed. | Removes the highest ordinal first. | Scaling down does not delete data. |
| Verification | kubectl rollout status deployment/<name> | kubectl rollout status statefulset/<name>; kubectl get pvc | Check each StatefulSet Pod has its own Bound PVC. |