Taints and Tolerations Example in Kubernetes

Taints and Tolerations are advance scheduling mechanism designed to repel pods if they do not have matching toleration. 

Pods are only accepted by Nodes if they match desired toleration otherwise Pods remains in Pending state or look for another nodes.

In today's example , we will configure nodes and pods with taints and toleration respectively. We will make use of Minikube cluster for managing pods.

Pre-requisite : Minikube Cluster 


As you can see in above picture , we have two pod one with toleration defined and another without toleration. Since minikube is just one node cluster , we will use master node and apply taints on it.

We will see pod scheduling behaviour when toleration applied versus toleration not applied. Let's make sure minikube cluster is running fine and check if master node has taints applied on it.

kubectl describe  nodes minikube | grep -i taints



As you can currently no taints is applied on minikube master node , in this case any pod can be schedule on master node.  But in order to demonstrate , we will go ahead any apply taints on node.  We want to make sure that students with department=computer pod should only be schedule on node.

kubectl taint node minikube department=computer:NoSchedule



Taint is applied on master node and can be checked with describe command. Now Let's create a pod without toleration and deploy in cluster.

kubectl run student --image=nginx --dry-run=client --restart=Never  -o yaml > student.yaml

kubectl apply -f student.yaml

kubectl get pods


You might notice that student pod status goes into Pending state and it does not change as there is no node available for pod to schedule as master has started to repel pod.

Now let's apply toleration in student pod and try to schedule again. Edit student.yaml and add below highlighted section in yaml.


Save student.yaml definition file and re-create pod on minikube cluster.

kubectl delete pod student 
kubectl apply -f student.yaml



Once you do get pods , you can observe that pod is in running state and successfully scheduled on master since there was match of taints and toleration. 

Hope you find blog usefully. Keep learning and keep sharing..!!

Git Link : https://github.com/shashivish/kubernetes-example/tree/master/taintsAndtolerations

Reference : https://kubernetes.io/docs/home/ 






Comments

Popular posts from this blog

JDBC Hive Connection fails : Unable to read HiveServer2 uri from ZooKeeper

Access Kubernetes ConfigMap in Spring Boot Application

Developing Custom Processor in Apache Nifi