Scheduling Pods with Taints and Tolerations in Kubernetes
Taint one of the worker nodes to repel work
Use the following command to taint the node:
kubectl get nodes
kubectl taint node $nodeName node-type=prod:NoSchedule
Schedule a pod to the dev environment
Use the following YAML to specify a pod that will be scheduled to the dev environment:
dev-pod.yaml
Use the following command to create the pod:
Allow a pod to be scheduled to the prod environment
Use the following YAML to create a deployment and a pod that will tolerate the prod environment:
prod-deployment.yaml
Use the following command to create the pod:
Verify each pod has been scheduled and verify the toleration.
Use the following command to verify the pods have been scheduled:
Scale up the deployment:
We can see the prod pods will be deployed on node .102 or .103 where as the dev-pod would only ever be deployed on .103 because of the taint on node .102
Verify the toleration of the production pod:
I found the video didn't do a great job explaining what was happening but to show it's working, I made a new deployment and tried making pods until it crashed because the tainted node wouldn't accept them,
test.yaml
Use the following command to create the pod:
We can see the test pods won't get deployed on node .102 because unlike the prod code it doesn't have the toleration set to bypass the taint on the node.