Sub topic 5
How the scheduler decides where a pod runs
This chapter assumes you know what pods, nodes, and deployments are, and that you can read kubectl describe output and YAML manifests. It explains the placement step so that the later Pending chapters make sense.
What the scheduler does
The scheduler is a control plane component called kube-scheduler. It watches for pods whose spec.nodeName field is empty. For each one, it picks a node and records the choice. The kubelet on that node then sees the pod assigned to it and starts the containers.
The scheduler does not start containers. It only decides placement. A pod with no node assigned is in the Pending phase.
Filter, then score
For each unassigned pod, the scheduler works in two steps:
- Filtering removes every node that cannot run the pod. The remaining nodes are the feasible nodes.
- Scoring ranks the feasible nodes. Factors include spreading pods evenly and preferring nodes that already have the image. The highest score wins, and ties are broken at random.
The scheduler then binds the pod by setting spec.nodeName. If filtering leaves zero nodes, there is nothing to score. The pod stays Pending, and the scheduler records a FailedScheduling event. It retries when something changes, such as a pod being deleted or a node being added.
What filtering checks
Each of these is a filter. A node that fails any one is excluded.
| Check | Question the scheduler asks |
|---|---|
| Resources | Do the pod's requests fit in the node's allocatable capacity, after subtracting pods already placed? |
| Taints | Does the pod tolerate every taint on the node? |
| Node selector and affinity | Do the node's labels match the pod's `nodeSelector` or required affinity rules? |
| Volumes | Can the pod's volumes be attached on this node, and are its claims bound? |
The later chapters on Pending pods cover each failure in detail.
See the decision for a running pod
After a successful placement, you can see where the pod went and what the scheduler said:
kubectl get pod web -o jsonpath='{.spec.nodeName}{"\n"}'
kubectl get events --field-selector involvedObject.name=web,reason=ScheduledThe first command prints the chosen node. The second shows the Scheduled event, with a message like Successfully assigned default/web to node-1.
Why this matters for triage
If a pod has a node name, scheduling worked, and your problem is in image pulls or the container itself. If it has no node name, the problem is in filtering, and the FailedScheduling message tells you which check failed.
Exercise
A pod is Pending and kubectl get pod web -o jsonpath='{.spec.nodeName}' prints nothing. Another pod on the same node shows low CPU usage in your monitoring tool. Why might the scheduler still reject that node for the Pending pod?
Show answer
The scheduler checks requests, not live usage. The pods already on the node may have requested most of its allocatable CPU, so the new pod's request does not fit, even though actual usage is low.