Pods and workloadsLesson 6 of 7
  1. Pod anatomy, not reconciled
  2. Pod lifecycle, restarts and termination, not reconciled
  3. Init containers and native sidecars, not reconciled
  4. Probes: startup, readiness and liveness, not reconciled
  5. Deployments and rolling updates, not reconciled
  6. DaemonSets, not reconciled
    1. One per node
    2. Choosing nodes
    3. Automatic tolerations
    4. Updates
    5. Typical tenants
    6. Priority
  7. Jobs and CronJobs, not reconciled

DaemonSets

A DaemonSet runs one copy of a pod on every eligible node, follows nodes as they join and leave, and tolerates the node trouble that would push other pods away.

  • 18 min
  • 4 objectives
  • 6 scenes

Shows the lesson one block at a time. Arrow keys step, number keys jump to a scene, and Escape returns to the page where you were.

Some software has to run on every node because its job is the node: shipping the node’s logs, exporting its metrics, programming its network, mounting its volumes. A Deployment cannot promise that, because it counts replicas and lets the scheduler put them anywhere. A DaemonSetA workload controller that runs one copy of a pod on each node that matches its template’s node selection and tolerations. counts nodes instead, and that one difference explains everything else about it.

Reconcile, in 6 scenes

One per node

A DaemonSet has a selector and a pod template like a Deployment, and no replicas field. Its controller walks the node list, decides for each node whether a daemon pod should run there, and creates one pod per eligible node. It does not bind the pod itself. It adds a required node affinity term that matches exactly one node by name, with matchFields on metadata.name, and leaves the binding to kube-scheduler like any other pod. If the pod does not fit, the scheduler may preempt lower-priority pods to make room.

Before Kubernetes 1.12, the release that turned the ScheduleDaemonSetPods feature on by default, the DaemonSet controller set spec.nodeName itself and skipped the scheduler. The feature went GA in 1.17, so a statement that DaemonSet pods bypass the scheduler describes only those early versions.

apiVersion: v1
kind: Namespace
metadata:
  name: observability
---
apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: log-agent
  namespace: observability
  labels:
    app: log-agent
spec:
  selector:
    matchLabels:
      app: log-agent
  updateStrategy:
    type: RollingUpdate
    rollingUpdate:
      maxUnavailable: 1
      maxSurge: 0
  template:
    metadata:
      labels:
        app: log-agent
    spec:
      terminationGracePeriodSeconds: 5
      containers:
        - name: agent
          image: busybox:1.37
          command: ["sh", "-c", "while true; do echo shipping node logs; sleep 30; done"]
          resources:
            requests:
              cpu: 20m
              memory: 32Mi
          volumeMounts:
            - name: varlog
              mountPath: /var/log
              readOnly: true
      volumes:
        - name: varlog
          hostPath:
            path: /var/log
            type: Directory

The hostPath volume is typical: a node agent reads the node’s own files. The template’s restartPolicy must be Always (the default), because a daemon is expected to keep running, and the selector is immutable once the DaemonSet exists, as with Deployments.

Three of four nodes
kubectl apply -f log-agent.yaml
namespace/observability created
daemonset.apps/log-agent created
kubectl -n observability get daemonset log-agent
NAME        DESIRED   CURRENT   READY   UP-TO-DATE   AVAILABLE   NODE SELECTOR   AGE
log-agent   3         3         3       3            3           <none>          15s
kubectl -n observability get pods -o wide
NAME              READY   STATUS    RESTARTS   AGE   IP           NODE         NOMINATED NODE   READINESS GATES
log-agent-mfqhl   1/1     Running   0          15s   10.244.2.3   kx-worker2   <none>           <none>
log-agent-trkwr   1/1     Running   0          15s   10.244.3.2   kx-worker3   <none>           <none>
log-agent-wgh9z   1/1     Running   0          15s   10.244.1.2   kx-worker    <none>           <none>
kubectl -n kube-system get daemonsets
NAME         DESIRED   CURRENT   READY   UP-TO-DATE   AVAILABLE   NODE SELECTOR            AGE
kindnet      4         4         4       4            4           <none>                   45s
kube-proxy   4         4         4       4            4           kubernetes.io/os=linux   45s
kubectl -n observability get pod -l app=log-agent -o jsonpath='{range .items[0].spec.tolerations[*]}{.key}{"\t"}{.effect}{"\n"}{end}'
node.kubernetes.io/not-ready	NoExecute
node.kubernetes.io/unreachable	NoExecute
node.kubernetes.io/disk-pressure	NoSchedule
node.kubernetes.io/memory-pressure	NoSchedule
node.kubernetes.io/pid-pressure	NoSchedule
node.kubernetes.io/unschedulable	NoSchedule

