StatefulSet
A StatefulSet is a Kubernetes controller that manages the deployment and scaling of a set of Pods with unique, stable identities and persistent storage.
It’s used for stateful applications such as:
Databases (MySQL, PostgreSQL, MongoDB)
Distributed systems (Cassandra, Kafka, Zookeeper)
Anything requiring stable Pod names, stable storage, or ordered startup/shutdown
Stable storage
Each Pod can get its own PersistentVolumeClaim (PVC), automatically created by the StatefulSet.
The storage is bound to the Pod’s identity (
mydb-0always usespvc-mydb-0).Even if the Pod is rescheduled on another node, it reattaches to the same storage.
Ordered, graceful deployment and scaling
Pods are created one by one, in order (
mydb-0, thenmydb-1, thenmydb-2).Similarly, they are deleted in reverse order.
Useful when apps require strict initialization order (like primary DB before replicas).
Rolling updates
StatefulSets support rolling updates, but they also ensure ordering and readiness at each step.
This prevents breaking distributed systems during upgrades.
In Production use StatefulSets if:
You need stable Pod IDs (databases, queues, clustered systems).
Each Pod must keep its own persistent data.
Startup order matters.
Commands
To apply and run a StatefulSet configuration:
To list the StatefulSets:
To describe a StatefulSet:
To delete a StatefulSet:
To update image through the CLI:
To get the rollout history of StatefulSets:
To rollback a StatefulSet to a previous version:
To scale StatefulSets:
Check consumption of a StatefulSet:
In this example, the Headless Service provides DNS por Pods and StatefulSet creates Pods with stable names.
Each Pod gets its own PVC.
Last updated