Kubernetes — Difference between Deployment and StatefulSet in K8s
Deployments vs StatefulSets in Kubernetes

TL;DR
Deployments are usually used for stateless applications while StatefulSets are used for stateful applications.
Key Differences
- Pods: Pods deployed by Deployment are identical and interchangeable, created in random order with random hashes in their Pod names. In contrast to that, the Pods deployed by StatefulSet component are NOT identical. They each have their own sticky identity, which they keep between restarts and each can be addressed individually. Thus, they can’t be created or deleted at the same time.
- ReplicaSet: StatefulSet is also a Controller but unlike Deployments, it doesn’t create ReplicaSet rather itself creates the Pod with a unique naming convention. It manages the deployment and scaling of a set of Pods, and provides guarantees about the ordering and uniqueness of these Pods.
- PVC: Every replica of a StatefulSet will have its own state, and each of the pods will be creating its own PVC (Persistent Volume Claim). So StatefulSet with 3 replicas will create 3 pods, each having its own Volume, so total 3 PVCs.
- Rollback: Unlike Deployments, you cannot roll back to any previous version of a StatefulSet as it don’t create ReplicaSet or anything of that sort. You can only delete or scale up/down the Statefulset.
- States: To save the states StatefulSets use volumeClaimTemplates/claims of persistent volumes in order to keep the state safe in case of crashes or restarts.
Summary
Deployment is useful for REST API, SPA Applications like Angular, React etc.
StatefulSet is useful for ElasticSearch, Redis, Databases like MongoDB, MySQL, Postgres etc.
View more from DevOps Mojo
Happy Learning!!!






