Sub topic 6
How a toleration matches a taint
This chapter assumes you can read pod manifests, know that a node taint has a key, value, and effect, and have seen the three effects (NoSchedule, PreferNoSchedule, NoExecute). Here you learn the exact rules that decide whether a toleration cancels a taint.
The matching rules
A toleration matches a taint when all of these hold:
- The keys are the same.
- The effects are the same.
- The operator condition holds. With
Equal, the values must also be the same. WithExists, no value is compared.
Comparisons are exact and case-sensitive. Dedicated does not match dedicated.
The Equal operator
Equal is the default if you omit operator. This pod tolerates the taint dedicated=gpu:NoSchedule.
apiVersion: v1
kind: Pod
metadata:
name: gpu-job
spec:
containers:
- name: app
image: nginx
tolerations:
- key: "dedicated"
operator: "Equal"
value: "gpu"
effect: "NoSchedule"If the node were tainted dedicated=cpu:NoSchedule, this toleration would not match, because the values differ.
The Exists operator
Exists ignores the value, so you must leave value out. The API server rejects a toleration that sets operator: Exists together with a value.
apiVersion: v1
kind: Pod
metadata:
name: any-dedicated-job
spec:
containers:
- name: app
image: nginx
tolerations:
# Matches any value for the key "dedicated", with the NoSchedule effect
- key: "dedicated"
operator: "Exists"
effect: "NoSchedule"Two special cases
Two omissions have a defined meaning:
- Empty key with
Existsmatches every taint, whatever its key, value, and effect. - Empty effect matches all effects for the given key.
tolerations:
# Matches every effect of any "dedicated" taint
- key: "dedicated"
operator: "Exists"
# Matches every taint on every node
- operator: "Exists"The catch-all toleration is powerful. A pod with it can run on tainted nodes it was never meant for, including nodes that are unreachable or under pressure. Use it only for system-level workloads.
An empty key with Equal is not a valid combination. The API server rejects it.
Quick reference
| Toleration | Matches taint `dedicated=gpu:NoSchedule`? |
|---|---|
| `dedicated`, `Equal`, `gpu`, `NoSchedule` | Yes |
| `dedicated`, `Equal`, `cpu`, `NoSchedule` | No, value differs |
| `dedicated`, `Equal`, `gpu`, `NoExecute` | No, effect differs |
| `dedicated`, `Exists`, `NoSchedule` | Yes |
| `dedicated`, `Exists`, no effect | Yes |
| no key, `Exists` | Yes |
The optional tolerationSeconds field
tolerationSeconds applies only to taints with the NoExecute effect. It sets how long a pod stays bound to a node after the taint appears. Matching still follows the same rules.
tolerations:
- key: "node.kubernetes.io/unreachable"
operator: "Exists"
effect: "NoExecute"
tolerationSeconds: 60Common errors
- Wrong effect. The taint says
NoExecuteand the toleration saysNoSchedule. There is no match. - Value with
Exists. The manifest is rejected at creation time. - Typos in the key or value. The pod stays Pending, and the scheduler event lists the untolerated taint.
- Assuming a toleration attracts the pod. A matching toleration only permits scheduling. It does not choose the node.
Exercise
A node has the taint team=data:NoSchedule. Which of these tolerations lets a pod schedule there: (a) key team, operator Equal, value Data, effect NoSchedule; (b) key team, operator Exists, effect NoSchedule; (c) key team, operator Exists, value data, effect NoSchedule?
Show answer
Only (b). Option (a) fails because values are case-sensitive and Data differs from data. Option (c) is invalid because Exists must not carry a value, so the API server rejects the pod.