Skip to content

DaemonSet

Run a pod on every node in the cluster automatically.

Time: ~10 minutes Difficulty: Beginner

  • DaemonSet: exactly one pod per node, always
  • Tolerations for running on control-plane nodes
  • Mounting host paths (node-level logs, metrics)
  • Rolling update strategy for DaemonSets
  • Real-world use cases: log collectors, monitoring agents, network plugins

Navigate to the demo directory:

Terminal window
cd demos/daemonset
Terminal window
kubectl apply -f manifests/namespace.yaml
kubectl apply -f manifests/node-monitor.yaml
kubectl apply -f manifests/log-collector.yaml
Terminal window
# One pod per node for each DaemonSet
kubectl get pods -n daemonset-demo -o wide
# See which nodes have pods
kubectl get daemonsets -n daemonset-demo

On minikube (single node), you will see one pod per DaemonSet. On a multi-node cluster, each DaemonSet would have one pod per node.

The node-monitor pod reports CPU, memory, disk, and container count every 30 seconds:

Terminal window
kubectl logs -l app=node-monitor -n daemonset-demo --tail=15

The log-collector tails the most recent container log file on the node:

Terminal window
kubectl logs -l app=log-collector -n daemonset-demo --tail=10
manifests/
namespace.yaml # daemonset-demo namespace
node-monitor.yaml # ConfigMap + DaemonSet: reports node stats every 30s
log-collector.yaml # DaemonSet: tails container logs from the host

Key concepts:

FeatureHow It Works
One pod per nodeThe DaemonSet controller schedules exactly one pod on each node
Tolerationsnode-monitor tolerates the control-plane taint, so it runs there too
hostPathMounts /var/log/containers from the node filesystem into the pod
Rolling updatesmaxUnavailable: 1 updates one node at a time
New nodesWhen a node joins the cluster, the DaemonSet automatically schedules a pod on it
  1. Add a second minikube node and watch the DaemonSet auto-schedule:

    Terminal window
    minikube node add
    kubectl get pods -n daemonset-demo -o wide -w
  2. Remove the toleration from node-monitor.yaml and re-apply. On clusters with tainted control-plane nodes, the pod will be evicted from those nodes.

  3. Restrict the DaemonSet to specific nodes using nodeSelector:

    spec:
    template:
    spec:
    nodeSelector:
    disk: ssd
Terminal window
kubectl delete namespace daemonset-demo

If you added a second node:

Terminal window
minikube node delete m02

See docs/deep-dive.md for a detailed explanation of DaemonSet scheduling, update strategies, node affinity vs nodeSelector, tolerations for special nodes, and common production patterns.

Move on to HPA to learn about automatic horizontal scaling based on load.