StatefulSet vs Deployment in Kubernetes: Key Differences

StatefulSet vs Deployment: Pod identity, headless Service DNS, per-Pod PVCs, ordered scaling, partitioned updates and when to use each, with YAML.

Aug 14, 2025 - 14:41
Nov 7, 2026 - 10:45
 0  139
TOPICDevOps BasicsPractical guide
StatefulSet vs Deployment in Kubernetes: Key Differences

A Deployment runs interchangeable Pods that share one template and can be replaced in any order, which suits stateless web apps and APIs. A StatefulSet gives each Pod a fixed name, a stable DNS record and its own PersistentVolumeClaim, and it creates, updates and removes Pods in ordinal order. Use it for databases, brokers and other clustered systems that need identity.

This guide compares the two controllers field by field, shows the YAML that makes the difference, and covers the update, scaling and storage behaviour that trips people up in production. It sits in our Kubernetes architecture components cluster. The behaviour described here was checked against the Kubernetes documentation in November 2026.

Key takeaways

  • Deployments manage ReplicaSets, and Pods get random suffixes such as web-7d4b9c-x2kq8. StatefulSet Pods are named web-0, web-1 and keep that name when rescheduled.
  • A StatefulSet needs a headless Service (clusterIP: None) named in spec.serviceName. You create that Service yourself.
  • volumeClaimTemplates gives each StatefulSet Pod its own PVC. A Deployment's Pods all mount the same claim, so ReadWriteOnce storage limits you to one replica in practice.
  • Deleting or scaling down a StatefulSet keeps its PVCs by default. persistentVolumeClaimRetentionPolicy, stable since Kubernetes v1.32, lets you change that.
  • StatefulSet rolling updates go from the highest ordinal to the lowest, and partition lets you stage a canary-like rollout.
  • A StatefulSet does not replicate data. The database or broker inside it still has to handle replication, leader election and backups.

Deployment vs StatefulSet at a glance

AspectDeploymentStatefulSet
Pod namesRandom hash suffix, changes on replacement<name>-<ordinal>, kept across rescheduling
Network identityReached through a normal Service (one virtual IP)Each Pod gets a DNS record through the headless Service
StorageShared volume or none; one PVC referenced by all PodsOne PVC per Pod from volumeClaimTemplates
Create and scale orderAll at once0, 1, 2 in order by default (OrderedReady)
Update strategiesRollingUpdate (default) or RecreateRollingUpdate (default) or OnDelete; Recreate is alpha in v1.37
Rollbackkubectl rollout undo switches ReplicaSetskubectl rollout undo works on ControllerRevisions; a broken Pod may need manual deletion
Underlying objectReplicaSetManages Pods directly
Typical workloadsREST APIs, frontends, workers that keep state elsewherePostgreSQL, MySQL, Kafka, ZooKeeper, Elasticsearch, etcd, Redis clusters

What "state" means for a Kubernetes workload

A workload is stateless when any replica can answer any request because the data lives somewhere else: a managed database, an object store or a cache that other services own. Kill a Pod and nothing is lost. That is the case Deployments are built for.

A workload is stateful when a replica holds data or a role that the others do not have. A PostgreSQL primary is different from its replicas. A Kafka broker owns specific partitions on its own disk. A ZooKeeper or etcd member is listed by name in the cluster configuration of its peers. If such a Pod comes back with a new name, a new IP and an empty disk, the cluster treats it as a stranger. StatefulSets exist to prevent that.

How a Deployment works

A Deployment owns one or more ReplicaSets. When you change the Pod template, it creates a new ReplicaSet and shifts Pods across according to maxSurge and maxUnavailable. Old ReplicaSets stay around (up to revisionHistoryLimit, default 10) so you can roll back.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: api
spec:
  replicas: 3
  selector:
    matchLabels:
      app: api
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 0
  template:
    metadata:
      labels:
        app: api
    spec:
      containers:
      - name: api
        image: registry.example.com/api:1.4.2
        ports:
        - containerPort: 8080
        readinessProbe:
          httpGet:
            path: /healthz
            port: 8080

All three Pods are equal. A Service load-balances across them, the Horizontal Pod Autoscaler can add or remove any of them, and the scheduler can put a replacement on any node. For the wider set of rollout patterns built on top of Deployments, see 14 Kubernetes deployment strategies with YAML examples.

How a StatefulSet works

A StatefulSet manages Pods directly and gives each one an ordinal index. With N replicas, Pods are numbered 0 to N-1 (or from spec.ordinals.start, stable since v1.31, if you set it). The ordinal drives three things: the Pod name, its DNS record and which PVC it binds to.

apiVersion: v1
kind: Service
metadata:
  name: db