The columns map onto the DaemonSet’s status. DESIRED is the number of eligible nodes, CURRENT the nodes that have a daemon pod, READY and AVAILABLE how many of those pods are ready and have been for minReadySeconds, and UP-TO-DATE how many run the current template. The status also counts misscheduled pods, ones running on a node that is no longer eligible.

DESIRED is 3, not 4. The two system DaemonSets in kube-system cover all four nodes, so something about kx-control-plane admits them and not log-agent. The last command already hints at the answer: the tolerations the controller added to the pod do not include the control-plane taint.

Choosing nodes

Three things decide whether a node is eligible:

  • spec.template.spec.nodeSelector and node affinity in the template. If you set neither, every node qualifies. The controller evaluates your affinity when it picks nodes, then replaces it on each pod with the single-node term described above.
  • Taints. A node is eligible only if the template tolerates each of its NoSchedule and NoExecute taints. kind’s control-plane node carries node-role.kubernetes.io/control-plane:NoSchedule, which is why log-agent skips it.
  • Fit. An eligible node with no room still gets a pod; the pod waits in Pending, or the scheduler preempts something to place it.

The two taint effects treat a running daemon pod differently. A NoSchedule taint added to a node later only blocks new placements: the existing pod keeps running, and the DaemonSet leaves it alone. A NoExecute taint that the pod does not tolerate evicts it, and the controller does not recreate it on that node until the taint is gone or tolerated.

Eligibility is re-evaluated continuously. A node that joins the cluster, or gains a matching label, gets a pod within one sync of the controller; a node that loses the label, or leaves, loses its pod. To run an agent only on GPU nodes, label those nodes and select the label:

spec:
  template:
    spec:
      nodeSelector:
        accelerator: gpu

To add the control-plane node, tolerate its taint:

spec:
  template:
    spec:
      tolerations:
        - key: node-role.kubernetes.io/control-plane
          operator: Exists
          effect: NoSchedule

Automatic tolerations

The DaemonSet controller adds tolerations of its own to every pod it creates, so node agents survive the conditions that move other pods away:

Toleration keyEffectWhat it allows
node.kubernetes.io/not-readyNoExecuteScheduling onto, and staying on, a node that is not Ready
node.kubernetes.io/unreachableNoExecuteStaying on a node the control plane cannot reach
node.kubernetes.io/disk-pressureNoScheduleScheduling onto a node with disk pressure
node.kubernetes.io/memory-pressureNoScheduleScheduling onto a node with memory pressure
node.kubernetes.io/pid-pressureNoScheduleScheduling onto a node with process pressure
node.kubernetes.io/unschedulableNoScheduleScheduling onto a cordoned node
node.kubernetes.io/network-unavailableNoScheduleScheduling onto a node without networking; added only for pods with hostNetwork: true

The NoExecute pair matters most. When a node stops reporting, the node lifecycle controller taints it and ordinary pods are evicted after their toleration window, 300 seconds by default. Daemon pods tolerate those taints forever, which is right: a log shipper on a sick node should keep shipping, and a replacement on another node would be meaningless.

The unschedulable toleration means a cordon does not stop a DaemonSet:

A cordoned node still gets its agent
kubectl cordon kx-worker
node/kx-worker cordoned
kubectl -n observability delete pod -l app=log-agent --field-selector spec.nodeName=kx-worker
pod "log-agent-wgh9z" deleted from observability namespace
kubectl -n observability get pods -o wide --field-selector spec.nodeName=kx-worker
NAME              READY   STATUS    RESTARTS   AGE   IP           NODE        NOMINATED NODE   READINESS GATES
log-agent-xvt8d   1/1     Running   0          10s   10.244.1.3   kx-worker   <none>           <none>

This is also why kubectl drain refuses to start on a node with DaemonSet pods unless you pass --ignore-daemonsets: evicting them would be pointless, since the controller would recreate them on the same node.

Updates

A DaemonSet’s spec.updateStrategy has two types.

