Sub topic 9
What happens when a node has several taints
This chapter assumes you can add a taint with kubectl taint, write a toleration in a pod spec, and tell the three effects apart: NoSchedule, PreferNoSchedule and NoExecute. Real nodes often carry more than one taint, so you need to know how the scheduler combines them.
The filter model
Kubernetes does not check taints one by one and stop at the first match. It works like a filter:
- Take all taints on the node.
- Remove every taint that one of the pod's tolerations matches.
- Look at the taints that remain. Their effects decide what happens to the pod.
A pod must tolerate every taint that would block it. Tolerating most of them is not enough.
What the remaining taints do
| Remaining taints include | Result for the pod |
|---|---|
| At least one `NoSchedule` | The scheduler does not place the pod on the node. A pod already running there is not evicted by this taint. |
| No `NoSchedule`, but at least one `PreferNoSchedule` | The scheduler tries to avoid the node. It can still use it if nothing better exists. |
| At least one `NoExecute` | The scheduler does not place the pod on the node. A running pod is evicted. |
If no taints remain, the node is acceptable as far as taints go. Other filters, such as resource requests and node affinity, still apply.
A worked example
Add three taints to node1:
kubectl taint nodes node1 key1=value1:NoSchedule
kubectl taint nodes node1 key1=value1:NoExecute
kubectl taint nodes node1 key2=value2:NoSchedule
kubectl describe node node1 | grep -A3 TaintsNow create a pod that tolerates the first two taints but not the third:
apiVersion: v1
kind: Pod
metadata:
name: partial-tolerations
spec:
containers:
- name: app
image: nginx
tolerations:
- key: "key1"
operator: "Equal"
value: "value1"
effect: "NoSchedule"
- key: "key1"
operator: "Equal"
value: "value1"
effect: "NoExecute"After the filter removes the two matched taints, key2=value2:NoSchedule remains. The scheduler will not place this pod on node1, and the pod stays Pending if no other node fits.
Suppose the pod was already running on node1 before you added the key2 taint. It keeps running. The only remaining taint has the NoSchedule effect, and that effect affects scheduling only. The NoExecute taint is tolerated, so no eviction happens either. If you later added key2=value2:NoExecute and the pod had no matching toleration, the kubelet-side eviction logic would remove it.
Several NoExecute taints and tolerationSeconds
A running pod can match more than one NoExecute taint, and each matching toleration may carry its own tolerationSeconds. The pod is evicted when the shortest of those periods runs out. If any matching toleration has no tolerationSeconds, that one lets the pod stay indefinitely on its own account, but the other taints still count.
A pod that is missing a toleration for a NoExecute taint is evicted immediately. A toleration with a large tolerationSeconds for a different taint does not delay this.
Common mistakes
- Tolerating only the taint you added. Another team or a built-in controller may have added a second taint. Run
kubectl describe nodebefore you write tolerations. - Matching the key but not the effect. A toleration with
effect: "NoSchedule"does not cover a taint with the same key andNoExecute. Leaveeffectempty to match every effect for that key. - Expecting an eviction from a
NoScheduletaint. OnlyNoExecuteevicts running pods.
Exercise
A node has the taints team=a:NoSchedule, disk=slow:PreferNoSchedule and maint=true:NoExecute. A pod tolerates only team=a:NoSchedule. Can the scheduler place it on this node? What if the pod is already running there when the maint taint is added?
Show answer
No, the scheduler will not place it, because the untolerated maint=true:NoExecute taint remains after filtering. The untolerated PreferNoSchedule taint would only lower the node's preference. If the pod is already running when maint=true:NoExecute is added, it is evicted, because it has no toleration for that taint.