Ye Lin's Random stuff

My random notes

16 Dec 2021

Static Pods in Kubernetes

After taking the CKAD exam, I am planning to take the (harder) CKA exam. As I was studying for it, I stumbled upon Static Pods in Kubernetes. It is slightly different from the regular Pods.

This is the normal Kubernetes cluster components

Kubernetes Constructs Concepts and Architecture From Cloud9 Kubernetes Concepts and Architecture

Learn more about the Control plane components here.

Now, let’s imagine there is a Kubernetes cluster with no Schedular or Controller or even no Master Node. There are worker nodes. On each worker node, there is kubelet running. Now, how can we tell kubelet to run a Pod itself?

We can do that by putting a Pod specification YAML file under /etc/kubernetes/manifests folder. Let’s say this is the spec. We save it a YAML file put it under the manifests folder.

apiVersion: v1
kind: Pod
  name: nginx
  - name: nginx
    image: nginx:1.18.0
    - containerPort: 80

kubelet will periodically check the folder and create the Pod. We should be seeing the nginx Pod up and running shortly. We can customize the folder path with --pod-manifest-path when we run kubelet process. The Control plane from the Master Node is not involved in creating a static Pod. Yet, once the api-server is reachable, kubelet will notify a record on the api-server as a mirror Pod record. So that we can see the pods when we do kubectl get pods.

When is this actually useful?

Most of the time, we won’t have to create one like this. Static pods are usually used by software bootstrapping Kubernetes itself. One use is kubeadm. During the setup, kubeadm uses static pods to bring up Kubernetes control plane components like api-server, controller-manager.

This only works for the Pods and not for ReplicaSet or Deployment.