StatefulSets and Persistent Volumes: Running Stateful Apps on Kubernetes

How StatefulSets give pods stable identities and storage, how PersistentVolumes, PVCs and StorageClasses work, and when to run databases on Kubernetes.

Published December 2, 2026

Deployments treat pods as interchangeable cattle, which is perfect for stateless services. Databases, message brokers and clustered systems need something different: stable network identities, stable storage that follows a specific pod, and ordered startup and shutdown. StatefulSets and persistent volumes provide exactly that.

The concept

A StatefulSet creates pods with predictable names (db-0, db-1, db-2) and, together with a headless Service, stable DNS names (db-0.db.prod.svc.cluster.local). Each pod gets its own PersistentVolumeClaim from a volumeClaimTemplate, and if a pod is rescheduled to another node, it reattaches to the same volume. Pods are created, updated and deleted in order by default.

Storage is abstracted in three layers. A StorageClass describes a type of storage (SSD, replicated, a CSI driver) and provisions volumes dynamically. A PersistentVolumeClaim (PVC) is a request for storage of a certain size and access mode. A PersistentVolume (PV) is the actual provisioned disk bound to that claim. Reclaim policies decide whether data is deleted or retained when a claim is removed.

Storage layers

StatefulSetdb-0, db-1, db-2 with stable namesvolumeClaimTemplatesone PVC per podPersistentVolumeClaimrequest: 100Gi, ReadWriteOnceStorageClass + CSI driverdynamic provisioningPersistentVolumeactual cloud disk
From StatefulSet to disk.

Deployment vs StatefulSet

DeploymentStatefulSet
Pod namesRandom suffixOrdinal: app-0, app-1
StorageShared or nonePer-pod PVC that follows the pod
Network identityVia Service onlyStable per-pod DNS (headless Service)
OrderingParallelOrdered create/update/delete
Use forStateless APIs, workersDatabases, Kafka, ZooKeeper, Elasticsearch

Should you run databases on Kubernetes?

  1. Is a managed database available? Prefer it for most teams
  2. Need it in-cluster? Use a mature operator (CloudNativePG, etc.)
  3. Plan backups and restore tests from day one
  4. Use topology spread and PodDisruptionBudgets
  5. Choose StorageClasses with appropriate performance and replication
Running databases on Kubernetes responsibly.

Practical examples

StatefulSet with per-pod storage

Requires a headless Service named in serviceName.

apiVersion: apps/v1
kind: StatefulSet
metadata: { name: redis }
spec:
  serviceName: redis
  replicas: 3
  selector: { matchLabels: { app: redis } }
  template:
    metadata: { labels: { app: redis } }
    spec:
      containers:
        - name: redis
          image: redis:7.4
          volumeMounts: [{ name: data, mountPath: /data }]
  volumeClaimTemplates:
    - metadata: { name: data }
      spec:
        accessModes: [ReadWriteOnce]
        storageClassName: fast-ssd
        resources: { requests: { storage: 20Gi } }

Inspect claims and volumes

See bindings and reclaim policies.

kubectl get pvc -l app=redis
kubectl get pv -o custom-columns=NAME:.metadata.name,CLAIM:.spec.claimRef.name,POLICY:.spec.persistentVolumeReclaimPolicy

Expand a volume

Works if the StorageClass allows volume expansion.

kubectl patch pvc data-redis-0 -p '{"spec":{"resources":{"requests":{"storage":"50Gi"}}}}'

Common mistakes

  • Running production databases on Kubernetes without backups and tested restores.
  • Using ReadWriteOnce volumes and expecting multiple pods to share them.
  • Delete reclaim policy on important data, losing disks when PVCs are deleted.
  • Ignoring zone placement, so a volume in one zone cannot attach to a pod rescheduled in another.

Key takeaways

  • StatefulSets give stable names, DNS and per-pod storage.
  • StorageClass → PVC → PV provisions and binds disks.
  • Prefer managed databases or mature operators for stateful systems.
  • Back up, test restores and mind zones and reclaim policies.

FAQ

Does deleting a StatefulSet delete its volumes?

By default the PVCs remain; recent Kubernetes versions offer a persistentVolumeClaimRetentionPolicy to control this.

What is ReadWriteMany?

An access mode allowing many nodes to mount a volume read-write, supported by some storage types like NFS or certain CSI drivers.

What does an operator add?

Operators encode database-specific operations: failover, backups, upgrades and scaling, beyond what a StatefulSet does.

More DevOps articles