In this video, we're going to go over
this lab on static pods.
The first question is,
how many static pods exist in the cluster in all of the namespaces?
Let's do a get pods -A, to list the pods in all namespaces.
Now, one way to figure out or differentiate a static pod
from the other pods is to look at its name.
At the end, you'll have the node name appended to it.
This one, this one, this.
This is a static pod created on controlplane.
All of these three are as well as this.
There are four static pods,
and then there are no others with a visible node name to the end of it.
That's one way to look at it.
Another way to be sure is to look at one of the pod in a bit more detail.
Let's say, for example, this one, let's do a kubectl get pod.
Then we provide a name space,
which is kube-system.
This is just going to list the pods.
It's not going to give us the information that we need.
We need to look at the YAML format of the pod.
We're going to do a -o and YAML.
This is going to give us a lot of information.
From this, what we need to do is we need to look at the owner reference section.
If you scroll down, there's this section called owner references.
Under this, you'll see the owner of this pod is the node,
the kind is node, and the name is controlplane.
That's one way to be sure if a pod is a static pod or not.
Let's clear the screen.
If you look at the same for another pod
that is not a static pod,
kube-system -o YAML output.
If we look at the owner reference for this
right here,
we see that the owner of this is a ReplicaSet.
This is not a static pod.
That's one way to figure that out.
There are ways that you can do this for all of the pods,
like using filters and selectors.
Now, we should be able to traverse this file,
and then we look at the owner reference.
We haven't learned about filters and advanced kubectl commands yet.
We'll skip that for now, but this is an easy way.
There are two ways to find out if a pod is static or not
and one of that is to look for no names at the end of it.
To be sure, you can use the command that is issued.
We know that there are four static pods
and they're all on controlplane as of now.
Let's run that command again.
The question is, which of the below components
is not deployed as a static pod?
If you look at this, we have the ETCD, the controlplane.
ETCD is a static pod.
Kube-apiserver is a static pod.
Kube-controller-manager is a static pod,
and kube-scheduler is a static pod.
Node coredns.
Coredns does not seem to be a static pod, let's select that.
Which of the below components is not deployed as a static pod?
Again, we know that all of these are
except for the kube-proxy.
The kube-proxy is not a static pod.
On which nodes are the static pods created currently?
All of these as we just saw are on controlplane.
Controlplane is the answer to this question.
Now, what is the path of the directory holding the static pod definition files?
One way to figure that out is to look at the kubelet conf, so
var/lib/kubelet, then we have a config.yaml.
If you look into this file, this is the kubelet configuration
and we've learned that it is the kubelet that creates the pods.
There is this specification here that says static pod path
and it is currently set to the etc/kubernetes/manifests directory.
Let's look at that directory, and we see that they are the files
that are used to create the static pods.
That is /etc/kubernetes/manifests.
That's the correct answer to this question.
Also remember that this is the path to check
the static pod configuration on any given node.
How many pod definition files are present in the manifests folder?
That's one, two, three, four.
Four.
That is equal to the number of static pods that we have here.
Now, what is the docker image used to deploy
the kube-api server as a static pod?
If you look at kube-api server file here,
so this followed by this.
If we look into the image,
we see that it's
k8s.gcr.io/kube-apiserver:v1.20.0.
As of this recording, this is the version.
You should make sure that whatever the version is that you're working on,
make sure you choose that as the answer.
The next question is to create a static pod
named static-busybox that uses the busybox image and the command sleep.
We know that the command to create a pod is kubectl run,
and the name is static busybox.
The image is busybox,
and the command is sleep 1000.
Now, what we need to do is, we don't want to create this.
Instead, we just want to get the pod definition file
and place it in the static pod path for this node.
We're going to do a dry run for this.
Dry run here.
Now, when you use the command option,
always remember not to place any option
that is for the kubectl command after this.
Anything that you put after this, especially after the two dashes here,
is going to be considered as an option for this command,
so not place anything.
The command should always be at the end.
In this case, I'm going to put the dry run before the command option.
Any option for the kubectl utility should be before the command option.
Dry run equals client, and then -o yaml.
I get this.
We're going to redirect that to a file.
For now, I'm going to put it to static-busybox.yaml.
Then we're going to move this to
/etc/Kubernetes/manifests folder.
Let's see if that was created.
Okay, so the pod is now created, static-busybox-controlplane,
and it's in a running state.
Let's go next.
Now, edit
the image on the static pod to use the busybox:1.28.4 image.
To make any changes to a static pod,
you could simply edit the file and save it.
Let's just go to edit the file
in etc/kubernetes/manifests static pod.
Then let's change this right here,
busybox:1.28.4,
and just save that.
If we look at the pod now, it's pending.
Let's watch the status.
There's an ImagePull issue.
I got it wrong.
Sorry about that.
Let's change that now.
That's why you should always verify after you do anything,
especially in the exam.
It's possible that we might make typos in different places.
You always verify your work after you're done.
That's done.
Let's wait for the next question.
We just created a new static pod named static-greenbox.
Find it and delete it.
Let's see.
Kubectl get pods.
We see that there is indeed a static-greenbox.
We have got to delete it.
Now, if we just try to delete the pod like this--
It says it's deleted, but if you look at it,
it's going to be recreated because we know
that it's a pod that the kubectl manages.
It's not possible to delete a static pod just using the delete command.
It would delete it but it would be created again.
We need to find the manifest file for that static pod and delete it.
If you look at
the etc/kubernetes/manifests/ directory,
we'll see that there is none for the greenbox,
and that's basically because if you look at the name of the static pod,
you see that it's created on node01.
We've got to go the node01
and delete it from there.
Let's find out how to go to node01.
Let's do a kubectl nodes command.
We see that we have indeed a controlplane and a node01 node.
If you do a -o wide, we'll see that it has an IP address.
The controlplane is at 10.38.102.6,
and node01 is at 10.38.102.8.
Let's ssh to node01.
Sometimes depending on how the DNS is configured,
if you just do a ssh to just node01, that might work too.
If that isn't working,
then you should always look up at the internal IP
address following this command and ssh to that node.
Now, we're on node01.
All we need to do is find the static file manifest path.
Let's go to etc/kubernetes/manifests/ directory.
As you see, it doesn't exist.
There is no static-greenbox path here.
We need to see why that is.
Let's go back and see the kubelet configuration
and find out what's wrong with the path to the static pod.
The file is
/var/lib/kubelet
and then you have config.yaml.
If you look at this file, we have the static pod path.
As you can see, it's not at
etc/kubernetes/manifests/.
It's actually changed.
It is at etc/just-to-mess-with-you.
That's a change we made just to get you to think a little bit.
There indeed we have the greenbox.yaml.
All we need to do is just remove this file from here.
Make sure it's removed.
Now, let's exit and go back to the controlplane
and list the nodes.
Let's watch and wait for it to be terminated.
The pod is now being terminated.
That's gone.
That's that.
That's the end of this lab.