RollingUpdate, the default, replaces pods node by node whenever the template changes. maxUnavailable (default 1) is how many nodes may be without an available daemon pod at once; a percentage is taken of the number of nodes that should run the pod and rounds up, unlike a Deployment’s. maxSurge (default 0) is how many nodes may run a new pod beside the old one. With maxSurge above 0 and maxUnavailable: 0, the controller starts the new pod first and deletes the old one only once the new one has been available for minReadySeconds, so the node is never without its agent. maxSurge for DaemonSets was beta in 1.22 and GA in 1.25. Material that says a DaemonSet cannot surge because it runs one pod per node predates it.

kubectl rollout status daemonset/<name> returns once every eligible node runs an updated pod that is available. It works only for the RollingUpdate type and returns an error for OnDelete, where the controller has no rollout of its own to report.

OnDelete creates updated pods only when you delete old ones. It suits agents where you want to choose the moment per node, for example during each node’s maintenance window.

A rolling update, one node at a time
kubectl -n observability set image daemonset/log-agent agent=busybox:1.38daemonset.apps/log-agent image updatedkubectl -n observability rollout status daemonset/log-agentWaiting for daemon set "log-agent" rollout to finish: 1 out of 3 new pods have been updated...
Waiting for daemon set "log-agent" rollout to finish: 2 out of 3 new pods have been updated...
Waiting for daemon set "log-agent" rollout to finish: 2 of 3 updated pods are available...
daemon set "log-agent" successfully rolled outkubectl -n observability get daemonset log-agent -o wideNAME        DESIRED   CURRENT   READY   UP-TO-DATE   AVAILABLE   NODE SELECTOR   AGE   CONTAINERS   IMAGES         SELECTOR
log-agent   3         3         3       3            3           <none>          24s   agent        busybox:1.38   app=log-agent

DaemonSets keep revisions as ControllerRevision objects (revisionHistoryLimit, default 10), so kubectl rollout history and kubectl rollout undo work on them as on Deployments. A rollout gets stuck in two common ways. A broken template, such as a crash-looping container or a mistyped image, stops progress; fix it by changing the template again, and the new rollout is not blocked by the broken one. A node without room for the new pod stops progress on that node; compare kubectl get nodes with the DaemonSet’s pods in -o wide to find it, then free capacity there.

Typical tenants

A workload belongs in a DaemonSet when it provides something to the node it runs on, so that a node without it is less capable:

  • Log shippers such as Fluent Bit, reading /var/log and the container runtime’s log directory.
  • Node and host metrics: node-exporter, or an OpenTelemetry Collector in agent mode.
  • CNI agents such as kindnet, Calico or Cilium, which program each node’s pod network.
  • CSI node plugins, which mount and unmount volumes on their node.
  • kube-proxy, which programs Service routing on each node.
  • Security and runtime agents such as Falco.

Every agent is also a fixed cost on every node. Its requests are reserved on each node it runs on, so an agent asking for 200m of CPU takes 20 cores from a 100-node cluster before any application starts. Size node agents as carefully as the nodes themselves.

These pods often need more of the node than an application does: hostPath mounts for logs and device sockets, hostNetwork: true for network agents and kube-proxy, sometimes a privileged security context. That power is the point of a node agent and also its risk, since a compromised agent holds every node it runs on. Keep such agents few, in namespaces whose Pod Security level allows exactly what they need, and review them like part of the node image.

cAdvisor is not on the list. The kubelet embeds it and serves per-container metrics at its /metrics/cadvisor endpoint, so a metrics pipeline scrapes the kubelet rather than running cAdvisor as a separate DaemonSet.

Some things do not belong in a DaemonSet:

  • A stateless service that needs a number of replicas behind a Service. Its count should follow load, not node count; use a Deployment.
  • Work that runs to completion. DaemonSet pods must restart forever; use a Job. Jobs handle failure far more finely than a retry count, with podFailurePolicy (GA in 1.31), backoffLimitPerIndex and successPolicy (GA in 1.33) and podReplacementPolicy (GA in 1.34), and they cover work queues too: a Job without completions finishes once one worker has succeeded and all of its workers have stopped.
  • A periodic task. Use a CronJob, which in Kubernetes 1.27 and later takes an IANA timeZone for its schedule.
  • A helper for one application, such as a log tailer for its files. Run it as a sidecar in the application’s pods. Native sidecar containers, GA in 1.33, start before the main containers and stop after them, and in a Job they do not hold the Job open after the main container finishes.
  • Components that must run before the API server exists, such as the control plane on a kubeadm cluster. Those are static pods that the kubelet reads from disk.

