Use it for databases and clustered apps that need stable identity and storage.
StatefulSets
A StatefulSet runs pods with stable names (app-0, app-1), stable network identities via a headless Service, and one PersistentVolumeClaim per pod, created and updated in order.
1. kubectl get sts,pods,pvc -l <selector>.
2. Which ordinal is stuck? describe it.
3. PVC Bound for each pod?
4. Headless Service DNS: <pod>.<svc>.
5. Update strategy and partition.
ordinal pods created in order → each with its PVC → stable DNS
Context & applicabilityCommon mistakes · platform/version boundaries
Operational reference
Fast context before you go deeper.
Verification & Troubleshooting
Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.
Use the operational verification above to establish the expected state.
Capture the concrete output, symptom, packet, log or counter before changing anything.
Step 1 How to verify Verify boundary
Confirm each Pod has its own Bound PVC. Test that the application cluster sees each member by its stable name. Check the update strategy and partition before changing the template.
Step 2 Common failures Narrow the fault
Scaling down does not delete PVCs, so data remains and costs storage. A Pod stuck not-ready blocks the rest of an ordered rollout. Using a normal Service instead of a headless one removes per-Pod DNS names.
Pods start in order; a stuck pod blocks the next. Deleting a StatefulSet keeps PVCs. Scaling down does not delete data.
kubectl get sts,pods,pvc -l <selector>— first check for this topickubectl get pods -o wide— pods, status, node, IPkubectl describe pod <pod>— events and conditionskubectl logs <pod> [-c <c>] [--previous]— container logs (incl. previous crash)kubectl get events --sort-by=.lastTimestamp— recent cluster events
ReferenceWhat it is1 section · depth on demand
How it works
The StatefulSet controller creates Pods one at a time in order (by default) and waits for each to be ready. Updates go in reverse order. Deleting a Pod recreates it with the same name and the same PVC, possibly on another node.
ReferenceImportant terms & boundaries3 sections · depth on demand
StatefulSet behaviour
- Pods named
db-0,db-1… created and terminated in order. - Stable DNS through a headless Service:
db-0.db.app.svc.cluster.local. volumeClaimTemplatesgive each Pod its own PVC, kept when Pods are rescheduled or the StatefulSet is scaled down.
Use for databases and clustered apps that need identity. Deleting a StatefulSet does not delete its PVCs (by default); clean them up deliberately.
In depth
A StatefulSet gives each replica a stable identity: a fixed name (db-0, db-1 …), a stable DNS name through a headless Service, and its own PersistentVolumeClaim from volumeClaimTemplates that follows the Pod when it is rescheduled.
Ordering options
| Setting | Behaviour |
|---|---|
podManagementPolicy: OrderedReady (default) | Create 0,1,2… one at a time, each Ready before the next; delete in reverse |
podManagementPolicy: Parallel | Create and delete all at once (still stable names and volumes) |
updateStrategy: RollingUpdate | Replace Pods from the highest ordinal down |
rollingUpdate.partition: 2 | Only ordinals ≥ 2 are updated — a canary for stateful apps |
Worked canary update
kubectl patch sts db -p '{"spec":{"updateStrategy":{"rollingUpdate":{"partition":2}}}}'
kubectl set image sts/db db=postgres:17.2
kubectl get pods -l app=db -L controller-revision-hash # only db-2 on the new revision
kubectl patch sts db -p '{"spec":{"updateStrategy":{"rollingUpdate":{"partition":0}}}}'
Volumes are kept on scale-down
Scaling from 3 to 2 deletes db-2 but keeps data-db-2; scaling back up reattaches it. persistentVolumeClaimRetentionPolicy (whenScaled, whenDeleted: Retain or Delete) changes that.
What a StatefulSet does not do
It does not set up replication, elect a primary or move data. The database or its operator must handle membership; the StatefulSet only provides stable names and disks.
Common mistakes
- Scaling StatefulSets without understanding ordering and PVCs.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Terms & aliases
Hover a linked term for a quick definition; click it to open its glossary entry. Aliases are other names that find this Topic in search.