What are Pods?
Pods are the tiniest, most basic deployable objects in the Google Kubernetes Engine. They represent a single instance of a running process in the cluster and may contain one or more containers. In the case of running multiple containers in a pod, all the containers share the Pod resources and are managed under a single entity. Not to be confused with nodes as nodes are the physical servers or virtual machines that contain a Kubernetes cluster.
What are Static Pods and why do they exist?
Static Pods are a type of Pods which are created and managed by the kubelet daemon on a node without the API server observing them. If a Static Pod crashes Kubelet restarts it automatically. The control plane is not involved in the lifecycle of a Static Pod. For each Static Pod, Kubelet also creates a replica pod on the Kubernetes API server so that the pod may be visible when you run the ‘kubectl get pod’ command Static Pods are primarily used to run control plane pods, they allow you to run kube-apiserver, scheduler, controller, manager, etcd etc in the cluster. Another real world use case for developers is deploying a load balancer for the control plane. K8s tools like Kubeadm creates all of the control plane components using Static Pods, and during that process you can create your own static pods for example a load balancer, these are more secure as there is no API server overlooking them and using static pods gives you the pod semantics without the overhead.
How to Identify a Static Pod?
To identify a Static Pod in your cluster you can check the owner reference using the ‘kubectl describe’ command and see that the pod is not controlled by a ReplicaSet but from a Node/controlplane.
Here we can see that kube-apiserver, scheduler, controller, manager and etcd are already created by Kubelet as Static Pods in this directory
Lets create a web server pod definition for this example,
Next we will configure kubelet on the node to use this directory by running it using the following argument:
— pod-manifest-path=/etc/kubernetes/manifests/
Alternatively, you can also add this path in the kubelet configuration file by adding:
staticPodPath: /etc/kubernetes/manifests/
As mentioned before Kubelet also creates a ReplicaPod of the Static Pod that we just definied, so to see the running pod lets run the following command:
kubectl get pods
Thats it! here you can see our static pod up and running suing kubectl get pods :)
We can delete the mirror pod from the API server but our StaticPod should still be there, lets confirm by deleting the running Pod mirror
kubectl delete pod static-web
Getting the list again
kubectl get pods
Here you can see that even though we deleted our Pod, Kubelet only deleted the ReplicaPod and our original Static Pod is still up and running.
Hopefully now you have an understanding of what Static Pods are and how they are you and also how you can create your own :)