Filters
How to search
  • Plain words find names, texts and examples.
  • "two words" finds the exact phrase.
  • --name or -x finds an option.
  • #word looks only inside commands.
  • @grep finds lessons and labs that use grep.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Put ! before a word to leave it out. OR between words means one of them.
  • ↑ ↓ to move · Enter to open · Esc to close · / to search

KubernetesCloud / DevSecOps series

Deployment vs StatefulSet

Deployment and StatefulSet both run pods, and choosing the wrong one causes real pain. The difference is whether your app cares which pod it is.

Quick reference

DEPLOYMENTSTATEFULSET
Pod namesRandom hashOrdered: app-0, app-1
IdentityInterchangeableStable and sticky
StorageShared or noneOwn volume per pod
ScalingAny order, parallelOrdered, one by one
Use forWeb, API, workersDatabases, Kafka, etcd
DNSOne serviceStable per-pod name

DEPLOYMENT (For stateless apps): Interchangeable pods with random names. Scale and replace freely.

kind: Deployment

STATEFULSET (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