I've been doing a lot of digging on Kubernetes, and I'm liking what I see a lot! One thing I've been unable to get a clear idea about is what the exact distinctions are between the Deployment and StatefulSet resources and in which scenarios would you use each (or is one generally preferred over the other).
StatefulSets represent a set of Pods with unique, persistent identities and stable hostnames that GKE maintains regardless of where they are scheduled. The state information and other resilient data for any given StatefulSet Pod is maintained in persistent disk storage associated with the StatefulSet.
Statefulsets is used for Stateful applications, each replica of the pod will have its own state, and will be using its own Volume. DaemonSet is a controller similar to ReplicaSet that ensures that the pod runs on all the nodes of the cluster.
A ReplicaSet ensures that a specified number of pod replicas are running at any given time. However, a Deployment is a higher-level concept that manages ReplicaSets and provides declarative updates to Pods along with a lot of other useful features.
A Daemonset will not run more than one replica per node. Another advantage of using a Daemonset is that, if you add a node to the cluster, then the Daemonset will automatically spawn a pod on that node, which a deployment will not do.
Deployments and ReplicationControllers are meant for stateless usage and are rather lightweight. StatefulSets are used when state has to be persisted. Therefore the latter use volumeClaimTemplates
/ claims on persistent volumes to ensure they can keep the state across component restarts.
So if your application is stateful or if you want to deploy stateful storage on top of Kubernetes use a StatefulSet.
If your application is stateless or if state can be built up from backend-systems during the start then use Deployments.
Further details about running stateful application can be found in 2016 kubernetes' blog entry about stateful applications
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With