Lesson 36 · Section 3: Scheduling
Lesson 36: Static Pods: Pods that the kubelet runs from a file, with no scheduler involved
What a static Pod is, how the kubelet turns a manifest file into a running Pod without the API server or the scheduler, what the mirror Pod is for, and how to create, change, find and repair static Pods on a kubeadm cluster. · 20 min read · 4 min video
Official competencies this lesson covers
Narrated by the local narrator voice. Keys: Space plays and pauses, J and L step, C captions, F full screen.
Why static Pods exist
Everything in this section is about how a Pod gets its node: the scheduler filters, scores and binds. Static Pods are the exception that needs no scheduler at all.
Think about a machine that runs only a kubelet and a container runtime. There is no API server to hold Pod objects, no scheduler and no controllers. The kubelet still knows how to do its one job, which is to turn a Pod spec into running containers. It only needs a Pod spec from somewhere, and a file on the local disk is enough.
This solves a real chicken-and-egg problem. The API server, etcd, the scheduler and the controller manager are containers too, but they cannot be created through an API server that is not running yet. kubeadm therefore writes them as four static Pod manifests, and the kubelet on each control plane node starts them at boot. That is the main use of static Pods, and the reason they matter so much in the exam: to change or repair a control plane component, you edit a static Pod manifest.
What a static Pod is
Parts:
- API server (stores the Pod)
- Scheduler (picks the node)
- Manifest file (web.yaml on disk), in node01
- kubelet (on node01), in node01
- Containers (via containerd), in node01
Connections:
- Scheduler to API server: binds
- API server to kubelet: normal Pods
- Manifest file to kubelet: static Pods
- kubelet to Containers: starts
A normal Pod and a static Pod end in the same place, containers started by the kubelet through the runtime, but they get there in different ways:
| Normal Pod | Static Pod | |
|---|---|---|
| Defined in | The API server (etcd) | A file in the kubelet's static Pod folder |
| Created by | You or a controller, through the API | Whoever writes the file on the node |
| Node chosen by | The scheduler | Nobody: always the node that holds the file |
| Kept alive by | The kubelet (containers) and a controller (replacement Pods) | The kubelet only |
| Needs a control plane | Yes | No |
| Name in kubectl | As created | <name>-<nodeName>, for example web-node01 |
| Change or remove | kubectl edit, kubectl delete | Edit, move or delete the file |
The manifest itself is an ordinary Pod definition. Nothing in the YAML says "static": what makes it static is where the file sits.
# /etc/kubernetes/manifests/web.yaml on node01
apiVersion: v1
kind: Pod
metadata:
name: web
labels:
app: web
spec:
containers:
- name: web
image: nginx:1.29
ports:
- containerPort: 80
Only kind: Pod works there. A Deployment, ReplicaSet or DaemonSet in that folder is ignored, because those are
handled by controllers in the control plane, and the kubelet understands nothing but Pods.
Where the folder is
The folder is a kubelet setting, so it can differ from node to node:
| Setting | Where | Notes |
|---|---|---|
staticPodPath | /var/lib/kubelet/config.yaml (the KubeletConfiguration) | The current way. kubeadm sets it to /etc/kubernetes/manifests on every node, workers included |
--pod-manifest-path | A flag on the kubelet command line | The older, deprecated way. Look for it with systemctl cat kubelet or ps aux | grep kubelet if the config file has no staticPodPath |
staticPodURL (--manifest-url) | Config file or flag | The kubelet downloads Pod definitions from a URL at intervals. Rare, but it explains a static Pod with no file |
How it works
The kubelet watches the folder
Parts:
- File appears (cp, tee, mv in)
- File changes (vi, sed)
- File disappears (rm, mv out)
- kubelet (watches the folder)
- Pod started (plus a mirror Pod)
- Pod recreated (old one is killed)
- Pod stopped (mirror removed)
Connections:
- File appears to kubelet
- File changes to kubelet
- File disappears to kubelet
- kubelet to Pod started
- kubelet to Pod recreated
- kubelet to Pod stopped
The static Pod folder is one of the kubelet's sources of Pods, next to the API server. The kubelet watches it for
changes and also rereads it every 20 seconds (fileCheckFrequency), so a change is normally picked up within a few
seconds and always within about half a minute. Then:
- File lands in the folder
- kubelet parses it as a Pod
- Sets the node name, adds the node suffix
- Runtime starts the containers
- Mirror Pod created in the API
- A new file starts a Pod. The kubelet fills in the node itself, so the scheduler is never asked.
- A changed file counts as a different Pod: the kubelet stops the old one and starts a new one. There is no
rolling update, so expect a short gap. For the API server that gap is when
kubectlstops answering. - A removed file stops the Pod and deletes its mirror.
- A crashed container is restarted by the kubelet according to
restartPolicy, like in any Pod. - A rebooted node brings the Pod back, because the file is still there. This is how the control plane survives a reboot.
Under the hood · What the kubelet reads, ignores and adds
- Every file counts, whatever its name. The kubelet tries to read each file in the folder, not only
*.yaml. A backup such askube-apiserver.yaml.bakis read as a second Pod with the same name and fights with the real one. Only files whose names start with a dot are ignored, which is why an editor's hidden swap file does no harm. - Subfolders are not read. The kubelet does not descend into directories inside the folder.
- A file that does not parse is skipped and reported in the kubelet's journal (
journalctl -u kubelet) as a manifest it could not process. If the file used to be valid, the Pod it defined is stopped, and nothing replaces it until the file is fixed. - Namespace. The manifest can set
metadata.namespace(kubeadm useskube-system); without it the Pod is indefault. - Taints do not keep it out. No scheduler is involved, so
NoScheduletaints are never checked, and the kubelet gives static Pods a toleration for everyNoExecutetaint. A static Pod runs on a tainted control plane node without any toleration in its manifest. nodeName,nodeSelectorand affinity are pointless. The Pod runs where the file is, whatever the manifest says.kubectl drainleaves it alone. Drain evicts Pods through the API, which cannot remove a static Pod, so mirror Pods are skipped without any extra flag.
The mirror Pod
Parts:
- web.yaml (the source of truth)
- kubelet (on node01)
- Static Pod (real containers)
- kubectl (get, logs, exec)
- Mirror web-node01 (in the API server)
- Scheduler (counts its requests)
Connections:
- web.yaml to kubelet: reads
- kubelet to Static Pod: runs
- kubelet to Mirror web-node01: creates and updates
- kubectl to Mirror web-node01: sees
- Scheduler to Mirror web-node01: sees
A Pod that exists only on a node would be invisible to the rest of the cluster. So when the kubelet can reach an API server, it creates a mirror Pod for every static Pod: an object in the API that describes the Pod and carries its live status.
The mirror Pod is what makes these work for a static Pod:
kubectl get,describe,logs,execandport-forward.- Scheduling arithmetic. The scheduler counts the mirror Pod's resource requests, so it does not overfill a node whose static Pods already use part of it.
- Services. Labels in the manifest are copied to the mirror Pod, so a Service selector can match a static Pod.
What it does not give you is control. The API server refuses most changes to a mirror Pod, and deleting it only removes the copy: the containers keep running, and the kubelet creates the mirror again within seconds.
You can recognise a mirror Pod in three ways:
kubectl get pod web-node01 -o yaml
metadata:
name: web-node01 # 1. the node name is appended
annotations:
kubernetes.io/config.source: file # 2. it came from a file (config.mirror and config.hash are set too)
ownerReferences:
- apiVersion: v1
kind: Node # 3. owned by a Node, not by a ReplicaSet or DaemonSet
name: node01
controller: true
What a static Pod cannot do
Being independent of the API server has a price:
- No references to API objects. The spec cannot use a ServiceAccount, a ConfigMap or a Secret, whether as a
volume, in
envor inenvFrom. Configuration has to come from the image, from literalenvvalues, or from files on the node mounted withhostPath. This is why the kubeadm control plane manifests mount/etc/kubernetes/pkifrom the host instead of using Secrets. - No ephemeral containers, so
kubectl debugcannot attach to one. - No rescheduling. If the node goes down, the Pod is down. Nothing recreates it elsewhere.
- No rollout, rollback or scaling. One file is one Pod on one node.
Static Pod or DaemonSet?
Both put a Pod on a specific node without the scheduler choosing the node freely, so they are easy to confuse. The previous lesson covered DaemonSets; here is the difference:
| Static Pod | DaemonSet | |
|---|---|---|
| Created by | The kubelet, from a file on the node | The DaemonSet controller, through the API |
| Needs a running control plane | No | Yes |
| Managed with kubectl | No | Yes: rolling updates, rollbacks, kubectl delete |
| Deploy to many nodes | Copy the file to each node yourself | One object covers every matching node |
| ConfigMaps, Secrets, ServiceAccount | Not available | Available |
| Typical use | Control plane components (kube-apiserver, etcd, kube-scheduler, kube-controller-manager) | Node agents (kube-proxy, CNI plugins, log and metrics collectors) |
The rule of thumb from the Kubernetes documentation: if you want a Pod on every node of a working cluster, use a DaemonSet. Keep static Pods for what must run before, or without, the control plane.
Using it
Example · Create a static Pod on a worker node
Task: run a static Pod named web with the image nginx:1.29 on node01.
Find the folder first, on the node the task names. Then let kubectl write the manifest; --dry-run=client only
prints YAML, so it works even where kubectl has no access to the cluster.
ssh node01
sudo grep staticPodPath /var/lib/kubelet/config.yaml # staticPodPath: /etc/kubernetes/manifests
kubectl run web --image=nginx:1.29 --dry-run=client -o yaml \
| sudo tee /etc/kubernetes/manifests/web.yaml
exit
kubectl get pods -o wide # web-node01 1/1 Running ... node01
If kubectl is not installed on the worker, write the file on the control plane node and copy it over with scp, or
type the dozen lines by hand.
Example · Change a static Pod, then remove it
Task: the static Pod web on node01 must use the image nginx:1.29-alpine. Later, remove it for good.
kubectl edit pod web-node01 and kubectl set image do not work: they act on the mirror. Change the file.
ssh node01
sudo sed -i 's|image: nginx:1.29|image: nginx:1.29-alpine|' /etc/kubernetes/manifests/web.yaml
exit
kubectl get pod web-node01 -o jsonpath='{.spec.containers[0].image}' # nginx:1.29-alpine, after a few seconds
To remove the Pod, remove the file. kubectl delete pod web-node01 appears to work and then the Pod is back.
ssh node01 sudo rm /etc/kubernetes/manifests/web.yaml
kubectl get pods # web-node01 is gone
Example · Find a static Pod on a node with a custom folder
Task: a Pod named audit-agent-node02 keeps coming back after kubectl delete. Remove it.
The node suffix and the behaviour say "static Pod", and the name tells you the node. Do not guess the folder.
kubectl get pod audit-agent-node02 -o jsonpath='{.metadata.ownerReferences[0].kind}' # Node
ssh node02
sudo grep staticPodPath /var/lib/kubelet/config.yaml # staticPodPath: /etc/kubelet.d
sudo ls /etc/kubelet.d # audit-agent.yaml
sudo rm /etc/kubelet.d/audit-agent.yaml
exit
kubectl get pods # audit-agent-node02 is gone
If config.yaml has no staticPodPath, check the command line: systemctl cat kubelet and
ps aux | grep kubelet show a --pod-manifest-path flag or a different --config file.
Example · Repair a control plane static Pod
Task: after a change, kubectl answers The connection to the server ... was refused.
The API server is a static Pod, so with it down kubectl is useless. Work on the control plane node with the runtime's own tool.
sudo crictl ps -a | grep kube-apiserver # state Exited, with a growing attempt count
sudo crictl logs <container-id> # Error: unknown flag: --etcd-server
sudo vi /etc/kubernetes/manifests/kube-apiserver.yaml # fix the flag: --etcd-servers
watch sudo crictl ps # kube-apiserver comes back as Running
kubectl get nodes
What the symptoms tell you:
- A container that exits again and again: the manifest parses, but the program rejects a flag, a file path or a
certificate.
crictl logsnames it. - No container at all: the kubelet could not use the file. Typical causes are broken YAML indentation, a wrong
image name, or a
hostPathvolume that points to a missing directory. Look insudo journalctl -u kubelet --no-pager | tail -n 30. - No containers for any control plane component: the kubelet itself is down.
systemctl status kubeletcomes first.
Tricks
Common mistakes
- Deleting or editing the mirror Pod.
kubectl deleteandkubectl editdo not touch the real Pod. Change the file on the node. - Writing the file on the wrong node. The Pod runs on the node that holds the file. A task that says "on node01"
means
ssh node01first; check the prompt before you write. - Assuming the default folder. Read
staticPodPathfrom that node's kubelet configuration. - Leaving backups or drafts in the folder. Every non-hidden file there is treated as a manifest.
- Putting a Deployment in the folder. Only Pods are understood.
- Using a ConfigMap, Secret or ServiceAccount in the manifest. A static Pod cannot reference API objects; use
literal values or
hostPathfiles. - Restarting the kubelet after editing a manifest. It is not needed: the kubelet notices the file by itself. A
restart is only needed when you change
staticPodPathor another kubelet setting. - Panicking when kubectl stops answering. After an edit to
kube-apiserver.yamloretcd.yaml, a short outage is normal. Usecrictlto see whether the new container is starting or failing.
Recap
- A static Pod is a Pod manifest in the kubelet's
staticPodPathfolder; that node's kubelet runs it with no API server, scheduler or controller involved. - The kubelet creates a read-only mirror Pod named
<name>-<nodeName>, owned by the Node, so the Pod is visible in kubectl and counted by the scheduler. - Create, change and remove a static Pod only through its file; the kubelet reacts within seconds.
- A kubeadm control plane is four static Pods in
/etc/kubernetes/manifests: etcd, kube-apiserver, kube-controller-manager and kube-scheduler. - When one of them is broken, kubectl may be down: use
crictl ps -a,crictl logsandjournalctl -u kubeleton the node, then fix the file.
Official docs
Quiz: check what you learned
5 questions on this lesson · about 3 min · instant feedback. Missed questions come back in your review queue.
Sign in to take the quiz and keep your score.
Practise: try it on a real cluster
A hands-on lab for this lesson. You get goals, not steps: any solution that reaches them passes.
Run a static pod on a worker whose kubelet reads its manifests from an unusual place, and get rid of a static pod that comes back every time it is deleted.
Build · Level 2 · standard · target 15 min
Discussion
Learners ask and answer questions here. Sign in to read and join the discussion.