StatefulSets and Persistent Storage: Stable Identity, PVCs, and StorageClasses

StatefulSets and Persistent Storage#

Deployments treat pods as interchangeable. StatefulSets do not – each pod gets a stable hostname, a persistent volume, and an ordered startup sequence. This is what you need for databases, message queues, and any workload where identity matters.

StatefulSet vs Deployment#

FeatureDeploymentStatefulSet
Pod namesRandom suffix (web-api-6d4f8)Ordinal index (postgres-0, postgres-1)
Startup orderAll at onceSequential (0, then 1, then 2)
Stable network identityNoYes, via headless Service
Persistent storageShared or nonePer-pod via volumeClaimTemplates
Scaling downRemoves random podsRemoves highest ordinal first

Use StatefulSets when your application needs any of: stable hostnames, ordered deployment/scaling, or per-pod persistent storage. Common examples: PostgreSQL, MySQL, Redis Sentinel, Kafka, ZooKeeper, Elasticsearch.