Sub topic 6
Tolerating taints, including control plane nodes
This chapter assumes you know Pods, labels, and nodeSelector, and that you can apply YAML with kubectl. It covers how taints affect DaemonSet Pods and how to add tolerations so the Pods run where you need them.
Taints and tolerations in one minute
A taint is a key, an optional value, and an effect that a node carries. It repels Pods that do not tolerate it. A toleration is a matching entry in a Pod spec that allows the Pod to be scheduled on the tainted node. A toleration permits a node but does not require it. It does not attract the Pod to that node.
The effect decides how strong the repulsion is:
| Effect | Behavior |
|---|---|
| `NoSchedule` | New Pods without a matching toleration are not placed on the node. |
| `PreferNoSchedule` | The scheduler avoids the node when it can, but may still use it. |
| `NoExecute` | New Pods are refused, and running Pods without a toleration are evicted. |
Why DaemonSets hit taints
A DaemonSet wants one Pod on every node, so any taint it does not tolerate leaves a gap. Control plane nodes are the most common case. Kubeadm-style clusters taint them with node-role.kubernetes.io/control-plane:NoSchedule. A node-level agent, such as a log collector, will skip those nodes unless you tolerate that taint.
Default tolerations
The DaemonSet controller adds some tolerations to every Pod it creates. You do not write these yourself. They let the Pods keep running when a node is unhealthy:
node.kubernetes.io/not-readywith effectNoExecutenode.kubernetes.io/unreachablewith effectNoExecutenode.kubernetes.io/disk-pressurewith effectNoSchedulenode.kubernetes.io/memory-pressurewith effectNoSchedulenode.kubernetes.io/pid-pressurewith effectNoSchedulenode.kubernetes.io/unschedulablewith effectNoSchedulenode.kubernetes.io/network-unavailablewith effectNoSchedule, added only for Pods that usehostNetwork
The not-ready and unreachable tolerations have no tolerationSeconds. A DaemonSet Pod is therefore never evicted because its node became unhealthy.
The defaults do not cover taints you or your platform add. Control plane taints and custom taints need explicit tolerations.
Tolerating the control plane taint
Add a tolerations list to the Pod template, not to the DaemonSet's top-level spec. This is the manifest from the earlier chapter, trimmed to the relevant part:
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: node-log-agent
namespace: kube-system
spec:
selector:
matchLabels:
app: node-log-agent
template:
metadata:
labels:
app: node-log-agent
spec:
tolerations:
- key: node-role.kubernetes.io/control-plane
operator: Exists
effect: NoSchedule
containers:
- name: agent
image: busybox:1.36
command:
- sh
- -c
- while true; do ls /host-logs | head -n 5; sleep 60; done
volumeMounts:
- name: varlog
mountPath: /host-logs
readOnly: true
volumes:
- name: varlog
hostPath:
path: /var/logoperator: Exists matches the key whatever its value, so you leave value out. With operator: Equal, you must give a value that matches the taint exactly.
Checking taints and results
List the taints on each node:
kubectl get nodes -o custom-columns=NAME:.metadata.name,TAINTS:.spec.taints[*].keyAfter applying the manifest, check that a Pod landed on every node:
kubectl get pods -n kube-system -l app=node-log-agent -o wideThe NODE column should list the control plane node as well as the workers.
Tolerating everything
A toleration with operator: Exists and no key matches every taint:
tolerations:
- operator: ExistsSome system agents, such as network plugins, use this so they run on every node. Use it only when the workload truly needs to be everywhere. It also runs on nodes that an administrator tainted on purpose, for example nodes being drained or reserved for special jobs.
Common errors
- Toleration in the wrong place. It must be under
spec.template.spec. Placed elsewhere, it is rejected or ignored. - Effect mismatch. A toleration with
effect: NoExecutedoes not cover aNoScheduletaint. Omiteffectto match all effects for that key. - Wrong operator.
Equalwith a missing or differentvaluedoes not match. - Expecting tolerations to select nodes. A toleration only allows placement. To limit where Pods run, use
nodeSelectoror node affinity as covered in the previous chapter. - Custom taints added later. If you taint a node after the DaemonSet exists, a Pod without the toleration is evicted only for
NoExecute. ForNoSchedule, existing Pods stay, but replacements are not created.
Diagnosing a gap
If DESIRED is lower than your node count, or a node has no Pod, compare the node's taints with the Pod template's tolerations:
kubectl describe node <node-name> | grep -A3 Taints
kubectl describe daemonset node-log-agent -n kube-systemExercise
A DaemonSet runs on all worker nodes but not on the control plane node, which has the taint node-role.kubernetes.io/control-plane:NoSchedule. What do you add, and where?
Show answer
Add a toleration with key node-role.kubernetes.io/control-plane, operator Exists, and effect NoSchedule under spec.template.spec.tolerations. The controller then creates a Pod on the control plane node.
Exercise
Does a toleration for a taint make a DaemonSet Pod run only on nodes with that taint?
Show answer
No. A toleration only permits placement on tainted nodes. The Pod still runs on untainted nodes. Use nodeSelector or node affinity to restrict placement.