Hello, readers! This article focuses on the Creation of the Static Pods in Kubernetes with a deep understanding of static pods.
So, let us begin!! 🙂
Understanding Static Pods in Kubernetes
As we have explored earlier, a Kubernetes Pod is thoroughly managed by an API-SERVER. The API-SERVER is responsible for observing and managing the application pods.
On the other hand, a Static Pod is never in control of the API-SERVER. That is, API-SERVER does not manage static pods, Kubelet on the worker nodes takes care of them. Kubelet is responsible to restart the static pods and have a health check if they fail.
Kubelets create these static pods on the nodes and manage them. Though they are not managed by API-SERVER, a kubelet creates a copy of these static pods on the k8 API-SERVER. As a result, when we try to list the pods, static pods will also be visible, but internally, the API server would have no control over this kind of pod.
The best case of static pods is to have them create Kubernetes control plane components. The kubeadm tool makes use of static pods to have the control plane components (kube-scheduler, API server, etc) in the cluster. The static pods run on the worker nodes and enable us to have various masterpiece components.
Note: If we plan to have a Kubernetes cluster with static pods to help run pods on every node, DaemonSets can be a better option to go with.
Having understood about Static pods, let us now try to create one. In the current scenario, we can have two types of Static pods-
- FileSystem-hosted static pod
- Web-hosted static pod
1. Creating a FileSystem-hosted static pod
In FileSystem hosted static pods, the pod definition YAML stays as a file at some specific location on the worker node (server/Virtual Machine).
For the same, at first, we would need to connect to the node where we want the static pod to run.
Once we are connected to the node, we use the staticPodPath in the kubelet configuration file to make the pod manifest file reside there. On a periodic basis, kubelet scans the directory and accordingly creates/deletes static pods based on the configuration from the configuration files.
Have a look at the below pod manifest YAML-
mkdir /etc/static/kubelet.d/ cat <<EOF >/etc/static/kubelet.d/static-pod.yaml apiVersion: v1 kind: Pod metadata: name: static-demo-pod labels: role: app spec: containers: - name: app image: busybox:1.28 ports: - name: app containerPort: 443 protocol: TCP EOF
In the above manifest, we have created a file with a busybox container to run as a static pod over port 443. We have created a directory under the /etc tree to have the file. Also, we need to make sure that the node has kubelet running on it for it to catch the configuration to create a static pod.
At last, we would need to restart the kubelet software on the current node-
systemctl restart kubelet
2. Creating a Web-hosted static pod
Apart from having a file manifest based static pod, we can also have static pods created through being a web-hosted structure. For the same, we would need to have a pod definition YAML being stored over a web server.
apiVersion: v1 kind: Pod metadata: name: static-demo-pod labels: role: app spec: containers: - name: app image: busybox:1.28 ports: - name: app containerPort: 443 protocol: TCP
Post which, we pass the URL of the above manifest to the kubelet present over the worker node by specifying the URL as the value for the flag –manifest-url=URL.
By this, we have come to the end of this topic. Feel free to comment below, in case you come across any questions.
For more such posts related to Kubernetes, Stay tuned with us.
Till then, Happy Learning!! 🙂