Pcornel
Browse topics
Options
Recent
Favorites
Containers · Technical reference

StatefulSets

Direct answer

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.

When to use this

Use it for databases and clustered apps that need stable identity and storage.

First 30 seconds

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.

Operational verification

ordinal pods created in order → each with its PVC → stable DNS

Context & applicabilityCommon mistakes · platform/version boundaries
Platform / version applicability
Docker / containerd / Podman / Kubernetes / OCI-compatible platforms
applies
Structured applicability is explicit Topic metadata; it does not infer compatibility beyond the stored rows.
At a glance

Operational reference

Fast context before you go deeper.

PlatformDocker / containerd / Podman / Kubernetes / OCI-compatible platforms
Scope / prerequisiteUse it for databases and clustered apps that need stable identity and storage.
What next?2 suggested next steps
Evidence0
On this pageJump to a specific section
Operational workflow

Verification & Troubleshooting

Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.

2 steps Observe → verify → isolate → change minimally → repeat the original test.
ObservedRecord what the original test actually shows

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.

Key points

Pods start in order; a stuck pod blocks the next. Deleting a StatefulSet keeps PVCs. Scaling down does not delete data.

Key checks
  • kubectl get sts,pods,pvc -l <selector> — first check for this topic
  • kubectl get pods -o wide — pods, status, node, IP
  • kubectl describe pod <pod> — events and conditions
  • kubectl 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.
  • volumeClaimTemplates give 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

SettingBehaviour
podManagementPolicy: OrderedReady (default)Create 0,1,2… one at a time, each Ready before the next; delete in reverse
podManagementPolicy: ParallelCreate and delete all at once (still stable names and volumes)
updateStrategy: RollingUpdateReplace Pods from the highest ordinal down
rollingUpdate.partition: 2Only 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.

Source basisSource attribution states what this section is based on; it is not independent proof that the current environment matches it.

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
Terminology layer

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.

Aliases that resolve here
statefulsetsstatefulset volumeclaimtemplatesheadless service
Confirmation

Confirm action

Continue?