Kubernetes Pods without the Kubernetes API
I recently worked on my Kubernetes preparation and found out an interesting capability - the Static Pods.
It’s interesting to find something new about a technology after about 4 years of working with it in production environments.
The Static Pods are managed directly by the kubelet
on a specific node without the Kubernetes API.
What is the use of this capability?
Let’s imagine you are a PaaS and the process of scaling of the Kuberentes cluster you offer needs to check something on the nodes before its added to the Kubernetes Control Plane. This could be done with a solution like Static Pods by launching a component on the node directly and doing the checks.
To demo it I will use 2 nodes: Worker Node 1 and Control Plane Node
1. On the Worker Node 1 create the following file:
$ sudo vi /etc/kubernetes/manifests/diagnostic.yml
2. Add the following into the file and save it :
apiVersion: v1
kind: Pod
metadata:
name: beebox-diagnostic
spec:
containers:
- name: beebox-diagnostic
image: acgorg/beebox-diagnostic:1
ports:
- containerPort: 80
3. On the Control Plane Node we will see a so called mirror Pod which is automatically created by kubelet
, it’s visible to the API server and can’t be controlled by it.
Bellow you can see how I can delete the mirror pod from the Control Plane, it gets deleted but then it immediately is created back.
user@k8s-control:~$ kubectl get po
NAME READY STATUS RESTARTS AGE
diagnostic-k8s-worker1 1/1 Running 0 20s
user@k8s-control:~$ kubectl delete po diagnostic-k8s-worker1
pod "diagnostic-k8s-worker1" deleted
user@k8s-control:~$ kubectl get po
NAME READY STATUS RESTARTS AGE
diagnostic-k8s-worker1 0/1 Pending 0 2s
user@k8s-control:~$ kubectl get po
NAME READY STATUS RESTARTS AGE
diagnostic-k8s-worker1 1/1 Running 0 23s
user@k8s-control:~$
Sign up now so you don’t miss the next issue.
In the meantime, tell your friends!