3 min read | by Jordi Prats
Static pods are managed directly by the kubelet without relying on the Kubernetes API server. Unlike regular pods, static pods are defined as manifest files placed in a specific directory on the node.
Since static pods are bound to a specific node, they are suffixed with the node hostname in the pod name. In this post, we will create a static pod in a kind cluster by mounting a directory from the host to the kubelet's static pod directory.
First we'll have to create a file with the static pod definition, then we'll create a kind cluster with a configuration that mounts the directory containing the static pod manifest.
apiVersion: v1 kind: Pod metadata: name: demo-static-pod namespace: kube-system spec: containers: - name: web image: nginx ports: - name: web containerPort: 80 protocol: TCP
We need to add this file to the /etc/kubernetes/manifests directory on the node that we want it to run. To do this in a kind cluster, we can mount a directory from the host to the control plane node:
kind: Cluster apiVersion: kind.x-k8s.io/v1alpha4 nodes: - role: control-plane extraMounts: - hostPath: /Users/jordiprats/tmp/kind-static containerPath: /etc/kubernetes/manifests
We can not create the cluster using:
kind create cluster -n static --config static-kind.yaml
Once created, we can check if the pod is running in the kube-system namespace:
$ kubectl get pods -n kube-system NAME READY STATUS RESTARTS AGE coredns-668d6bf9bc-6d4g6 1/1 Running 0 24s coredns-668d6bf9bc-776l6 1/1 Running 0 24s demo-static-pod-static-control-plane 1/1 Running 0 34s etcd-static-control-plane 1/1 Running 0 31s kindnet-rlljv 1/1 Running 0 24s kube-apiserver-static-control-plane 1/1 Running 0 31s kube-controller-manager-static-control-plane 1/1 Running 0 31s kube-proxy-h2ktn 1/1 Running 0 24s kube-scheduler-static-control-plane 1/1 Running 0 31s
As you can see, the Pod name is suffixed with the node hostname, in this case static-control-plane. In addition, the Pod definition will contain additional annotations and a owner reference to the node:
apiVersion: v1 kind: Pod metadata: annotations: kubernetes.io/config.hash: e316cce1f609de50dda0b065f293a8e1 kubernetes.io/config.mirror: e316cce1f609de50dda0b065f293a8e1 kubernetes.io/config.seen: "2025-02-15T16:17:52.340240888Z" kubernetes.io/config.source: file creationTimestamp: "2025-02-15T16:18:40Z" name: demo-static-pod-static-control-plane namespace: kube-system ownerReferences: - apiVersion: v1 controller: true kind: Node name: static-control-plane uid: 4c700dd7-c4e7-4042-8be8-ac4f70ff7313 resourceVersion: "548" uid: 9818e55d-84ca-478a-9d23-a27d804ec7ea spec: (...)
Posted on 24/02/2025