Taints on nodes repel pods. Tolerations on pods let them ignore specific taints. Together they give you control over scheduling.
Taint effects
- NoSchedule — pods without a matching toleration won’t be scheduled on the node.
- PreferNoSchedule — the scheduler avoids the node but will use it if there’s nowhere else.
- NoExecute — pods without a matching toleration are evicted and won’t be rescheduled there.
Applying a taint
kubectl taint nodes node1 type=db:NoSchedule
This prevents any pod from being scheduled on node1 unless it has a toleration for type=db.
Adding a toleration to a pod
apiVersion: v1
kind: Pod
metadata:
name: db-pod
spec:
containers:
- name: db-container
image: db-image
tolerations:
- key: type
operator: Equal
value: db
effect: NoSchedule
The operator can be Equal (key and value must match) or Exists (only the key must match).
Removing a taint
kubectl taint nodes node1 type:NoSchedule-
The trailing - removes the taint.