Running stateful apps with StatefulSets
stateful workloads in Kubernetes.
stateful apps need stable identity and storage; a StatefulSet gives stable names, ordered rollout, and per-Pod volumes.
claiming a Deployment plus PVC solves it.
WHAT THIS TESTS This probes your grasp of identity and storage requirements for stateful systems and the specific Kubernetes object designed for them.
A GOOD ANSWER COVERS A Deployment assumes its Pods are interchangeable: they get random names, can be replaced by any new Pod, and typically share nothing or the same volume. That breaks for stateful apps like databases, where each replica owns distinct data, has a stable identity, and may play a specific role such as primary or replica. If a Deployment Pod is rescheduled it may come back as a different identity with the wrong or no data, and multiple replicas pointed at one volume corrupt it. A StatefulSet solves this. It gives each Pod a stable, predictable name and ordinal, db-0, db-1, db-2, with a stable DNS hostname so peers can find each other reliably. Through volumeClaimTemplates each Pod gets its own dedicated PersistentVolume that follows it across rescheduling, so db-0 always reattaches to its own data. It also provides ordered, graceful operations: Pods are created and scaled in order and updated one at a time, which matters for clustered systems that must bootstrap or elect leaders deterministically.
COMMON WRONG ANSWERS Saying a Deployment with a PersistentVolumeClaim is enough; that gives one shared volume and unstable identities, not per-Pod storage and stable names. Believing StatefulSets make any app automatically highly available; you still need the app's own clustering and replication. Ignoring ordering guarantees.
LIKELY FOLLOW-UPS What is a headless Service and why does a StatefulSet need one? How do volumeClaimTemplates create per-Pod volumes? How do ordered scaling and rolling updates work? Why might you still run databases outside Kubernetes as a managed service?
ONE CONCRETE EXAMPLE Running a three-node database cluster, a StatefulSet creates db-0, db-1, db-2 in order, each with its own PersistentVolume and stable hostname. If db-1 crashes, it is recreated with the same name and reattaches to the same volume holding its data, and peers still resolve db-1 by DNS. A Deployment would instead spin up a randomly named Pod with no guaranteed link to that data, breaking the cluster.
Read the original → kubernetes.io
Get five bites like this every day.
Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.