A StatefulSet is a Kubernetes workload API object used to manage stateful applications by providing stable, unique network identifiers, ordered deployment and scaling, and persistent storage volumes that are bound to individual pod instances. Unlike a Deployment, which manages stateless pods as interchangeable replicas, a StatefulSet maintains a sticky identity for each of its pods (named -0, -1, etc.). This identity persists across pod rescheduling, enabling applications like databases (e.g., Cassandra, MongoDB, etcd), message queues, and other clustered services that require stable network endpoints and durable storage.
Key characteristics include:
- Stable Pod Hostname: Each pod derives its hostname from the pattern
$(statefulset name)-$(ordinal). The pod web-0 will always be web-0.
- Stable Storage: PersistentVolumeClaims (PVCs) created from the StatefulSet's
volumeClaimTemplates are bound to the specific pod ordinal, following it even if the pod is rescheduled to another node.
- Ordered, Graceful Deployment & Scaling: Pods are created, updated, and terminated in a strict sequential order (e.g.,
web-0, then web-1). Scaling down removes pods in reverse order.
- Ordered, Graceful Rolling Updates: Updates follow the same pod order, ensuring only one pod is down at a time during a rolling update.