Skip to content
LF Cert Trainer

Lesson 12 · Section 2: Core Concepts

Lesson 12: kube-scheduler: who decides where a Pod runs

What the scheduler does and what it leaves to others, how it filters and scores nodes, where it runs in a kubeadm cluster, and how to read and fix a Pending Pod in the exam. · 20 min read · 4 min video

1/11kube-scheduler
0:00 / 4:11

Narrated by the local narrator voice. Keys: Space plays and pauses, J and L step, C captions, F full screen.

Why the scheduler exists

When you create a Pod, you normally do not say where it should run. A cluster may have three nodes or five thousand, and they are not interchangeable: some are full, some are tainted for special workloads, some do not have the disk, the GPU or the labels the Pod asks for. Something has to look at every new Pod, look at every node, and match them.

That something is kube-scheduler, one of the control plane components. It is deliberately a single decision maker: if several components placed Pods independently, two of them could promise the same free CPU to two different Pods.

What the scheduler does, and what it does not

From kubectl to a running containernode-2createsavePod, no nodedecidesnodeNamePod on node-2startskubectlcreate Pod webAPI serverPod web, node: noneetcdstores the Podkube-schedulerfilter, then scoreBindingweb → node-2kubeletwatches its PodsContainersstarted by runtime
From kubectl to a running container. The scheduler only writes one field: the node name. It reads Pods from the API server and writes its decision back; the kubelet on the chosen node does the rest.

Parts:

  • kubectl (create Pod web)
  • API server (Pod web, node: none)
  • etcd (stores the Pod)
  • kube-scheduler (filter, then score)
  • Binding (web → node-2)
  • kubelet (watches its Pods), in node-2
  • Containers (started by runtime), in node-2

Connections:

  • kubectl to API server: create
  • API server to etcd: save
  • API server to kube-scheduler: Pod, no node
  • kube-scheduler to Binding: decides
  • Binding to API server: nodeName
  • API server to kubelet: Pod on node-2
  • kubelet to Containers: starts

Follow one Pod from kubectl to a running container:

  1. You create the Pod. The API server validates it and saves it in etcd. Its spec.nodeName is empty, so its status is Pending.
  2. The scheduler watches the API server for Pods whose spec.nodeName is empty and whose spec.schedulerName is its own name (default-scheduler unless you say otherwise).
  3. It picks a node and posts a small Binding object to the API server. The API server sets spec.nodeName on the Pod. That is the whole output of the scheduler: one field.
  4. The kubelet on that node watches for Pods carrying its node name. It pulls the images and asks the container runtime to start the containers.

Like every control plane component, the scheduler only ever talks to the API server. It never contacts a node, the kubelet or etcd directly.

QuestionWho answers it
How many Pods should exist?Controllers (Deployment, ReplicaSet, DaemonSet, Job) in kube-controller-manager
On which node does each Pod run?kube-scheduler
Who starts the containers and keeps them running?The kubelet on that node, through the container runtime
Who evicts Pods from a node under memory or disk pressure?The kubelet (node-pressure eviction)

How it picks a node

Filter, then scorependingnono6287: bindPod webrequests 500m CPUkube-schedulerone Pod at a timecontrolplanetaint: filtered outnode-1CPU full: filterednode-2fits, score 62node-3fits, score 87
Filter, then score. Filtering is a hard yes or no per node. Scoring ranks only the nodes that passed, and the highest total wins.

Parts:

  • Pod web (requests 500m CPU)
  • kube-scheduler (one Pod at a time)
  • controlplane (taint: filtered out)
  • node-1 (CPU full: filtered)
  • node-2 (fits, score 62)
  • node-3 (fits, score 87)

Connections:

  • Pod web to kube-scheduler: pending
  • kube-scheduler to controlplane: no
  • kube-scheduler to node-1: no
  • kube-scheduler to node-2: 62
  • kube-scheduler to node-3: 87: bind

The scheduler handles one Pod at a time, in two phases.

Filtering asks a yes or no question for every node: can this Pod run here at all? A node is thrown out if any filter says no. The filters you will meet in the exam:

FilterA node fails when
NodeResourcesFitThe Pod's CPU, memory or other requests do not fit in what is still unreserved on the node
TaintTolerationThe node has a NoSchedule or NoExecute taint that the Pod does not tolerate
NodeAffinityThe node's labels do not match the Pod's nodeSelector or required node affinity
NodeUnschedulableThe node is cordoned (kubectl cordon, kubectl drain)
NodePortsA hostPort the Pod wants is already taken on the node
InterPodAffinity, PodTopologySpreadRequired Pod affinity, anti-affinity or spread rules would be broken
VolumeBinding, VolumeZoneThe Pod's volumes cannot be bound or attached on that node

Scoring then ranks the nodes that passed. Each scoring rule gives every node 0 to 100 points, the points are multiplied by the rule's weight and added up, and the node with the highest total wins (a random one on a tie). By default the scheduler prefers nodes with more free resources after placing the Pod (LeastAllocated), balanced CPU and memory use, nodes that already have the image, and placements that satisfy preferred affinity and spread rules.

Filtering is strict and scoring is only a preference. That maps directly onto the Pod fields you will write: nodeSelector, requiredDuringSchedulingIgnoredDuringExecution and resource requests are filters; preferredDuringSchedulingIgnoredDuringExecution is a score.

Under the hood · The scheduling framework: more than two phases

Filter and score are two of a longer list of extension points. Each one is served by plugins, and the default scheduler is simply a default set of plugins:

  1. queueSort
  2. preFilter
  3. filter
  4. postFilter
  5. preScore
  6. score
  7. reserve
  8. permit
  9. preBind
  10. bind
  11. postBind
One Pod through the scheduler
  • queueSort orders the pending Pods. The default plugin, PrioritySort, puts higher Pod priority first.
  • postFilter runs only when no node passed. The default plugin, DefaultPreemption, looks for a node where deleting lower-priority Pods would make room. If it finds one, it deletes those Pods and records the node in the waiting Pod's status.nominatedNodeName.
  • reserve marks the resources as taken in the scheduler's own cache, so the next Pod is scheduled against the new picture before the first one is even bound.
  • preBind does the slow work, such as waiting for volumes to be provisioned and bound. bind posts the Binding.

Everything up to permit is the scheduling cycle and runs for one Pod at a time. preBind and bind are the binding cycle and run in the background, so a slow volume does not hold up every other Pod.

In very large clusters the scheduler stops filtering once it has found enough nodes that fit (percentageOfNodesToScore). In exam-sized clusters every node is checked.

What happens when nothing fits

Where a pending Pod waitsnextfitsno node fitseventretryActive queuehighest priority 1stScheduling cyclefilter and scoreBinding cyclevolumes, then bindBackoff queue1s, doubling to 10sUnschedulablewaits for a change
Where a pending Pod waits. A Pod that fits nowhere is not retried in a tight loop. It is parked until the cluster changes in a way that could help, then tried again after a short backoff.

Parts:

  • Active queue (highest priority 1st)
  • Scheduling cycle (filter and score)
  • Binding cycle (volumes, then bind)
  • Backoff queue (1s, doubling to 10s)
  • Unschedulable (waits for a change)

Connections:

  • Active queue to Scheduling cycle: next
  • Scheduling cycle to Binding cycle: fits
  • Scheduling cycle to Unschedulable: no node fits
  • Unschedulable to Backoff queue: event
  • Backoff queue to Active queue: retry

If no node passes the filters, the scheduler records a FailedScheduling event on the Pod, sets the Pod's PodScheduled condition to False with reason Unschedulable, and parks the Pod. It does not retry in a tight loop. The Pod is tried again when something happens that could help: a node is added, uncordoned or relabelled, a taint is removed, another Pod is deleted. Before each retry it waits in a backoff queue, one second at first, doubling up to ten seconds.

In practice this means you never have to "kick" a Pending Pod. Fix the cause (free some capacity, remove the taint, correct the label) and the Pod is scheduled a few seconds later on its own.