spec:
  clusterIP: None
  selector:
    app: db
  ports:
  - name: pg
    port: 5432
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: db
spec:
  serviceName: db
  replicas: 3
  selector:
    matchLabels:
      app: db
  minReadySeconds: 10
  template:
    metadata:
      labels:
        app: db
    spec:
      terminationGracePeriodSeconds: 60
      containers:
      - name: postgres
        image: postgres:17
        ports:
        - containerPort: 5432
          name: pg
        volumeMounts:
        - name: data
          mountPath: /var/lib/postgresql/data
  volumeClaimTemplates:
  - metadata:
      name: data
    spec:
      accessModes: ["ReadWriteOncePod"]
      storageClassName: fast-ssd
      resources:
        requests:
          storage: 20Gi

This creates Pods db-0, db-1 and db-2, and PVCs data-db-0, data-db-1 and data-db-2. If db-1 is evicted, the controller recreates a Pod called db-1 and reattaches data-db-1. The Kubernetes docs recommend ReadWriteOncePod over ReadWriteOnce for production, since it guarantees only one Pod can mount the volume.

Note that the manifest above only gives you three independent PostgreSQL servers. Turning them into a primary with streaming replicas needs init logic, configuration or an operator. That is the most common misunderstanding about StatefulSets.

Pod identity and DNS

The headless Service in the example has no cluster IP. Instead, cluster DNS publishes one record per Pod in the form $(podname).$(service).$(namespace).svc.cluster.local. In the default namespace the members are reachable at:

db-0.db.default.svc.cluster.local
db-1.db.default.svc.cluster.local
db-2.db.default.svc.cluster.local

Clustered software uses these names in its peer lists. Kafka brokers advertise them, ZooKeeper's server list can reference them, and a replica can be told that its primary is always db-0.db. The IP behind a name changes when a Pod moves, so clients should resolve the name each time rather than caching the IP for long.

A Deployment can sit behind a headless Service too, but the records point at random Pod names that disappear on replacement, so they are no use as stable peer addresses. For how ClusterIP, headless and other Service types differ, read Kubernetes Service patterns explained with use cases.

Storage: shared claim vs a claim per Pod

A Deployment's Pod template can reference a PVC, but every replica references the same one. With a ReadWriteMany volume (NFS, CephFS, Azure Files, Amazon EFS) that works for shared content. With block storage such as ReadWriteOnce disks, the second replica on another node cannot attach the volume and stays Pending. Teams then run replicas: 1 with a Deployment and wonder why a rollout briefly has two Pods fighting for one disk. If you must do that, use the Recreate strategy.

A StatefulSet's volumeClaimTemplates stamp out a separate PVC per ordinal, so each member gets its own disk. Two behaviours matter:

  • Retention. By default, PVCs survive both scale-down and deletion of the StatefulSet. That protects data but leaves orphaned disks that keep costing money. Set persistentVolumeClaimRetentionPolicy with whenDeleted and whenScaled to Retain or Delete to choose.
  • Template changes. You cannot edit most of volumeClaimTemplates on an existing StatefulSet. Growing a disk means expanding each PVC (if the StorageClass allows expansion) and, if you want the template to match, recreating the StatefulSet object with kubectl delete sts db --cascade=orphan so the Pods keep running.
spec:
  persistentVolumeClaimRetentionPolicy:
    whenDeleted: Retain
    whenScaled: Delete

Storage classes, CSI drivers and access modes are covered in 12 Kubernetes storage options explained.

Scaling and ordering

With the default podManagementPolicy: OrderedReady, a StatefulSet creates db-0 first, waits until it is Running and Ready, then creates db-1, and so on. Scale-down removes the highest ordinal first and waits for each Pod to terminate fully. If db-0 is unhealthy, scaling up stops until it recovers.

That ordering helps software that bootstraps from the first member. It also slows things down. If your application handles its own membership (Cassandra, for instance, or a set of independent workers that only need stable disks), set podManagementPolicy: Parallel. Pods then start and stop together. The policy only affects scaling; updates still follow the update strategy.

Deployments have no ordering. Scaling from 3 to 10 creates seven Pods at once, which is what you want for an autoscaled API. Our guide to scaling strategies for Kubernetes applications covers HPA, VPA and event-driven scaling for both cases.

Updates and rollbacks

Deployment updates

A Deployment rollout replaces Pods in any order within the surge and unavailability limits. Rollback is quick because the old ReplicaSet still exists: kubectl rollout undo deployment/api.

StatefulSet updates

With RollingUpdate, the controller deletes and recreates Pods one at a time from the highest ordinal down: db-2, then db-1, then db-0. Each new Pod must be Running and Ready (plus minReadySeconds) before the next one goes. maxUnavailable for StatefulSets is beta and enabled by default as of v1.37 if you want to update more than one Pod at a time.

The partition field holds back Pods below a given ordinal:

spec:
  updateStrategy:
    type: RollingUpdate
    rollingUpdate:
      partition: 2

With three replicas, only db-2 gets the new template. You watch it, then lower the partition to 1 and 0. This is the usual way to canary a database version change.

OnDelete means the controller never replaces Pods on its own. You delete each Pod when you are ready, which suits operators or runbooks that need to fail over a primary before restarting it.

