Scheduling: Placing Pods on the Right Nodes

Topics Covered

How the Scheduler Decides

The scheduling cycle

Requests, not usage

What else the filter checks

Reading the scheduler's view of a node

Choosing a scheduler

The order to try fixes

What the grader looks for

A quick vocabulary check

Scheduling is a one time decision

Scheduling tasks on the administrator exam are short and precise. You are asked to make a pod land on a particular node, keep pods off a node, spread replicas, give a workload priority, or explain why a pod is Pending and fix it. Each one maps to a specific field in the pod spec or a specific command on a node. This lesson covers the fields and commands, but it starts with how the scheduler thinks, because every Pending pod you debug is the scheduler telling you that no node passed its filters.

Draining and cordoning were covered during upgrades in the cluster install lesson; here they appear only as scheduling controls. Static pods were covered as the control plane mechanism; this lesson returns to them briefly as a way to place a pod without the scheduler.

The scheduling cycle

kube-scheduler watches for pods whose spec.nodeName is empty. For each one, it runs two phases. Filtering removes every node that cannot run the pod: not enough requested CPU or memory left, a taint the pod does not tolerate, a nodeSelector or required affinity that does not match, a port conflict, a volume that cannot attach there, or a node that is cordoned. Scoring ranks the nodes that survive, using plugins that prefer balanced resource use, matching preferred affinities, spreading replicas and having the image already pulled. The highest score wins, ties are broken randomly, and the scheduler writes a Binding that sets spec.nodeName. From then on the kubelet on that node owns the pod.

Every pod goes through the same cycle: filter the nodes, score the survivors, bind to the winner.

If filtering leaves zero nodes, the pod stays Pending, and the scheduler records an event explaining what each group of nodes failed on. That event is the single most useful thing to read in a scheduling task.

bash
1kubectl describe pod web-1 | sed -n '/Events/,$p'
2# Warning  FailedScheduling  0/3 nodes are available: 1 node(s) had untolerated taint
3#   node-role.kubernetes.io/control-plane: , 2 Insufficient cpu.
4#   preemption: 0/3 nodes are available: 3 No preemption victims found for incoming pod.

Read the message as a tally. It says how many nodes failed and why, grouped by reason. A message with mixed reasons tells you that fixing one cause will not be enough.

Requests, not usage

The scheduler places pods by their resource requests, not by what the containers actually use. A node with 4 CPUs allocatable and pods requesting 3.8 CPUs between them is nearly full in the scheduler's eyes, even if the CPU is idle. A pod with no requests counts as needing zero for scheduling purposes, which is why best effort pods can land on nodes that look full.

bash
1kubectl describe node node2 | sed -n '/Allocatable/,/Events/p'
2# Allocated resources:
3#   Resource  Requests      Limits
4#   cpu       3800m (95%)   6 (150%)
5#   memory    6Gi (78%)     8Gi (104%)

Allocatable is the node's capacity minus what the kubelet reserves for the system and for itself. The Allocated resources table sums requests and limits of all pods on the node. When a pod is Pending with Insufficient cpu, compare its request against the free allocatable on each node. The fix is one of three things: lower the pod's request, free capacity by removing or shrinking other pods, or add a node.

Limits do not affect scheduling. A node can be overcommitted on limits, as in the example above where limits add up to 150 percent of CPU. Limits matter at runtime: CPU above the limit is throttled, memory above the limit gets the container killed. The pods lesson covers requests and limits in detail.

What else the filter checks

Besides resources and the placement rules in the rest of this lesson, the filter checks a few things that surprise people. Host ports: two pods requesting the same hostPort cannot share a node. Volume topology: a PersistentVolume bound to one zone can only be used by pods on nodes in that zone, and a pod using a local volume can only go to that volume's node. Node conditions: a node with memory or disk pressure gets a taint, which repels new pods. Node readiness: a NotReady node is tainted with node.kubernetes.io/not-ready, so new pods avoid it.

The volume case is a classic trap. A pod is Pending, the message mentions volume node affinity conflict, and the cause is that its claim is bound to a volume pinned to a node or zone that cannot take the pod. The storage lesson covers volume binding modes; for scheduling, remember that WaitForFirstConsumer exists so the volume is created where the pod lands, not the other way round.

Reading the scheduler's view of a node

Several commands give you the scheduler's view quickly. Labels show what selectors and affinity rules can match. Taints show what repels pods. Allocatable and allocated resources show capacity. The SchedulingDisabled status shows a cordon.

bash
1kubectl get nodes --show-labels
2kubectl get nodes -L topology.kubernetes.io/zone,disktype
3kubectl describe node node2 | grep -A3 Taints
4kubectl get nodes -o custom-columns=NAME:.metadata.name,TAINTS:.spec.taints[*].key

The -L flag adds a column for each label you name, which is much easier to read than --show-labels on a node with twenty built in labels. Use it whenever a task mentions specific labels.

Choosing a scheduler

A pod can name a different scheduler with spec.schedulerName. The default is default-scheduler. If a pod names a scheduler that does not exist, nothing picks it up and it stays Pending with no events at all, which looks exactly like the default scheduler being down. When you see a Pending pod with an empty events section, check schedulerName before anything else.

bash
kubectl get pod web-1 -o jsonpath='{.spec.schedulerName}'

The exam may ask you to run a pod with a second scheduler that has already been deployed. The task is just that one field in the pod spec.

The order to try fixes

When a pod will not schedule, work from the event message, not from guesses. If the message mentions taints, look at the node's taints and the pod's tolerations. If it mentions node affinity or selector, compare the pod's rules with the node labels. If it mentions insufficient resources, compare requests with free allocatable. If it mentions pod affinity or anti affinity, look at which pods are already on each node. If there is no event, check schedulerName and whether kube-scheduler is running. That order handles almost every scheduling task the exam can set.

What the grader looks for

A scheduling task is graded on where the pod ended up and on the spec that put it there. Typical checks are that the pod is Running, that spec.nodeName is a particular node or one of an allowed set, and sometimes that the pod spec contains the expected field, such as a toleration with the right key and effect or an affinity rule with the right operator. That second kind of check means the route matters as well as the result: if a task says to use node affinity, a nodeSelector that happens to land on the same node may not satisfy it. Read for the mechanism the task names, use that mechanism, and finish by checking the pod's node with kubectl get pod -o wide.

A quick vocabulary check

Four terms come up again and again in task text and are easy to blur under pressure. A selector or affinity rule is something the pod says about nodes it wants. A taint is something a node says about pods it rejects. A toleration is something a pod says about taints it can live with. Cordoning is something an administrator does to a node to stop new placements without touching running pods. Each section of this lesson takes one of those and shows the exact fields.

Scheduling is a one time decision

Once a pod is bound, the scheduler never looks at it again. It does not move pods to better nodes when new nodes join, when load becomes uneven, or when labels change. The only things that relocate a pod are its deletion and recreation, by you, by a controller during a rollout, by an eviction, or by preemption. Projects such as the descheduler exist to evict pods that no longer fit current rules so that the scheduler can place them again, but they are add ons, not part of a kubeadm cluster. On the exam, if a task asks you to move a running pod, the answer is always to recreate it with the right spec, never to wait for the scheduler to notice.

Pending is a message, not a mystery

The FailedScheduling event lists every node and why it was filtered out. Read it before changing anything; it usually names the fix directly.