DaemonSets — One Pod Per Node
A DaemonSet ensures that exactly one copy of a pod runs on every node in the cluster (or on specified nodes). When a new node is added, the pod is automatically scheduled there.
DaemonSets are perfect for infrastructure workloads like logging agents, monitoring exporters, and network plugins.
How DaemonSets Work
Cluster with 3 nodes:
┌──────────┐ ┌──────────┐ ┌──────────┐
│ Node 1 │ │ Node 2 │ │ Node 3 │
│ ┌──────┐ │ │ ┌──────┐ │ │ ┌──────┐ │
│ │Pod A │ │ │ │Pod A │ │ │ │Pod A │ │
│ └──────┘ │ │ └──────┘ │ │ └──────┘ │
└──────────┘ └──────────┘ └──────────┘
New node joins:
┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐
│ Node 1 │ │ Node 2 │ │ Node 3 │ │ Node 4 │
│ ┌──────┐ │ │ ┌──────┐ │ │ ┌──────┐ │ │ ┌──────┐ │
│ │Pod A │ │ │ │Pod A │ │ │ │Pod A │ │ │ │Pod A │ │
│ └──────┘ │ │ └──────┘ │ │ └──────┘ │ │ └──────┘ │
└──────────┘ └──────────┘ └──────────┘ └──────────┘
Automatically deployed to Node 4!
Creating a DaemonSet
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: fluentd
namespace: kube-system
spec:
selector:
matchLabels:
name: fluentd
template:
metadata:
labels:
name: fluentd
spec:
tolerations:
- key: node-role.kubernetes.io/control-plane
effect: NoSchedule
containers:
- name: fluentd
image: fluentd:v1.16
resources:
limits:
memory: "200Mi"
cpu: "100m"
volumeMounts:
- name: varlog
mountPath: /var/log
volumes:
- name: varlog
hostPath:
path: /var/log
tolerations — The control plane node has a taint that prevents normal pods from running. This DaemonSet tolerates that taint so it runs everywhere, including the master.
Common DaemonSet Use Cases
Logging — Collect logs from every node (Fluentd, Filebeat).
Monitoring — Export node metrics (Prometheus Node Exporter).
Networking — Manage network plugins (Calico, Weave Net).
Storage — Provide storage drivers on every node (Ceph, GlusterFS).
Managing DaemonSets
# Apply a DaemonSet
kubectl apply -f daemonset.yaml
# Check which pods are running on which nodes
kubectl get pods -o wide
# Update the DaemonSet image
kubectl set image daemonset/fluentd fluentd=fluentd:v1.17
# Rollback
kubectl rollout undo daemonset/fluentd