One limitation from the docs: with RollingUpdate and OrderedReady, a bad template can leave a Pod that never becomes Ready, and the rollout stops. Reverting the template is not enough; you also have to delete the stuck Pod so it is recreated from the good revision. Rollback techniques for both controllers are in 10 deployment rollback strategies with commands.

How to choose

QuestionIf yes
Can any replica serve any request, with data held outside the Pod?Deployment
Do peers need to find each other by a fixed hostname?StatefulSet
Does each replica need its own disk that must follow it to a new node?StatefulSet
Must members start or stop in a fixed order?StatefulSet with OrderedReady
Is it a single-instance app with one RWO disk?Either; a one-replica StatefulSet avoids two Pods attaching the disk during rollout
Is a mature operator available (CloudNativePG, Strimzi, ECK)?Use the operator; it creates StatefulSets or Pods for you and adds failover and backup logic
Is a managed service an option (RDS, Cloud SQL, MSK)?Often the simpler choice for production databases

Running both together

Most real applications use both. A typical layout is a Deployment for the web tier and API, a StatefulSet (usually created by an operator) for PostgreSQL or Kafka, and a Deployment for background workers that read from the queue. The Deployment Pods connect to the stateful tier through a regular ClusterIP Service for read/write traffic, while the stateful members talk to each other through the headless Service.

Production checklist for StatefulSets

  • Create a PodDisruptionBudget so node drains do not take down more members than the cluster can lose.
  • Spread members across zones with topologySpreadConstraints or pod anti-affinity, and check that your StorageClass uses volumeBindingMode: WaitForFirstConsumer so disks are created in the Pod's zone.
  • Set a terminationGracePeriodSeconds long enough for the database to flush and shut down cleanly.
  • Use readiness probes that reflect real availability (replica caught up, broker in sync), not just an open port.
  • Back up at the application level and with volume snapshots; see Kubernetes backup tools for enterprise data.
  • Scale to zero before deleting a StatefulSet if you need ordered, graceful termination; deletion itself gives no ordering guarantee.

Common mistakes

  • Running a database as a multi-replica Deployment with one shared RWO claim. Replicas get stuck Pending or, with RWX storage, corrupt each other's files.
  • Assuming a StatefulSet makes a database highly available. It gives identity and storage; replication is the application's job.
  • Forgetting the headless Service, so Pod DNS names never resolve.
  • Deleting a StatefulSet and expecting disks to go too. They stay unless the retention policy says otherwise.
  • Pinning clients to Pod IPs instead of DNS names.

If you want to practise this on real clusters, our CKA training (classroom in Kharadi, Pune, and live online) covers workloads, storage and troubleshooting. Interview-style scenarios on the same topic are in Kubernetes scenario-based interview questions.

FAQs

What is the main difference between a StatefulSet and a Deployment?

A StatefulSet gives each Pod a stable name, DNS record and its own PersistentVolumeClaim, and handles Pods in ordinal order. A Deployment treats Pods as identical and replaceable in any order.

Can a Deployment use persistent storage?

Yes, but every replica mounts the same PVC. That works with ReadWriteMany storage for shared files. With ReadWriteOnce block storage you are limited to one replica, and you should use the Recreate strategy to avoid two Pods trying to attach the disk.

Why does a StatefulSet need a headless Service?

The headless Service, named in spec.serviceName, makes cluster DNS publish a record for each Pod, such as db-0.db.default.svc.cluster.local. Without it, Pods have no stable network names. You must create the Service yourself.

What happens to PVCs when I delete a StatefulSet?

By default they are kept, both on deletion and on scale-down, so data is not lost. You can change that with persistentVolumeClaimRetentionPolicy (stable since v1.32), setting whenDeleted and whenScaled to Retain or Delete.

Do StatefulSets support rolling updates?

Yes. RollingUpdate is the default and replaces Pods one at a time from the highest ordinal to the lowest. The partition setting lets you update only higher ordinals first, and OnDelete leaves replacement to you.

Can I convert a Deployment into a StatefulSet?

Not in place. You create a new StatefulSet, move or restore the data into its PVCs, switch traffic, then remove the Deployment. Plan it as a migration with a backup.

Does a StatefulSet make my database highly available?

No. It provides stable identity, storage and ordering. Replication, failover and backups come from the database itself or from an operator built for it.

When should I use podManagementPolicy Parallel?

When members do not depend on each other during startup and you want faster scaling. Parallel launches and terminates Pods together instead of one by one. It does not change how updates are rolled out.

References

Interested in learning more?Get a callback from our training advisors.

What's Your Reaction?

Like Like 0
Dislike Dislike 0
Love Love 0
Funny Funny 0
Angry Angry 0
Sad Sad 0
Wow Wow 0
Mridul I am a passionate technology enthusiast with a strong focus on DevOps, Cloud Computing, and Cybersecurity. Through my blogs at DevOps Training Institute, I aim to simplify complex concepts and share practical insights for learners and professionals. My goal is to empower readers with knowledge, hands-on tips, and industry best practices to stay ahead in the ever-evolving world of DevOps.