DaemonSet Controller

A new Node joins the cluster and may get no Pod from the DaemonSet until someone labels it. How does a DaemonSet decide where its Pods run, how many it needs, and what happens when a Node leaves?

Play the animation 6 steps, animated, plays on a computer or a tablet

DaemonSet Controller, Kubernetes diagram

DaemonSet Controller, step by step

  1. The controller reads no replica count, because a DaemonSet has no replicas field. It lists Nodes through the API and matches each one against the nodeSelector in the DaemonSet Pod template. All three Nodes carry logging=enabled, so desiredNumberScheduled counts three. Nothing is running yet.

    Play from step 1
  2. The controller creates one Pod per matching Node through the API, each one pinned to its own Node by nodeAffinity. A DaemonSet keeps exactly one Pod per Node, and only a non-zero maxSurge during a rollout ever puts a second there, so the fleet follows the Node set instead of a replica number. A Node counts in numberReady once its Pod reports Ready.

    Play from step 2
  3. Node-4 joins the cluster without a logging=enabled label, so the nodeSelector in the Pod template does not select it, and joining alone earns it no Pod. The controller sees the new Node object and leaves desiredNumberScheduled at three.

    Play from step 3
  4. An operator labels Node-4 with logging=enabled. The controller watches Node objects, sees the update, recomputes desiredNumberScheduled to four and creates one Pod there. The three Pods already running are untouched, because the controller reconciles the difference and nothing about their Nodes changed.

    Play from step 4
  5. The image is bumped from fluentd v1 to v2. RollingUpdate with maxUnavailable=1 replaces the Pods one Node at a time: numberReady drops to three while the Pod on Node-1 is recreated, and is back at four once the v2 Pod is Ready. Log collection keeps running on the other Nodes. OnDelete would instead wait until you delete each Pod by hand.

    Play from step 5
  6. Node-2 leaves the cluster and its Node object is deleted, so desiredNumberScheduled drops back to three and the Pod on Node-2 is garbage collected, not recreated elsewhere as a Deployment replica would be. A drain would not have removed this Pod, because a drain never evicts running DaemonSet Pods.

    Play from step 6

Sources