Applying Taints to Nodes
What you'll learn: How to use kubectl taint commands to add, modify, and remove taints on nodes for workload isolation.
The Core Concept
Now that you understand taint effects (NoSchedule, PreferNoSchedule, NoExecute), it's time to actually apply them. Taints are node-level markings managed via the kubectl taint command. Think of it like putting "wet paint" signs on specific benches in a park—only people with the right gear (tolerations) will sit there.
Basic Taint Syntax
To add a taint to a node:
kubectl taint nodes <node-name> key=value:effect
For example, to mark a node for GPU workloads only:
kubectl taint nodes node-gpu-01 workload=gpu:NoSchedule
This prevents any pod without a matching toleration from scheduling on node-gpu-01.
Modifying Taints
To change an existing taint, add the --overwrite flag:
kubectl taint nodes node-gpu-01 workload=gpu:PreferNoSchedule --overwrite
Removing Taints
To remove a taint, append a minus sign (-) to the key:
kubectl taint nodes node-gpu-01 workload-
This removes any taint with the workload key, regardless of its value or effect.
Practical Use Cases
- Dedicated nodes:
kubectl taint nodes prod-db-01 dedicated=database:NoSchedule - Maintenance mode:
kubectl taint nodes worker-03 maintenance=true:NoExecute(evicts running pods immediately) - Hardware-specific:
kubectl taint nodes ssd-node-01 disk-type=ssd:NoSchedule
Verification
Check node taints with:
kubectl describe node <node-name> | grep Taints
Key Takeaway: Use kubectl taint nodes <node> key=value:effect to add taints, --overwrite to modify them, and key- to remove them, enabling precise control over workload placement across your cluster.