๐ŸŽ“ A1Learner
๐Ÿ”
0 of 51 lessons completed

Kubernetes: Deployment vs StatefulSet vs DaemonSet

A Deployment, a StatefulSet and a DaemonSet are three workload controllers. Each one keeps pods running, and each one suits a different kind of app. Stateless means an app where every copy is the same.

One app, three shapes

A web front end has no memory between requests. Any pod can serve any visitor. A Deployment fits it.

kubectl get deployments
kubectl get statefulsets
kubectl get daemonsets

The stable-name test

A database pod must keep its name and its data after a restart. A Deployment gives it a new name each time. A StatefulSet keeps the same name.

kubectl get pods -l app=database

The every-node test

A log collector is useless if it misses a node. A DaemonSet adds a pod to each new node on its own. A Deployment would leave the new node uncovered.

kubectl get pods -l app=log-agent -o wide

Example

kubectl get deployments,statefulsets,daemonsets

Key points

  • Deployment: keeps a set number of identical, replaceable pods running
  • StatefulSet: keeps pods with stable names, stable storage and ordered scaling
  • DaemonSet: keeps one pod on every node, or on every matching node
  • Use a Deployment for a stateless app that any pod can serve
  • Use a StatefulSet for an app that needs a stable identity or its own disk
  • Use a DaemonSet for an agent that must run on every node, like a log collector

In this example, the command lists all three workload types at once. The Deployment shows three web pods ready. The StatefulSet shows one database pod ready. The DaemonSet shows one log-agent pod ready, matching its one desired pod.

Note

pick the workload by what the app needs, not by which name sounds familiar

Try it Yourself

Edit the code, then press Run.

Running is simulated ยท Rust Playground

Exercise

Which workload should run a log collector that must be present on every node?