Kubernetes - Taints and Tolerations âĸī¸
Description đ
Taints
and Tolerations
are features that allow you to control the placement of pods on nodes. Taints are applied to nodes, and tolerations are applied to pods.A taint
on a node
instructs the node
to repel all pods
that do not tolerate
the taint
.
Basic Commands
đ
Taints - Node
-
taint-effect: Â
NoSchedule
,PreferNoSchedule
,NoExecute
-
generic
kubectl taint nodes <node-name> <key>=<value>:<taint-effect>
-
example
kubectl taint nodes node1 app=blue:NoSchedule
-
to see if
taints
exist on anode
kubectl describe node node01 | grep taint
Tolerations - Pod
spec:
tolerations:
- key: app
operator: "Equal"
value: blue
effect: NoSchedule
Examples đ§Š
-
sample
pod
withtolerations
definitionapiVersion: v1 kind: Pod metadata: name: my-app spec: containers: - name: nginx image: nginx tolerations: - key: app operator: "Equal" value: blue effect: NoSchedule
Bee and Mosquito Example
đđĻ
-
create
node01
nodeapiVersion: v1 kind: Node metadata: name: node01 spec:
-
create
controlplane
nodeapiVersion: v1 kind: Node metadata: name: controlplane # add a taint with key spray and value mortien and effect NoSchedule taint: - key: spray value: mortien effect: NoSchedule spec:
-
apply
taint
kubectl taint nodes node01 spray=mortein:NoSchedule
-
bee
pod
definition đapiVersion: v1 kind: Pod metadata: name: bee spec: containers: - name: nginx-bee image: nginx tolerations: - key: spray operator: "Equal" value: mortein effect: NoSchedule
-
mosquito
pod
definition đĻapiVersion: v1 kind: Pod metadata: name: mosquito spec: containers: - name: nginx-mosquito image: nginx
- create the bee and mosquito
pods
and watch what happens- bee will be scheduled on node01 and mosquito will not be scheduled on any
node
- bee will be scheduled on node01 and mosquito will not be scheduled on any
- remove the taint on
controlplane
- mosquito will be scheduled on
controlplane
- mosquito will be scheduled on