Priority

A node agent that is not running is a node that is quietly broken, so it should be the last thing to lose a fight for resources. Two mechanisms decide those fights: the scheduler preempts lower-priority pods to place a higher-priority one, and the kubelet ranks pods for node-pressure eviction first by whether their usage exceeds their requests, then by priority.

Preemption is what rescues a daemon pod that lands on a full node. The pod is pinned to that node by its affinity, so the scheduler cannot place it anywhere else; if its priority is higher than some pods already there, the scheduler evicts enough of them to make room, giving them their graceful termination period and honouring PodDisruptionBudgets only on a best-effort basis. Without a higher priority the daemon pod simply stays Pending.

Kubernetes ships two PriorityClasses for components a node or cluster cannot work without.

The built-in critical classes
kubectl get priorityclasses
NAME                      VALUE        GLOBAL-DEFAULT   AGE   PREEMPTIONPOLICY
system-cluster-critical   2000000000   false            30s   PreemptLowerPriority
system-node-critical      2000001000   false            30s   PreemptLowerPriority
kubectl -n kube-system get daemonset kube-proxy -o jsonpath='{.spec.template.spec.priorityClassName}'
system-node-critical
kubectl -n kube-system get daemonset kindnet -o jsonpath='{.spec.template.spec.tolerations}'
[{"operator":"Exists"}]

kube-proxy runs as system-node-critical, the highest class there is. Reserve the two system classes for agents the node genuinely cannot run without, such as the CNI and CSI node plugins. For your own agents, create a PriorityClass with a high value, at most 1,000,000,000, the ceiling for user-defined classes, and set priorityClassName in the template. Set requests as well: when a node runs short, a pod whose usage stays within its requests is ranked behind every pod that exceeds them, whatever their priorities.

Watch the system DaemonSets on your cluster

  1. kubectl --context kind-kx -n kube-system get daemonsets -o wide
  2. kubectl --context kind-kx -n kube-system get daemonset kindnet -o jsonpath='{.spec.template.spec.tolerations}'
  3. kubectl --context kind-kx cordon kx-worker
  4. kubectl --context kind-kx -n kube-system delete pod -l k8s-app=kube-proxy --field-selector spec.nodeName=kx-worker
  5. kubectl --context kind-kx -n kube-system get pods -l k8s-app=kube-proxy -o wide --field-selector spec.nodeName=kx-worker
  6. kubectl --context kind-kx uncordon kx-worker

For your own kind cluster kx: copy a command and paste it into your terminal. Run in the simulator runs the same command in this page's simulated cluster instead; nothing on this page touches your machine. A new kube-proxy pod lands on the cordoned node within seconds, because every DaemonSet pod tolerates the unschedulable taint.

Actual state

Check your understanding

5 checks

Your first answer to each check is the one that counts. After a miss you can answer again; passing every check reconciles the lesson.

  1. Check 1 of 5

    A DaemonSet with no node selector and no tolerations of its own reports DESIRED 3 on the kx cluster, which has four nodes. Why?

  2. Check 2 of 5

    A DaemonSet's update strategy sets maxSurge: 1 and maxUnavailable: 0. What happens on each node during an image update?

  3. Check 3 of 5

  4. Check 4 of 5

    You cordon kx-worker and then delete the DaemonSet pod on it. What happens?

  5. Check 5 of 5

    Which of these node-level tools does not need a DaemonSet of its own?

Lesson not yet reconciled

Desired: 4 objectives, 0 metReconciled: 4 of 4 objectives met

  • Run one pod per eligible node and restrict it to a subset with nodeSelector or node affinity. (not yet met)
  • Explain how DaemonSet pods tolerate taints that repel other workloads. (not yet met)
  • Tune a DaemonSet rolling update with maxUnavailable and maxSurge. (not yet met)
  • Name the workloads that belong in a DaemonSet and the ones that do not. (not yet met)

Pass every check above to reconcile this lesson.

Every check has passed, so the desired state is met. First-try accuracy: 0 of 5. This lesson's review cards are in your queue.

Practice

Put this lesson to work on the simulated cluster. Everything runs in your browser, with nothing to install.

Changed since the notes