The scheduler also never revisits a decision. IgnoredDuringExecution in the affinity field names says exactly that: once a Pod is running, later changes to labels or load do not move it.

Ways to steer, replace or bypass it

How the node is chosenSet byThe scheduler's part
Default schedulingNothingFilters and scores all nodes
nodeSelector, affinity, tolerations, requestsFields in the Pod specStill decides, within the limits you set
spec.schedulerName: my-schedulerThe Pod specThe default scheduler ignores the Pod; a scheduler with that name must exist
spec.nodeName: node-2The Pod spec, at creationNone: the Pod already has a node
Static Pod (a file in /etc/kubernetes/manifests)The kubelet's own diskNone: the kubelet runs it without asking anyone
DaemonSetThe DaemonSet controllerSchedules each Pod, pinned to one node by a node affinity the controller adds

Two details in that table are worth remembering:

  • nodeName skips every check. No filter runs, so the Pod lands on a tainted, cordoned or full node all the same. Only NoExecute taints still bite, because the node itself evicts the Pod, and a kubelet that really cannot fit the Pod rejects it (status OutOfcpu or OutOfmemory).
  • More than one scheduler can run. Each one only handles Pods whose schedulerName matches a name it serves. One kube-scheduler process can even serve several names, called profiles, from a single configuration file:
apiVersion: kubescheduler.config.k8s.io/v1
kind: KubeSchedulerConfiguration
profiles:
  - schedulerName: default-scheduler
  - schedulerName: no-scoring-scheduler
    plugins:
      score:
        disabled:
          - name: "*"

Where it runs in a kubeadm cluster

kubeadm runs the scheduler as a static Pod on every control plane node. The kubelet reads the manifest from disk and starts it, which is how the scheduler can run before any scheduler exists.

WhatWhere
Manifest/etc/kubernetes/manifests/kube-scheduler.yaml
Podkube-scheduler-<node name> in kube-system, label component=kube-scheduler
Credentials/etc/kubernetes/scheduler.conf (user system:kube-scheduler), passed with --kubeconfig
Health and metricsHTTPS port 10259, bound to 127.0.0.1 by default (/healthz, /metrics)
Leader lockLease kube-scheduler in kube-system

With several control plane nodes there are several scheduler Pods, but --leader-elect=true makes sure only one is active. The others wait and take over when the leader stops renewing its Lease. That is all the high availability the scheduler needs, because it keeps no state of its own: everything it knows is rebuilt from the API server.

On clusters that are not built with kubeadm the scheduler may be a systemd service instead (systemctl status kube-scheduler, options in the unit file), and on managed clusters such as EKS, GKE or AKS you cannot see it at all.

Using it

Example · Find out why a Pod is Pending

The Pod web has been Pending for a minute. Ask the scheduler why:

kubectl get pod web -o wide                 # NODE is <none>: not scheduled yet
kubectl describe pod web                    # read the Events at the bottom
Warning  FailedScheduling  default-scheduler  0/3 nodes are available: 1 node(s) had untolerated taint
{node-role.kubernetes.io/control-plane: }, 2 Insufficient cpu. preemption: 0/3 nodes are available: 1 Preemption is
not helpful for scheduling, 2 No preemption victims found for incoming pod.

Read it as a tally of the filters: of 3 nodes, 1 was rejected for its taint and 2 for CPU. The numbers always add up to the node count. Now check the cause that you can change:

kubectl get pod web -o jsonpath='{.spec.containers[*].resources.requests}'
kubectl describe node node-1 | grep -A 8 "Allocated resources"

If the Pod asks for cpu: "2" and each worker has about 1.5 CPU unreserved, lower the request or free capacity. The Pod is scheduled by itself once it fits.

Example · Repair a scheduler that is down

New Pods stay Pending and kubectl describe pod shows no events at all. Nobody is scheduling. On a kubeadm cluster, check the scheduler's own Pod:

kubectl -n kube-system get pods -l component=kube-scheduler
kubectl -n kube-system logs kube-scheduler-controlplane

