Sub topic 12
DaemonSets and automatic tolerations
This chapter assumes you know how taints, the three effects, and toleration matching work, and that you can read a DaemonSet manifest. It covers how DaemonSet pods get tolerations you never wrote, and which taints you still have to tolerate yourself.
Why DaemonSets are a special case
A DaemonSet runs one pod on every node, or on every node that matches a selector. Typical uses are log shippers, monitoring agents, and network plugins. These pods must stay on a node even when it is unhealthy, because they are often what reports or repairs the problem.
A node under stress gets taints such as node.kubernetes.io/disk-pressure:NoSchedule. A normal pod would be kept out. A DaemonSet pod must not be, so the DaemonSet controller adds tolerations to its pods automatically.
Tolerations the controller adds
The DaemonSet controller adds these tolerations to every pod it creates:
| Taint key | Effect | Notes |
|---|---|---|
| `node.kubernetes.io/not-ready` | NoExecute | No `tolerationSeconds`, so the pod is never evicted for this |
| `node.kubernetes.io/unreachable` | NoExecute | No `tolerationSeconds` |
| `node.kubernetes.io/disk-pressure` | NoSchedule | |
| `node.kubernetes.io/memory-pressure` | NoSchedule | |
| `node.kubernetes.io/pid-pressure` | NoSchedule | |
| `node.kubernetes.io/unschedulable` | NoSchedule | Lets the pod run on cordoned nodes |
| `node.kubernetes.io/network-unavailable` | NoSchedule | Added only when the pod uses `hostNetwork: true` |
Compare this with ordinary pods. An admission step gives them tolerations for not-ready and unreachable with tolerationSeconds: 300, so they are evicted after five minutes. DaemonSet pods have no time limit, so they stay bound to the node.
What is not tolerated automatically
The controller only covers the node condition taints. It does not touch taints that an administrator or a distribution adds. Two common cases:
- The control plane taint
node-role.kubernetes.io/control-plane:NoSchedule. A DaemonSet will skip control plane nodes unless you tolerate it. - Your own taints, such as
dedicated=gpu:NoSchedulefrom the dedicated-node pattern.
Your tolerations are merged with the automatic ones. You do not need to repeat the automatic ones.
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: node-logger
spec:
selector:
matchLabels:
app: node-logger
template:
metadata:
labels:
app: node-logger
spec:
tolerations:
- key: "node-role.kubernetes.io/control-plane"
operator: "Exists"
effect: "NoSchedule"
- key: "dedicated"
operator: "Exists"
effect: "NoSchedule"
containers:
- name: agent
image: busybox:1.36
command: ["sh", "-c", "while true; do echo running; sleep 60; done"]This DaemonSet runs on ordinary nodes, control plane nodes, and any node tainted with the key dedicated and effect NoSchedule, whatever the value.
Checking the result
After you apply the manifest, read the tolerations on a created pod:
kubectl apply -f node-logger.yaml
kubectl get pod -l app=node-logger -o jsonpath='{.items[0].spec.tolerations}'The output lists your two tolerations plus the automatic ones. If a node is missing a pod, compare kubectl get pods -o wide against kubectl get nodes, then run kubectl describe node <name> and look at its taints.
How placement works
The DaemonSet controller creates one pod per eligible node. Each pod carries a node affinity that pins it to a single node name, and the default scheduler then binds it. Taints and tolerations are therefore checked as for any pod, which is why the automatic tolerations are needed. Narrow a DaemonSet to some nodes with nodeSelector or node affinity in the pod template. A toleration only permits placement. It never attracts the pod to a node.
Exercise
A DaemonSet pod is running on a node. The node becomes unreachable and gets the taint node.kubernetes.io/unreachable:NoExecute. A normal pod on the same node has default tolerations. What happens to each pod, and why?
Show answer
The normal pod is evicted after about 300 seconds, because its default toleration for unreachable has tolerationSeconds: 300. The DaemonSet pod is not evicted, because the DaemonSet controller adds a toleration for unreachable:NoExecute with no tolerationSeconds, so it tolerates the taint indefinitely.