Contents

Kubernetes Taint and Toleration

You must know

Taint and Toleration
Usually it uses not to bind PODs to specific Node.
For example, there’s a Node that has GPU resources then you want not to bind PODs that don’t need GPU resources.
At this time, you can use taint and toleration.

Taint

taint
taint is to apply to the Node.

Commands

Add taint command structure

1
kubectl taint nodes [node-name] [key]=[value]:[taint-effect]
NameExample
[node-name]node01
[key]app
[value]myapp
[taint-effect]NoSchedule / PreferNoSchedule / NoExecute

Add taint

1
kubectl taint nodes node01 app=myapp:NoSchedule

Remove taint

1
2
# Focus on tailing dash(-)
kubectl taint nodes node01 app=myapp:NoSchedule-

Taint Effect

NoSchedule
If there’s no toleration in the PODSpec, the scheduler does not bind the POD to the Node.
It’s not affect to exist PODs.
PreferNoSchedule
If there’s no toleration in the PODSpec, the scheduler try not to bind the POD to the Node, but it’s not a necessary.
There’s not enough resources on the cluster, the scheduler could bind the POD to the Node that has taint.
NoExecute
If there’s no toleration in the PODSpec, the scheduler does not bind the POD to the Node.
The exists PODs that don’t have toleration are terminated.

Toleration

tolerations
tolerations is to set PODs.
In the tolerations definitions, you need to set double quotes(") for the values.

POD YAML

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
apiVersion: v1
kind: Pod
metadata:
  name: myapp-pod
spec:
  containers:
    - name: nginx-container
      image: nginx
  tolerations:
    - key: "app"
      operator: "Equal"
      value: "myapp"
      effect: "NoSchedule"

operator

operator
Equal
If the operator is Equal, the value must set same value of the taint.
Exists
If the operator is Exists, you must not define the value.

When taint and tolerations matched

operator = Equal

tainttolerations
keykey
valuevalue
taint-effecteffect

operator = Exists

tainttolerations
keykey
taint-effecteffect