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#

Feature Deployment StatefulSet
Pod names Random suffix (web-api-6d4f8) Ordinal index (postgres-0, postgres-1)
Startup order All at once Sequential (0, then 1, then 2)
Stable network identity No Yes, via headless Service
Persistent storage Shared or none Per-pod via volumeClaimTemplates
Scaling down Removes random pods Removes 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.