Kubernetes Tutorial · Workloads · Lesson 11 of 26
DaemonSets
Run one pod on every node (or a chosen set of nodes) for log shippers, monitoring agents and network plugins.
One per node
A DaemonSet makes sure every matching node runs one copy of a pod; new nodes get one automatically. Typical uses: log collectors (Fluent Bit), metrics agents (node-exporter), CNI and storage plugins.
- Restrict to some nodes with a
nodeSelectoror affinity. - Add tolerations to run on tainted nodes (for example control-plane nodes).
- DaemonSet pods often mount host paths (
/var/log), which makes them powerful: keep their permissions tight.
kubectl create namespace demo-ds > /dev/null
trap 'kubectl delete namespace demo-ds --wait=false > /dev/null' EXIT
cat > ds.yaml <<'EOF'
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: node-agent
spec:
selector:
matchLabels: {app: node-agent}
template:
metadata:
labels: {app: node-agent}
spec:
tolerations:
- key: node-role.kubernetes.io/control-plane
effect: NoSchedule
containers:
- name: agent
image: busybox:1.37
command: ["sh", "-c", "echo watching node $NODE; sleep 3600"]
env:
- name: NODE
valueFrom: {fieldRef: {fieldPath: spec.nodeName}}
EOF
kubectl -n demo-ds apply -f ds.yaml > /dev/null
kubectl -n demo-ds rollout status daemonset/node-agent --timeout=120s > /dev/null
kubectl -n demo-ds get daemonset node-agent -o custom-columns=DESIRED:.status.desiredNumberScheduled,READY:.status.numberReady
kubectl -n demo-ds logs daemonset/node-agent
Output
DESIRED READY 1 1 watching node rc-docs-control-plane
Run this on your computer — see “Get Started” for setup.
See DaemonSet.
Test yourself
Which workload type fits a log collector that must run on every node?
DeploymentStatefulSetDaemonSetJob
Show answer
Answer: DaemonSet
DaemonSets schedule exactly one pod per matching node, including new nodes.