If the Pod is missing or kubectl logs gives nothing useful, go to the control plane node and ask the container runtime and the kubelet directly:

ssh controlplane
sudo crictl ps -a --name kube-scheduler          # is there a container, and did it exit?
sudo crictl logs <container-id>                  # why it exited
sudo journalctl -u kubelet --since "5 min ago" | grep -i scheduler   # manifest could not be parsed?
sudo vi /etc/kubernetes/manifests/kube-scheduler.yaml

Typical breakages are a typo in the command or image, a wrong path in --kubeconfig, a volume that mounts a file that does not exist, or the manifest moved out of the folder. Save the fixed file and wait: the kubelet notices the change and recreates the Pod within a few seconds. Then confirm that the waiting Pods get nodes:

kubectl -n kube-system get pods -l component=kube-scheduler
kubectl get pods -o wide

Example · Place a Pod by hand

You are asked to run a Pod on node-2 without the scheduler, or the scheduler is down and a Pod must start now. Set nodeName when you create it:

kubectl run web --image=nginx:1.29-alpine --dry-run=client -o yaml > web.yaml
apiVersion: v1
kind: Pod
metadata:
  name: web
spec:
  nodeName: node-2
  containers:
    - name: web
      image: nginx:1.29-alpine
kubectl apply -f web.yaml
kubectl get pod web -o wide                 # NODE is node-2, with no Scheduled event

nodeName cannot be changed on an existing Pod. For a Pod that is already Pending, export it, add the field and recreate it in one step:

kubectl get pod web -o yaml > web.yaml      # add nodeName under spec
kubectl replace --force -f web.yaml         # deletes and creates

Example · Send a Pod to a second scheduler

A second scheduler named my-scheduler runs in the cluster. Only one line in the Pod chooses it:

apiVersion: v1
kind: Pod
metadata:
  name: batch
spec:
  schedulerName: my-scheduler
  containers:
    - name: batch
      image: busybox:1.37
      command: ["sleep", "3600"]

Prove which scheduler placed it. The Scheduled event names its source:

kubectl get events --field-selector involvedObject.name=batch,reason=Scheduled \
  -o custom-columns=FROM:.reportingComponent,MESSAGE:.message

Tricks

Common mistakes

  • Thinking the scheduler starts Pods. It only writes the node name. A Pod that is ContainerCreating, ImagePullBackOff or CrashLoopBackOff has already been scheduled; the problem is on the node, not in the scheduler.
  • Looking at kubectl top to explain "Insufficient cpu". The scheduler compares requests with allocatable capacity. Look at Allocated resources in kubectl describe node.
  • Trying to edit nodeName or schedulerName on a live Pod. Both are fixed at creation. Recreate the Pod (kubectl replace --force -f), or change the Pod template of the Deployment that owns it.
  • Using nodeName and expecting taints to hold. nodeName skips the scheduler, so NoSchedule taints and cordons are not checked. Use nodeSelector or node affinity when you want the checks to stay on.
  • Restarting the scheduler with kubectl delete pod. For a static Pod this only deletes the mirror object in the API; the kubelet puts it straight back. Real changes are made in the manifest file on the node.
  • Waiting for the scheduler to rebalance. It places each Pod once. Adding a node does not move running Pods onto it; only new or recreated Pods can land there.

Recap

  • kube-scheduler gives every new Pod a node by setting spec.nodeName; the kubelet does the rest.
  • It filters out nodes that cannot run the Pod, scores the others and binds to the best one.
  • It counts resource requests, never real usage, and never moves a running Pod.
  • On kubeadm it is a static Pod: /etc/kubernetes/manifests/kube-scheduler.yaml, one active leader.
  • Pending with FailedScheduling: fix the Pod or the nodes. Pending with no events: fix the scheduler.

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.

  • New pods stay Pending without a single event. Find out why the scheduler of a kubeadm cluster does not run, and repair it instead of doing its work by hand.

    Fix · Level 2 · standard · target 15 min

Discussion

Learners ask and answer questions here. Sign in to read and join the discussion.