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
taintsexist on anodekubectl describe node node01 | grep taint
Tolerations - Pod
spec:
tolerations:
- key: app
operator: "Equal"
value: blue
effect: NoSchedule
Examples đ§Š
-
sample
podwithtolerationsdefinitionapiVersion: 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
node01nodeapiVersion: v1 kind: Node metadata: name: node01 spec: -
create
controlplanenodeapiVersion: 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
taintkubectl taint nodes node01 spray=mortein:NoSchedule -
bee
poddefinition đapiVersion: v1 kind: Pod metadata: name: bee spec: containers: - name: nginx-bee image: nginx tolerations: - key: spray operator: "Equal" value: mortein effect: NoSchedule -
mosquito
poddefinition đĻapiVersion: v1 kind: Pod metadata: name: mosquito spec: containers: - name: nginx-mosquito image: nginx - create the bee and mosquito
podsand 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