What Is a Kubernetes StatefulSet? Stable Pod identity and storage
A Kubernetes StatefulSet manages Pods whose identities and ordering remain predictable across rescheduling. Pods receive ordinal names such as `web-0` and can keep a matching PersistentVolumeClaim (PVC), so the same logical replica can reconnect to its storage. This does not make Kubernetes replicate or back up application data. If Pods are interchangeable and need no stable identity or order, a Deployment is usually simpler.
A Kubernetes StatefulSet manages Pods whose identities and ordering remain predictable across rescheduling. Pods receive ordinal names such as web-0 and can keep a matching PersistentVolumeClaim (PVC), so the same logical replica can reconnect to its storage. This does not make Kubernetes replicate or back up application data. If Pods are interchangeable and need no stable identity or order, a Deployment is usually simpler.
When does a StatefulSet help?
Deployment replicas share a template and are generally interchangeable. StatefulSet replicas share a template too, but each has a persistent identity. That is useful when peers discover one another by stable name, each replica needs its own storage, or the application expects ordered startup, shutdown, scaling, or updates.
StatefulSet web
├─ web-0 ── PVC data-web-0
├─ web-1 ── PVC data-web-1
└─ web-2 ── PVC data-web-2
└── a Headless Service provides per-Pod DNS namesIf a Pod fails, Kubernetes creates a replacement with the same ordinal identity. It is still a new Pod object with a new UID, not the old container moved to another node. When storage provisioning and attachment permit, the replacement can mount the PVC associated with that ordinal. StatefulSet identity
Stable networking and storage
A StatefulSet normally needs a Headless Service (clusterIP: None) for stable Pod DNS; spec.serviceName points to that Service. With Service web, namespace shop, StatefulSet db, and the usual cluster domain, one Pod address is db-0.web.shop.svc.cluster.local. The actual domain can differ, and DNS caching can delay discovery of a newly created Pod. The Service must be created separately. Headless Services
volumeClaimTemplates can create one PVC per Pod. A matching StorageClass must support dynamic provisioning, or an administrator must have pre-provisioned a suitable PersistentVolume. If the claim remains Pending, the Pod cannot mount it. Check capacity, access mode, StorageClass, provisioner, and topology constraints. Persistent Volumes and PVCs
Example: Headless Service and StatefulSet
This manifest requests three example NGINX Pods and one 1 GiB claim per Pod. Replace the image, namespace, StorageClass, capacity, and access mode to match the cluster and application. my-storage-class is a placeholder. ReadWriteOnce is shown for simplicity; the Kubernetes guide recommends ReadWriteOncePod for production when the storage driver supports it.
apiVersion: v1
kind: Service
metadata:
name: web
spec:
clusterIP: None
selector:
app: web
ports:
- name: http
port: 80
targetPort: http
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: db
spec:
serviceName: web
replicas: 3
selector:
matchLabels:
app: web
template:
metadata:
labels:
app: web
spec:
containers:
- name: web
image: registry.example.com/team/web:<approved-tag-or-digest>
ports:
- name: http
containerPort: 8080
volumeMounts:
- name: data
mountPath: /var/lib/app
volumeClaimTemplates:
- metadata:
name: data
spec:
accessModes: ["ReadWriteOnce"]
storageClassName: my-storage-class
resources:
requests:
storage: 1GiThe selector must match the Pod template labels. The claim template name data must match the volume mount name. The mount path and storage settings must suit the application and storage driver. StatefulSet components
Creation and updates are ordered by default
The default Pod management policy, OrderedReady, creates Pods from lower to higher ordinal and waits for each predecessor to become Running and Ready before proceeding. Scale-down and the default rolling update proceed from the highest ordinal downward. If db-0 never becomes Ready, db-1 and db-2 may not be created. This ordering can help applications that initialize peers in sequence, but a failed readiness probe or application error can block later replicas. Parallel relaxes ordering; choose it only when the application can tolerate concurrent creation and deletion. Pod management policies
The default update strategy is RollingUpdate: higher ordinals are recreated first, and each updated Pod must become Ready before the controller moves on. A stuck Pod can stop the rollout. Use kubectl rollout status statefulset/db -n <namespace> and kubectl describe pod db-0 -n <namespace> to inspect progress and events. Some broken ordered rollouts require manual intervention, so plan compatibility and recovery before changing a production template.
Apply and verify
These commands are examples and were not run against a cluster. Check the context, namespace, StorageClass, and whether provisioning is available before applying the manifest.
kubectl config current-context
kubectl apply -n <namespace> -f <statefulset.yaml>
kubectl get statefulset,pods -n <namespace> -l app=web
kubectl get pvc -n <namespace>
kubectl describe pvc data-db-0 -n <namespace>
kubectl rollout status statefulset/db -n <namespace> --timeout=10mExpect names db-0, db-1, and db-2, plus claims such as data-db-0, data-db-1, and data-db-2. If creation stalls, inspect the lowest ordinal first. For a Pending Pod, inspect its PVC and storage events. A successful apply does not verify data consistency, database replication, or restore readiness; those require application-level checks and tested backups.
Check retention before deleting or scaling down
By default, deleting a StatefulSet or reducing replicas does not automatically delete its PVCs. This favors data retention but is not a backup. The optional PVC retention policy and the PersistentVolume reclaim policy affect what remains; verify both before a cleanup. Deleting a StatefulSet also does not guarantee ordered Pod termination. If an application needs graceful reverse-order shutdown, consider scaling the StatefulSet to zero first and confirming termination before deleting it. StatefulSet limitations · PVC retention policy
StatefulSet or Deployment?
| Need | StatefulSet | Deployment |
|---|---|---|
| Pod identity | Stable ordinal-based identity | Interchangeable replicas |
| Storage | Can attach a distinct PVC per Pod | Usually shared stateless configuration |
| Ordering | Ordered create, scale, and update by default | General-purpose rolling replacement |
| Typical fit | Each instance needs a stable name or storage | Any replica can perform the same role |
A StatefulSet does not configure database consensus, replication, failover, schema changes, snapshots, or backups. Choose it only when stable identity, storage, or ordering is an actual application requirement.
Sources
[StatefulSets](https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/)
[Headless Services](https://kubernetes.io/docs/concepts/services-networking/service/#headless-services)
[Persistent Volumes](https://kubernetes.io/docs/concepts/storage/persistent-volumes/)
[Deployments](https://kubernetes.io/docs/concepts/workloads/controllers/deployment/)
[Pod lifecycle](https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/)
Scope: StatefulSet identity, Headless Service, PVCs, default ordering, verification, and storage-retention caveats. Kubernetes documentation checked on 2026-11-22. The manifest and commands are examples and were not run against a cluster. Database-specific replication and quorum, snapshots, and backup/restore procedures are outside scope.