Skip to content
tezvyn:

StatefulSet vs Deployment: what's the difference?

Source: interviewMediumHow cards are made

Summary

choosing the right workload controller.

Key points

Deployments treat Pods as interchangeable; StatefulSets give stable ordinal names, stable per-Pod storage via volumeClaimTemplates, and ordered rollout.

What's really being asked

Whether you can pick the correct controller for a workload and articulate exactly which guarantees stateful systems depend on.

The full answer

A Deployment is for stateless workloads. Its Pods are fungible, get random hash-suffixed names, are created and replaced in no guaranteed order, and typically share storage or have none. A StatefulSet is for workloads where identity matters. It gives each Pod a stable, predictable name based on an ordinal index, such as db-0 and db-1, that persists across rescheduling. Combined with a headless Service, each Pod gets a stable DNS hostname so peers can address each other reliably. Each Pod gets its own PersistentVolume created from a volumeClaimTemplate, and that volume stays bound to the same ordinal even if the Pod is rescheduled to another node, preserving per-replica data. Operations are ordered: Pods are created and scaled up sequentially from the lowest ordinal, and terminated in reverse, which lets clustered systems bootstrap and gracefully shrink safely.

The mistakes people make

Using a Deployment for a database and expecting stable names or per-Pod storage. Thinking StatefulSet Pods share one volume. Believing rollout order does not matter. Forgetting the headless Service requirement for stable network identity.

What usually comes next

How does the headless Service provide DNS identity? What does volumeClaimTemplates do? Why does ordered termination matter for a quorum-based database? When is a Deployment with a shared PVC still acceptable?

A concrete example

A three-node Cassandra cluster runs as a StatefulSet so Pods cassandra-0 through cassandra-2 keep stable hostnames and each retains its own data volume after a reschedule, whereas a stateless web frontend runs as a Deployment whose Pods can be replaced freely.

Interview question

Which guarantee does a StatefulSet provide that a Deployment does not?

  • a.Faster parallel rollout of all Pods at once
  • b.Automatic horizontal autoscaling of replicas
  • c.Built-in load balancing across Pods
  • d.Stable per-Pod identity and dedicated persistent storage per replicaCorrect
Why?

StatefulSets give each Pod a stable ordinal identity and its own persistent volume via volumeClaimTemplates, which Deployments do not. Autoscaling and load balancing are separate features, and parallel rollout is actually a Deployment trait.

Just read this? Test yourself on what you have been reading.

Read the original → kubernetes.io

Put your scrolling time to good use

Learn one idea, try a quiz and save useful cards for revision. Tezvyn makes it easy to learn and stay current in your tech field, a few minutes at a time.

The iPhone app is on the way

We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.

Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.

Get it on Google PlayiPhone app coming soon

We are hiring for this. Open roles that interview on kubernetes — each one lists the topics its interview covers.

See open roles