Taints and Tolerations Example in Kubernetes

Shashi Vishwakarma
3 min readJan 13, 2021

--

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

Photo by Kenrick Baksh on Unsplash

Pods are only accepted by Nodes if they match desired toleration otherwise Pods remains in Pending state or looks 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 seen 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 taint 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 see 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.yamlkubectl 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 it again. Edit student.yaml and add below highlighted section in yaml.

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

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

Have a good day. Keep learning and keep sharing..!!

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

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

Originally published at http://learning-madeeasy.blogspot.com.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Shashi Vishwakarma
Shashi Vishwakarma

Written by Shashi Vishwakarma

Senior Software/AI Engineer , Technical Writer

No responses yet

Write a response