DaemonSet
Run a pod on every node in the cluster automatically.
Time: ~10 minutes Difficulty: Beginner
What You Will Learn
Section titled “What You Will Learn”- 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
Deploy
Section titled “Deploy”Navigate to the demo directory:
cd demos/daemonsetkubectl apply -f manifests/namespace.yamlkubectl apply -f manifests/node-monitor.yamlkubectl apply -f manifests/log-collector.yamlVerify
Section titled “Verify”# One pod per node for each DaemonSetkubectl get pods -n daemonset-demo -o wide
# See which nodes have podskubectl get daemonsets -n daemonset-demoOn minikube (single node), you will see one pod per DaemonSet. On a multi-node cluster, each DaemonSet would have one pod per node.
Check the Node Monitor
Section titled “Check the Node Monitor”The node-monitor pod reports CPU, memory, disk, and container count every 30 seconds:
kubectl logs -l app=node-monitor -n daemonset-demo --tail=15Check the Log Collector
Section titled “Check the Log Collector”The log-collector tails the most recent container log file on the node:
kubectl logs -l app=log-collector -n daemonset-demo --tail=10What is Happening
Section titled “What is Happening”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 hostKey concepts:
| Feature | How It Works |
|---|---|
| One pod per node | The DaemonSet controller schedules exactly one pod on each node |
| Tolerations | node-monitor tolerates the control-plane taint, so it runs there too |
| hostPath | Mounts /var/log/containers from the node filesystem into the pod |
| Rolling updates | maxUnavailable: 1 updates one node at a time |
| New nodes | When a node joins the cluster, the DaemonSet automatically schedules a pod on it |
Experiment
Section titled “Experiment”-
Add a second minikube node and watch the DaemonSet auto-schedule:
Terminal window minikube node addkubectl get pods -n daemonset-demo -o wide -w -
Remove the toleration from
node-monitor.yamland re-apply. On clusters with tainted control-plane nodes, the pod will be evicted from those nodes. -
Restrict the DaemonSet to specific nodes using
nodeSelector:spec:template:spec:nodeSelector:disk: ssd
Cleanup
Section titled “Cleanup”kubectl delete namespace daemonset-demoIf you added a second node:
minikube node delete m02Further Reading
Section titled “Further Reading”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.
Next Step
Section titled “Next Step”Move on to HPA to learn about automatic horizontal scaling based on load.