Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kubernetes Deployments vs StatefulSets

Tags:

kubernetes

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).

like image 382
SS781 Avatar asked Oct 15 '22 13:10

SS781


People also ask

What is StatefulSets in Kubernetes?

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.

What is the difference between a deployment a StatefulSet and a Daemonset?

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.

What is the difference between deployment and replica set?

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.

What is the difference between deployment and Daemonset?

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.


1 Answers

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

like image 168
pagid Avatar answered Oct 17 '22 02:10

pagid