Question
Taint the worker node node01 with details provided below.
Create a pod called dev-pod-nginx using image nginx, make sure that workloads are not scheduled to this worker node (node01).
Create another pod called prod-pod-nginx using image nginx with toleration to be scheduled on node01.
Details:
key: env_type
value: production
operator: Equal
Effect: NoSchedule
Answer
Get environment details:
kubectl get nodes
kubectl describe node controlplane | greo -i taint
kubectl describe node node01 | greo -i taint
We can see that there are no taints set on the nodes.kubectl taint node node01 env_type=production:NoSchedule
Verify:
kubectl describe node node01 | greo -i taint
Run dev pod:
kubectl run dev-pod-nginx --image=nginx
See, where it is running:
kubectl get po dev-pod-nginx -o wide
we can see that it is scheduled on controlplanekubectl run prod-pod-nginx --image=nginx --dry-run=client -o yaml > prod.yaml
Open prod.yaml and modify it in this way:
apiVersion: v1
kind: Pod
metadata:
labels:
run: prod-pod-nginx
name: prod-pod-nginx
spec:
tolerations:
- key: "env_type"
operator: "Equal"
value: "production"
effect: "NoSchedule"
containers:
- image: nginx
name: prod-pod-nginx
Apply and check if the pod is running on node01:
kubectl apply -f prod.yaml
kubectl get po prod-pod-nginx -o wide
we can see that the pod prod-pod-nginx is running on node01