#051 Kubernetes - Taints and Tolerations 2 (Practice)
Tags: kubernetes, devops, tutorial
Published: 2020-08-18 23:03:08

# Introduction
![intro](https://media1.tenor.com/images/f15057a41413c960db1f328ca5a732e3/tenor.gif?itemid=6203225)

this is part 51 from the journey it's a long journey(360 day) so go please check previous parts , and if you need to walk in the journey with me please make sure to follow because I may post more than once in 1 Day but surely I will post daily at least one 😍.

And I will cover lot of tools as we move on.
***
# Files for this lab

all the files can be found on the repository of this journey , if you already have it just pull if not clone it.
Files can be found [here](https://github.com/OmarElKhatibCS/DevOpsJourney/tree/master/app_051)
***
# Lab
![app39](https://dev-to-uploads.s3.amazonaws.com/i/b1hyx2li74l8a1m2tbw3.png)

if we have an pod already running it will not be affected by taint because it's running before the taint.
But every new pod will be affected.
to make our POD tainted we run
![tol](https://dev-to-uploads.s3.amazonaws.com/i/vibhplpdeu9y450hos0i.jpg)
```bash
kubectl taint nodes minikube app=myapp:NoSchedule
```
this will taint our Node it had a key to determine it.
the key here is 'app' the operator is '=' and the taint effect is NoSchedule.
Now let's take a look for the file I prepare for this lab
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/55wnn8xcnic5ibsbl3k5.png)
it's called app_051.yml
![getPo](https://dev-to-uploads.s3.amazonaws.com/i/7v6guwdfzea2e3jz8esg.png)
```bash
kubectl create -f app_051.yml
kubectl get pods
```
We can see that the pod is holding on Pending because our node is tainted.
let's do toleration on this pod , I will do it in app_051_v2.yml

![v2](https://dev-to-uploads.s3.amazonaws.com/i/312mcmvdsegejqqo3mj0.png)
this is a look at the v2 , We specify inside spec the toleration of the pod we put same as our taint rules.
now let's delete our old pod
![del](https://dev-to-uploads.s3.amazonaws.com/i/0u4u32cvt0x2od5qsnar.png)
```bash
kubectl delete pods test-taint
```
now let's create new one using v2
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/jrwyrf8h5nm6e4z9332j.png)
```bash
kubectl create -f app_051_v2.yml
kubectl get pods
```
our pod start to create the container if you have a better pc and connection than me it will be running :p

Now let's untaint our Node
![untaint](https://dev-to-uploads.s3.amazonaws.com/i/x5fll8v6ohvs38urd234.png)
```bash
kubectl taint nodes minikube app-
```
app is the key and - mean delete it
it's now untainted.
![image8](https://dev-to-uploads.s3.amazonaws.com/i/frbv13ou1je7d5by1ytn.png)
```bash
kubectl taint nodes minikube app=myapp:PreferNoSchedule
```
PreferNoSchedule mean "Hello master if you don't have an available pod came and put it inside of me" in another words I am your last  choice.
let's delete our pod now again
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/mdfxvg9lj86m65qsoxdy.png)
```bash
kubectl delete pods test-taint
kubectl create -f app_051.yml
kubectl get pods
```
notice it's app v1 which doesn't have toleration inside of it.
It run immediately because we have no other Nodes (only 1 minikube) . 
![untaint](https://dev-to-uploads.s3.amazonaws.com/i/x5fll8v6ohvs38urd234.png)
```bash
kubectl taint nodes minikube app-
```
let's remove taint again.
delete pod also again
![del](https://dev-to-uploads.s3.amazonaws.com/i/0u4u32cvt0x2od5qsnar.png)
```bash
kubectl delete pods test-taint
```
***
# Break
![gifStretch](https://media1.tenor.com/images/f60e1ffc1425a31d7fc9eb6af81b6117/tenor.gif?itemid=11154367)

***
# End Break
let's go back to our Lab again.
Our last effect that we will talk about is NoExcute which means if you already have pods already running and they doesn't tolerated with condition of tainting terminate them and for every new pods it should be tolerated.
![image10](https://dev-to-uploads.s3.amazonaws.com/i/labhceobyqefslrzu7mv.png)
```bash
kubectl create deployment hello-node --image=k8s.gcr.io/echoserver:1.4
kubectl taint nodes minikube app=myapp:NoExecute
```
first I create an hello world image and waited to run the we can take a look at our v3 then I create it.
We can notice the hello-node is terminated because it doesn't have the requirements.
![image11](https://dev-to-uploads.s3.amazonaws.com/i/a8g3ogcin2i7g84s9b5v.png)
```bash
kubectl create -f app_051_v3.yml
kubectl get pods
```
We can see our hello-node pod is terminated and go back to Pending.
And our new pod is Starting the container.

now let's untaint it
![untaint](https://dev-to-uploads.s3.amazonaws.com/i/x5fll8v6ohvs38urd234.png)
```bash
kubectl taint nodes minikube app-
```