This lesson draws on an earlier set of study notes. Where the documentation contradicts a claim in them, qualifies it or has moved past it, the claim is listed here with the corrected statement and the source it was checked against.

Show 6 corrections
  1. Stale, true once, no longerDaemonSets, Jobs, and CronJobs

    The notes said'use the newer timeZone field (if your cluster version supports it)'

    CorrectedCronJob spec.timeZone has been GA since 1.27 (gate removed 1.29), so every EKS-supported version (1.31 to 1.37) has it; drop the hedge. Values are IANA names such as Etc/UTC; CRON_TZ/TZ inside the schedule string are not supported.

    Sourcekubernetes.io/docs/concepts/workloads/controllers/cron-jobs#time-zones;%20https://kubernetes.io/docs/reference/command-line-tools-reference/feature-gates/

  2. Stale, true once, no longerDaemonSets, Jobs, and CronJobs

    The notes said'DaemonSet pods bypass the normal scheduler by default in older Kubernetes versions'

    CorrectedHistorical only: ScheduleDaemonSetPods went GA in 1.17 and the gate was removed in 1.18. DaemonSet pods are scheduled by kube-scheduler using node affinity that the DaemonSet controller injects. Frame it as history or drop it.

    Sourcekubernetes.io/docs/reference/command-line-tools-reference/feature-gates

  3. Stale, true once, no longerDaemonSets, Jobs, and CronJobs

    The notes saidJob features limited to completions/parallelism/backoffLimit/ttl

    CorrectedCurrent GA Job features beyond the basics: podFailurePolicy (GA 1.31), backoffLimitPerIndex with Indexed Jobs (GA 1.33), successPolicy (GA 1.33) and podReplacementPolicy (GA 1.34). All are GA on EKS 1.34 to 1.37; on 1.31 to 1.33 the later ones are beta.

    Sourcekubernetes.io/docs/concepts/workloads/controllers/job/;%20https://kubernetes.io/docs/reference/command-line-tools-reference/feature-gates

  4. Stale, true once, no longerDaemonSets, Jobs, and CronJobs

    The notes saidSidecar handling in Jobs is unaddressed

    CorrectedNative sidecar containers (an initContainer with restartPolicy: Always) are GA in 1.33 (beta and on by default since 1.29). They start before and run alongside the main containers, and the kubelet terminates them after the main containers exit, so they no longer block Job completion.

    Sourcekubernetes.io/docs/concepts/workloads/pods/sidecar-containers

  5. Wrong, not trueDaemonSets, Jobs, and CronJobs

    The notes said'Unlike Deployments, there's no maxSurge because DaemonSets run exactly one pod per node; you can't create surge pods'

    CorrectedDaemonSet RollingUpdate supports maxSurge (beta 1.22, GA 1.25). With maxSurge > 0 (and maxUnavailable 0) the new pod starts on the node before the old one is killed, so two pods briefly run on the node.

    Sourcekubernetes.io/docs/tasks/manage-daemon/update-daemon-set

  6. Nuance, true with conditionsDaemonSets, Jobs, and CronJobs

    The notes saidLists 'cAdvisor' among DaemonSet monitoring agents

    CorrectedcAdvisor is embedded in the kubelet and its container metrics are scraped from the kubelet's /metrics/cadvisor endpoint; running cAdvisor as a separate DaemonSet is unusual. Better examples: node-exporter, Fluent Bit, the CloudWatch agent or an OpenTelemetry Collector.

    Sourcekubernetes.io/docs/concepts/cluster-administration/system-metrics

Every correction across the guide, by note and topic.

Sources

Checked against kubernetes.io and AWS documentation for Kubernetes 1.37 on .

  1. kubernetes.io/docs/concepts/workloads/controllers/daemonset
  2. kubernetes.io/docs/tasks/manage-daemon/update-daemon-set
  3. kubernetes.io/docs/reference/kubernetes-api/workload-resources/daemon-set-v1
  4. kubernetes.io/docs/concepts/scheduling-eviction/taint-and-toleration
  5. kubernetes.io/docs/concepts/scheduling-eviction/pod-priority-preemption
  6. kubernetes.io/docs/concepts/cluster-administration/system-metrics
  7. kubernetes.io/docs/reference/command-line-tools-reference/feature-gates-removed

DaemonSets

↓ ↑ step, 1 to 6 scene, Esc leave

kind cluster kxLast command: Nothing run yet