Skip to content
LF Cert Trainer

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

1/11Static Pods
0:00 / 4:10

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

Two ways a Pod reaches a nodenode01bindsnormal Podsstatic PodsstartsAPI serverstores the PodSchedulerpicks the nodeManifest fileweb.yaml on diskkubeleton node01Containersvia containerd
Two ways a Pod reaches a node. A normal Pod is stored in the API server, placed by the scheduler and then picked up by the kubelet. A static Pod skips all of that: the kubelet reads it from a file on its own disk.

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 PodStatic Pod
Defined inThe API server (etcd)A file in the kubelet's static Pod folder
Created byYou or a controller, through the APIWhoever writes the file on the node
Node chosen byThe schedulerNobody: always the node that holds the file
Kept alive byThe kubelet (containers) and a controller (replacement Pods)The kubelet only
Needs a control planeYesNo
Name in kubectlAs created<name>-<nodeName>, for example web-node01
Change or removekubectl edit, kubectl deleteEdit, 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:

SettingWhereNotes
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-pathA flag on the kubelet command lineThe 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 flagThe 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

What each change to the folder doesFile appearscp, tee, mv inFile changesvi, sedFile disappearsrm, mv outkubeletwatches the folderPod startedplus a mirror PodPod recreatedold one is killedPod stoppedmirror removed
What each change to the folder does. The folder is the whole interface. The kubelet reacts to files that appear, change or disappear, usually within a few seconds.

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:

  1. File lands in the folder
  2. kubelet parses it as a Pod
  3. Sets the node name, adds the node suffix
  4. Runtime starts the containers
  5. Mirror Pod created in the API
From file to running Pod
  • 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 kubectl stops 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 as kube-apiserver.yaml.bak is 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 uses kube-system); without it the Pod is in default.
  • Taints do not keep it out. No scheduler is involved, so NoSchedule taints are never checked, and the kubelet gives static Pods a toleration for every NoExecute taint. A static Pod runs on a tainted control plane node without any toleration in its manifest.
  • nodeName, nodeSelector and affinity are pointless. The Pod runs where the file is, whatever the manifest says.
  • kubectl drain leaves 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

The static Pod and its mirrorreadsrunscreates and updatesseesseesweb.yamlthe source of truthkubeleton node01Static Podreal containerskubectlget, logs, execMirror web-node01in the API serverSchedulercounts its requests
The static Pod and its mirror. The real Pod lives on the node and is defined by the file. The mirror Pod is a read-only copy in the API server, there so that kubectl, the scheduler and Services can see the 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, exec and port-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 env or in envFrom. Configuration has to come from the image, from literal env values, or from files on the node mounted with hostPath. This is why the kubeadm control plane manifests mount /etc/kubernetes/pki from the host instead of using Secrets.
  • No ephemeral containers, so kubectl debug cannot 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 PodDaemonSet
Created byThe kubelet, from a file on the nodeThe DaemonSet controller, through the API
Needs a running control planeNoYes
Managed with kubectlNoYes: rolling updates, rollbacks, kubectl delete
Deploy to many nodesCopy the file to each node yourselfOne object covers every matching node
ConfigMaps, Secrets, ServiceAccountNot availableAvailable
Typical useControl 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 logs names it.
  • No container at all: the kubelet could not use the file. Typical causes are broken YAML indentation, a wrong image name, or a hostPath volume that points to a missing directory. Look in sudo journalctl -u kubelet --no-pager | tail -n 30.
  • No containers for any control plane component: the kubelet itself is down. systemctl status kubelet comes first.

Tricks

Common mistakes

  • Deleting or editing the mirror Pod. kubectl delete and kubectl edit do 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 node01 first; check the prompt before you write.
  • Assuming the default folder. Read staticPodPath from 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 hostPath files.
  • 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 staticPodPath or another kubelet setting.
  • Panicking when kubectl stops answering. After an edit to kube-apiserver.yaml or etcd.yaml, a short outage is normal. Use crictl to see whether the new container is starting or failing.

Recap

  • A static Pod is a Pod manifest in the kubelet's staticPodPath folder; 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 logs and journalctl -u kubelet on 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.