Static Pods - Kubernetes

Static Pods - Kubernetes

What if there is no Kube API server, no Kube scheduler, no controllers, no etcd, no master, and no other nodes. Just only one node having a kubelet & docker engine installed in it.

The kubelet can manage a node independently and we can configure the kubelet to read the pod definition files from a directory on that particular node designated to store information about the pods. we just need to place the pod definition files in this directory and the kubelet periodically checks this directory for pod definition files, reads these files, and creates pods on this node.

Kubelet ensures that the pod stays alive and if the application crashes the kubelet attempts to restart it. If we make any changes to the file, the kubelet will re-create the pods for those changes to reflect. So these pods are created by kubelet on its own without the intervention from the api server or the rest kubernetes cluster components are known as static pods.

Also, we cannot create replicasets, deployments, services by kubelet alone by placing the pod definition file in the designated directory due to the kubelet works at a pod level.

The designated folder could be any directory on the node and the location of that directory is passed in the kubelet as an option while running the service. We can check or configure the path of the directory by running a simple command as:-

# pod-manifest-path=/etc/kubernetes/manifests/

Also, the static pod definition files path can be found in the config files of the kubelet daemon on a specific node. To access those pod definition files we need to find out the path of the directory as:-

First, identify the kubelet config file:

# ps -aux | grep /usr/bin/kubelet

From the output, we can see that the kubelet config file used /var/lib/kubelet/config.yaml

Next, lookup the value assigned for staticPodPath:

# grep -i staticpod /var/lib/kubelet/config.yaml

staticPodPath: /etc/kubernetes/manifests

As we can see, the path configured is the /etc/kubernetes/manifests directory. we can define the pod definition files in /etc/kubernetes/manifests/ path and once the static pods are created we can view them by running a docker command.

# docker ps

The kubelet can create both kinds of pods, the static pods and the ones from the api server at the same time. The api server knows which pods are created by the api server or which pods are static created by kubelet alone.

We cannot edit or delete the static pods like the usual pods, we can only delete them by modifying the files from the node manifest folder. The name of static pods will be automatically appended with the node name, ex: static-web-Node01.

Use case: we can use the static pod to deploy the control plane components itself as pods on the node.

Note: ps -aux command is used to display the information of all running processes. grep command searches for the pattern specified by the pattern parameter and writes each matching line to the standard output.

Thank you so much for taking your valuable time for reading.

I have tried my level best to explain as much information as possible in the easiest manner. Thank you Kunal Kushwaha for giving this idea to showcase the skills at the public community level.

Any feedback for further improvement will be highly appreciated! WeMakeDevs

We can connect at : Rahul Kumar Verma | LinkedIn