Quick reference
| DEPLOYMENT | STATEFULSET | |
|---|---|---|
| Pod names | Random hash | Ordered: app-0, app-1 |
| Identity | Interchangeable | Stable and sticky |
| Storage | Shared or none | Own volume per pod |
| Scaling | Any order, parallel | Ordered, one by one |
| Use for | Web, API, workers | Databases, Kafka, etcd |
| DNS | One service | Stable per-pod name |
DEPLOYMENT (For stateless apps): Interchangeable pods with random names. Scale and replace freely.
kind: DeploymentSTATEFULSET (For stateful apps): Pods with stable identity and their own storage. For databases.
kind: StatefulSet- Deployment → stateless apps. The default for most workloads.
- StatefulSet → apps that need stable identity and storage.
Explained
A Deployment runs stateless pods: interchangeable, with random names like web-7d9f8c6b5-x2kqp. Any pod can handle any request, so Kubernetes can create, destroy, scale and replace them freely and in parallel. This is the default for web servers, APIs and workers, anything that keeps no important local state.
A StatefulSet runs pods that have a stable identity. They get ordered, predictable names (db-0, db-1, db-2), each keeps the same name across restarts, and each gets its own persistent volume that follows it. Pods are created and scaled in order, one at a time, and each has a stable DNS name. This is for apps where the instances are not interchangeable: databases, message brokers like Kafka, and clustered systems like etcd.
Why it matters
Run a database as a Deployment and you get chaos: pods with random names sharing or losing storage, no stable address for replication, and scaling that does not respect the order a cluster needs. Run a stateless web app as a StatefulSet and you add complexity and slow, ordered rollouts for no benefit.
The quick test
Does each instance need its own persistent data and a stable identity? StatefulSet. Are the instances interchangeable? Deployment.
Most of your workloads are stateless, so Deployment is the common case. Reach for StatefulSet deliberately, for the specific apps that need it. And remember: stateful apps on Kubernetes also need a StorageClass for their volumes.
Identity is the deciding question.
More notes: Kubernetes
Open in the notes app: search, filters, copy This note on GitHub