Okay, so let's go over the lab for practicing taints and tolerations.
Let's start with the first question.
How many nodes exist on the system, including the control plane?
Let's look at the number of nodes
and we see that there are 2 nodes control plane and node01,
the answer is 2.
The next question is, do any taints exist on node01 node?
For that, we're going to have to take a closer look at node01.
We do kubectl describe node01
and we see
taints right here
and we see that there are none.
There are no taints on this particular node.
I'm going to select, no.
It's going to clear my screen.
The next question is to create a taint on node01
with key of spray value of mortein and effect of NoSchedule.
We're going to continue with the silly example
that we used in the lecture
of the spray and mortein and mosquito and B.
Here, the task is to create a taint.
We're going to do kubectl taint,
and let's quickly look at the help.
The command is kubectl taint and then nodes,
then the name of the node,
and then followed by these values, which are the key has to be spray.
Then the value is mortein and then the effect is NoSchedule.
Let's do that.
It's kubectl taint node.
It's node01.
Then the key is spray
and the value is mortein
and the effect is NoSchedule.
Okay.
Let's confirm that.
We have the spray=mortein and NoSchedule effect,
so that's done.
We now have a taint on node01.
Now the goal is to create a new pod with the nginx image
and the pod name as mosquito.
We're going to do a kubectl run,
that's the pod name image=nginx.
Let's do get pods.
Let me see that it's created, ignore the status for now.
Okay, so what is the state of the pod?
It seems to be in a pending state.
Select pending.
Now, why do you think the pod is in a pending state?
Is it because the image is not available, is there an error?
Let's see.
Let's do describe pod
and the pod name
and here, you'll see
the reason why it's in a pending state.
It says that the pod didn't tolerate 1 node
that had taint, spray, and mortein that the pod didn't tolerate.
Basically, the pod mosquito cannot tolerate the taint mortein,
that's a problem here.
We're going to select that.
Okay, so now we have to create another pod named bee
with the nginx image,
which has a toleration set to the taint mortein.
We're going to do a kubectl run command to create a pod.
The name is going to be bee
and the image is going to be nginx.
Basically, now we have to add toleration to it,
but you cannot specify toleration in the command line.
What we're going to do is we are going to do a dry run= client
to generate a yaml file with this pod.
That's the yaml file,
and we're going to redirect that to bee.yaml.
We have this in bee.yaml, we're going to edit bee.yaml file,
and we're going to add in tolerations.
Add a section called tolerations.
Now if you're not sure of the format,
check out the Kubernetes documentation pages
and search for taints and tolerations.
That's the first result.
This is the command taint
and this is the format for tolerations
so dash key, operator, value, and effect.
That's key, so key is going to be spray,
operator, value, and effect.
The value is going to be mortein,
effect is going to be NoSchedule.
Finally, we have operator which has to be equal.
Operator set to equal,
you save that,
and let's create image.
Okay, it's now in a container-creating state.
Let's watch the creation process
and we can see that it's now in a running state.
This part is now running.
Okay, so that's correct.
Notice the bee pod was scheduled on node01.
Let's see where it was scheduled.
We see the bee pod is on node01.
Basically, now this bee was able to tolerate the taint set on node01.
Do you see any taints on controlplane node?
Let's look at the controlplane node.
Let's look at taints
and we see that yes, there is a taint set on the controlplane node
and it's set to NoSchedule.
That's the effect.
Yes, it's set and it's set to NoSchedule.
Okay, now remove the taint on controlplane,
which currently has the taint effect of NoSchedule.
We've got to remove that.
First, let's get that.
This is the taint.
Let's copy that.
The command to remove is the same, kubectl taint.
You just specify the node, that's controlplane node.
Specify the taint that we want to remove
and at the end, you've got to put a dash or a minus
or to remove that taint.
It says it's untainted.
Let's confirm that.
Go back to taint.
I see that nothing is set.
Let's click on check.
Okay, so that's done.
Now we've got to check
the status of the pods again.
We see that the pod mosquito which earlier was in a pending state
is now in a running state.
That's the state of the pod mosquito.
Then we have to,
let's check on what node it is placed.
As you can see, it's now placed on the controlplane node.
Earlier in the beginning,
the controlplane node has a taint set on it
and then we set taint on node01.
Then we created the mosquito pod.
It was not placed on any of the nodes
because both of them had a taint then.
Then we created the bee pod with the toleration or node01
so the bee pod was able to be placed on node01.
Then we removed the taint on controlplane.
Without doing anything the pod mosquito
was automatically placed on controlplane
because it no longer has any taint on it.
The answer to this is controlplane.
Okay, so that's the end of this lab.