Verifying and Managing Taints
Verifying Taints
You can use the kubectl get nodes
command to view the taints applied to a node. The output will show the taints in the TAINTS
column.
kubectl get nodes
NAME STATUS ROLES AGE VERSION TAINTS
node1 Ready <none> 5d v1.21.0 app=backend:NoSchedule
node2 Ready <none> 5d v1.21.0 <none>
In the example above, node1
has a taint with the key app
, value backend
, and effect NoSchedule
.
You can also use the kubectl describe node
command to get more detailed information about the taints on a node.
kubectl describe node node1 | grep Taints
Taints: app=backend:NoSchedule
Managing Taints
Adding a Taint
You can add a taint to a node using the kubectl taint
command, as shown in the previous section.
kubectl taint nodes node1 app=backend:NoSchedule
Removing a Taint
To remove a taint from a node, you can use the same kubectl taint
command, but prefix the taint key with a -
to indicate removal.
kubectl taint nodes node1 app=backend:NoSchedule-
This will remove the app=backend:NoSchedule
taint from node1
.
Updating a Taint
To update a taint, you can simply add a new taint with the same key but a different value or effect.
kubectl taint nodes node1 app=frontend:NoSchedule
This will update the taint on node1
to app=frontend:NoSchedule
, overwriting the previous taint.
Taint and Toleration Example
Here's an example of a pod that tolerates the app=backend:NoSchedule
taint:
apiVersion: v1
kind: Pod
metadata:
name: backend-pod
spec:
containers:
- name: backend-container
image: backend:v1
tolerations:
- key: "app"
operator: "Equal"
value: "backend"
effect: "NoSchedule"
This pod can be scheduled on the node1
node, which has the app=backend:NoSchedule
taint.