Control plane
Why is my Pod Pending?
Reading FailedScheduling
A new Pod sits in Pending and nothing seems to be wrong with it. The answer is already in the cluster, in one dense sentence the scheduler wrote. Read it piece by piece, match each piece to the node it's about, fix one blocker - and find the next one that was hiding behind it.
- Pod
- search · 3 CPU · nodeSelector disk=ssd
- node-1
- 1.1 CPU free · tainted for batch jobs
- node-2
- 2.8 CPU free · has an SSD, has no label
- Symptom
- 0/2 nodes are available
Read the whole lesson as text
1. A Pod with no node
You apply a Pod called search: 3 CPU requested, and a nodeSelector that only accepts nodes labelled disk=ssd. The API server accepts it and saves it in etcd, without complaint. But its spec.nodeName is empty, so no kubelet owns it and nothing will start it. kubectl get pods says Pending.
- You apply the search Pod. The API server accepts it.
- It saves the Pod in etcd. So far the Pod is only a record, with no node.
2. Two nodes, two vetoes
The scheduler runs its filters on each node, in order: taints, then node affinity, then resources. The first one that fails ends the check for that node. On node-1 that's the taint dedicated=batch:NoSchedule. On node-2 it's the missing disk=ssd label: the SSD is there, nobody labelled it. Neither node got as far as the CPU check, so nobody knows yet that 3 CPU wouldn't fit on either of them.
- The scheduler's watch delivers a Pod with no node.
- node-1 is out at the first filter: it has a taint this Pod doesn't tolerate.
- node-2 has no taint, but it isn't labelled disk=ssd, so it's out too.
3. The verdict is saved
No node passed, so the scheduler asks whether evicting lower-priority Pods would help. It wouldn't: neither a taint nor a missing label goes away when Pods leave. It writes its answer down in two places, the Pod's PodScheduled condition and a FailedScheduling event, and parks the Pod in its unschedulable pool. It is not retrying in a loop. It waits for something in the cluster to change.
- Could evicting other Pods make room? Not here: no Pod is in the way.
- The scheduler writes why onto the Pod itself, as a condition.
- It records the same sentence as an event, the one kubectl describe will show you.
4. Read the message
First look at Node in kubectl describe. If it's empty, the scheduler hasn't placed the Pod, and the event says why. If a node is named, scheduling worked and the hold-up is on that node's kubelet: an image pull, a volume. Here it's empty. Now read the event: 0/2 is how many nodes fit, and each number after it counts the nodes with that reason. It doesn't name the nodes. Their labels and taints do.
- A minute later you ask. Node is empty, so this is the scheduler's answer to read.
- You list the nodes' taints. The taint is on node-1.
- You list the disk label. No node has it, so the selector can't match anywhere.
5. Fix one, find another
node-1 is reserved for batch on purpose, so leave its taint alone. node-2 does have an SSD, so you give it the label. The parked Pod was waiting for exactly that: the node change reaches the scheduler, the NodeAffinity plugin says this one matters, and the Pod goes back in the queue. node-2 now passes the label check, reaches the CPU check for the first time, and fails it. Still 0/2, but the reason changed. That's progress.
- You add the missing label to node-2.
- The scheduler hears of the new label and puts the parked Pod back in its queue.
- node-2 gets past the label check, and fails the next one: CPU.
- Still 0/2, but the sentence is different: the CPU problem is now visible.
6. Requests, not usage
node-2 is barely busy: 340m of its 4 CPU are in use. The scheduler doesn't look at usage. It adds up the requests of the Pods on the node, 1.2 CPU, and calls the remaining 2.8 free. Three doesn't fit, whether or not anyone is using it. In your tests search peaked at 1.6 CPU, so you lower its request to 2. A Pod's CPU request can't be changed with a plain edit, so you delete the Pod and apply it again.
- You check what node-2 has promised to its Pods, rather than what they use.
- You delete the stuck Pod. It's gone at once, since it never ran anywhere.
- You apply it again, asking for 2 CPU instead of 3.
- It's a new Pod with the same name, saved and Pending like the first one was.
7. Bound
Same filters, new answer: node-1 still refuses, node-2 passes all of them, and one is all it takes. The scheduler binds the Pod to node-2. For a moment kubectl get pods still says Pending, but now with a node beside it: the kubelet has it and is starting the container. Once the container is up, Pending is over.
- The filters run again: node-1 still refuses, node-2 passes every one.
- The scheduler binds the new Pod to node-2.
- node-2's kubelet sees the Pod on its watch and starts it.
- The container is up and the Pod is Ready.
Summary
An empty Node means the scheduler is holding the Pod; a filled one means the kubelet is. FailedScheduling counts nodes by the first check each one failed, so a fix can reveal another reason, and a changed message is progress. If every reason is right and nothing should change, the cluster needs room: a cluster autoscaler can add a node, and a higher-priority Pod can preempt others.
Next lesson: Reconcile loops