✅ Summary Table: Taints vs Tolerations
| Concept | Node Setting (Taint) | Pod Setting (Toleration) |
|---|---|---|
| Taints | kubectl taint nodes <node> <key>=<value>:<effect> | ❌ Not defined in pod spec (repels pods unless tolerated) |
| Tolerations | ❌ Not applicable (defined in pods only) | tolerations: - key, value, effect, operator in pod spec |
🧠 What Are Taints and Tolerations?
- Taints: Mark nodes to repel pods unless those pods have the matching toleration.
- Tolerations: Pods use tolerations to "tolerate" the taint and be scheduled on tainted nodes.
🔷 1. Taint on Node
This command taints a node to only accept pods with the key dedicated=ml:
kubectl taint nodes node1 dedicated=ml:NoSchedule⛔️ Any pod without a matching toleration will not be scheduled on node1.
🔷 2. Toleration in Pod
▶ Example Pod with Matching Toleration
apiVersion: v1
kind: Pod
metadata:
name: ml-pod
spec:
tolerations:
- key: "dedicated"
operator: "Equal"
value: "ml"
effect: "NoSchedule"
containers:
- name: ml-container
image: tensorflow/tensorflow✅ Result: This pod can be scheduled on the tainted node.
▶ Example Pod Without Toleration
apiVersion: v1
kind: Pod
metadata:
name: generic-pod
spec:
containers:
- name: app
image: nginx⛔️ Result: This pod cannot be scheduled on the node tainted with dedicated=ml:NoSchedule.
🔁 Types of Taint Effects
| Effect | Description |
|---|---|
NoSchedule | Do not allow scheduling unless pod has matching toleration |
PreferNoSchedule | Try to avoid scheduling unless tolerated (soft rule) |
NoExecute | Evict already running pods unless tolerated |
🧪 NoExecute Taint Example (Evicts Pods)
Taint the node:
kubectl taint nodes node1 key1=value1:NoExecuteToleration with tolerationSeconds (only tolerate for 60s)
apiVersion: v1
kind: Pod
metadata:
name: toleration-pod
spec:
tolerations:
- key: "key1"
operator: "Equal"
value: "value1"
effect: "NoExecute"
tolerationSeconds: 60
containers:
- name: app
image: nginx✅ Result: Pod can run on the node but will be evicted after 60s if taint is not removed.
🧩 Summary Comparison
| Feature | Taints (Node) | Tolerations (Pod) |
|---|---|---|
| Defined On | Node | Pod |
| Purpose | Repel certain pods | Allow pods to tolerate taints |
| Required Fields | key=value:effect | key, operator, value, effect (optionally tolerationSeconds) |
| Effect Types | NoSchedule, PreferNoSchedule, NoExecute | Must match effect to tolerate |
| Default Behavior | Pods are repelled by default | Pods must explicitly tolerate taints |