How to Create Static Pod on the Kubeadm Cluster

In this example, I am going to show you how to create a static pod on the Kubedam cluster for the nginx web server.

Step 1: Create a Manifest file

First, we need to create a YAML manifest file for the nginx static pod, to create the manifest file run the following command

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

This command will create a manifest file for nginx to run as a static pod. If you need to make any changes to the manifest file use the command below

vi nginx.yaml

A small portion of the nginx.yaml file is shown below.

Create Static Pod on the Kubeadm Cluster: static pod yaml file

Step 2: Validate the Manifest file

The next step is to validate the manifest file, to validate we can use the Kubeval utility.

If you don’t have Kubeval installed in your system run the following command to install it.

wget https://github.com/instrumenta/kubeval/releases/latest/download/kubeval-linux-amd64.tar.gz

tar xf kubeval-linux-amd64.tar.gz

sudo cp kubeval /usr/local/bin

To verify if Kubeval is installed properly run the below command

kubeval --version

You will get the following output.

Create Static Pod on the Kubeadm Cluster: verifying kubeval verison

Now, run the following command to validate the manifest file.

kubeval nginx.yaml

You will get the following output if the manifest file is created according to the Kubernetes requirements.

Create Static Pod on the Kubeadm Cluster: Validating manifest file using Kubeval

Step 3: Deploy the Nginx Static pod

To deploy the static pod, you have to copy the nginx.yaml manifest to the static pod manifest location.

/etc/kubernetes/manifests/ is the location where every static pod manifest file is present.

The manifest files in this directory are deployed by Kubectl, Kubectl deploys the static pod during the booting time and keeps it running without the involvement of Controlplane.

Now, run the following command to move the nginx manifest file to the /etc/kubernetes/manifests/ directory.

sudo mv nginx.yaml /etc/kubernetes/manifests/

Step 4: Verifying Static Pod

Verify if your nginx pod has been deployed automatically without giving the apply command. Use the below command to check if the pod is up and running

kubectl get po

Static pods cannot be deleted until the manifest file is removed from the /etc/kubernetes/manifests/ directory.

Even if you delete the static pod using the delete pod command, a new pod will be created within a minute.

The only way to delete a static pod is to remove the static pod manifest file from the /etc/kubernetes/manifests/ directory.

Create Static Pod on the Kubeadm Cluster: Static pod testing commands

You can see in the above image, that the static pod cannot be deleted until the static pod manifest file is removed from the /etc/kubernetes/manifests/ directory.

Conclusion

In summary, we learned about Kubernetes static pod, their manifest file location, and how it is created.

I believe this blog gives you simple knowledge about Kubernetes Static Pods.

Other Interesting Blogs

Leave a Comment

Share via
Copy link
Powered by Social Snap