Skip to content
LF Cert Trainer

Lesson 26 · Section 3: Scheduling

Lesson 26: Scheduling introduction: every way to decide where a Pod runs

A map of the scheduling section: the path a Pod takes to a node, what the Pod can ask for and what a node can refuse, which rules are hard and which are only preferences, and which Pods never meet the scheduler at all. · 15 min read · 4 min video

1/10Scheduling introduction
0:00 / 4:05

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

Why this section exists

In the core concepts you met kube-scheduler: the control plane component that gives every new Pod a node. Left alone, it puts a Pod on any node that has room for it. That is fine for a stateless web server, and wrong for a surprising number of real workloads:

  • a database should land on the nodes with fast disks;
  • the expensive GPU nodes should stay free for the jobs that need a GPU;
  • a log collector has to run on every node, including nodes that join next month;
  • when the cluster is full, the payment service should win over the nightly report.

This section is about your side of the conversation with the scheduler: every field and object you can use to say where a Pod should run, where it must not, and what happens when both cannot be true. This lesson is the map. The lessons after it take the tools one at a time, and each of them is something the CKA exam can ask you to configure or repair in a couple of minutes.

The path from kubectl to a node

The path from kubectl to a nodekube-schedulercreatesaved, Pendingnextpassedbest nodePod has a nodestartskubectlcreate Pod webAdmissionmutate, validateScheduling queuehigh priority firstFilterhard rules: yes or noScoresoft rules: rankBindsets spec.nodeNamekubeleton the chosen nodeContainerslimits enforced here
The path from kubectl to a node. Every topic in this section acts at one of these stops. Admission can change or reject the Pod before it is saved, priority orders the queue, hard rules filter nodes, soft rules rank them, and the kubelet runs what it is given.

Parts:

  • kubectl (create Pod web)
  • Admission (mutate, validate)
  • Scheduling queue (high priority first), in kube-scheduler
  • Filter (hard rules: yes or no), in kube-scheduler
  • Score (soft rules: rank), in kube-scheduler
  • Bind (sets spec.nodeName), in kube-scheduler
  • kubelet (on the chosen node)
  • Containers (limits enforced here)

Connections:

  • kubectl to Admission: create
  • Admission to Scheduling queue: saved, Pending
  • Scheduling queue to Filter: next
  • Filter to Score: passed
  • Score to Bind: best node
  • Bind to kubelet: Pod has a node
  • kubelet to Containers: starts

Every topic in this section acts at one stop on this path, so it pays to know the order:

  1. Admission. Before the Pod is saved, the API server passes it through its admission controllers. They can change the Pod (fill in default requests from a LimitRange, add default tolerations, resolve a priority class name into a number) or reject it (a ResourceQuota is used up). What the scheduler sees is the Pod after admission, which may not be exactly what you wrote.
  2. The queue. The saved Pod has an empty spec.nodeName and shows as Pending. It waits in the scheduling queue, where Pods with a higher priority go first.
  3. Filter. The scheduler takes one Pod and asks of every node: can this Pod run here at all? These are the hard rules. One "no" removes the node.
  4. Score. The nodes that passed are ranked by the soft rules, the preferences. The best total wins.
  5. Bind. The scheduler writes the winner into spec.nodeName. Its work on this Pod is finished, for good.
  6. Run. The kubelet on that node starts the containers and enforces their resource limits for as long as they run.

If step 3 leaves no node, the scheduler can try preemption: removing Pods of lower priority to make room. Otherwise the Pod stays Pending with a FailedScheduling event, and is tried again when the cluster changes.

The toolbox

These are the tools of the section, grouped by what they are for. The middle column is where you configure them, which is the thing to memorise.

You want toToolWhere it livesKind of rule
Put a Pod on one exact node yourselfManual schedulingspec.nodeNameBypasses the scheduler
Run a Pod only on nodes of a certain kindNode selectorspec.nodeSelector + node labelsHard
The same, with "or", "not" and preferencesNode affinityspec.affinity.nodeAffinity + node labelsHard or soft
Keep Pods off a node unless they opt inTaints and tolerationsTaint on the node, spec.tolerations on the PodHard, or soft with PreferNoSchedule
Reserve room for a PodResource requestsspec.containers[].resources.requestsHard
Cap what a container may useResource limitsspec.containers[].resources.limitsNot a scheduling rule: enforced on the node
Run one copy on every nodeDaemonSetA workload objectScheduler, one Pod pinned per node
Run a Pod with no API server at allStatic PodA manifest file on the nodeBypasses the scheduler
Decide who goes first, and who is evicted to make roomPriority classesPriorityClass object + spec.priorityClassNameQueue order and preemption
Use a different placement policyMultiple schedulers, scheduler profilesspec.schedulerName + scheduler configurationChooses who decides
Change or reject Pods before they are savedAdmission controllersAPI server, webhooksBefore scheduling

Labels and selectors sit underneath several of these. Nodes are objects with labels like any other, and a node selector or a node affinity rule is nothing more than a label query against nodes. Getting comfortable with labels first makes the rest of the section much easier.

The Pod asks, the node answers

What the Pod asks, what the node answersPod specNodeasksoffersasksoffersacceptsrefusesnodeSelector, affinityI need disktype=ssdLabels match?NodeAffinity filterNode labelsdisktype=ssdRequestsI need 500m CPUDoes it fit?NodeResourcesFitAllocatableminus other requestsTolerationsI accept gpu taintTaints tolerated?TaintTolerationTaintsgpu=true:NoSchedule
What the Pod asks, what the node answers. Each hard rule is a pair: a field in the Pod spec and a property of the node. A node stays in the race only if every pair matches.

Parts:

  • nodeSelector, affinity (I need disktype=ssd), in Pod spec
  • Labels match? (NodeAffinity filter)
  • Node labels (disktype=ssd), in Node
  • Requests (I need 500m CPU), in Pod spec
  • Does it fit? (NodeResourcesFit)
  • Allocatable (minus other requests), in Node
  • Tolerations (I accept gpu taint), in Pod spec
  • Taints tolerated? (TaintToleration)
  • Taints (gpu=true:NoSchedule), in Node

Connections:

  • nodeSelector, affinity to Labels match?: asks
  • Node labels to Labels match?: offers
  • Requests to Does it fit?: asks
  • Allocatable to Does it fit?: offers
  • Tolerations to Taints tolerated?: accepts
  • Taints to Taints tolerated?: refuses

Each hard rule is a pair: one half in the Pod spec, one half on the node.

The Pod saysThe node saysThe node passes when
nodeSelector or required node affinityIts labelsThe labels satisfy the Pod's rule
Resource requestsAllocatable, minus the requests of the Pods already placed thereThe requests still fit
TolerationsIts taintsEvery NoSchedule and NoExecute taint is tolerated
(nothing)spec.unschedulable (set by kubectl cordon and kubectl drain)The node is not cordoned

Three consequences follow, and each one is a classic exam trap:

  • Hard rules are combined with "and". A node must pass every one of them. Each rule you add can only shrink the list of candidate nodes, never grow it.
  • Attract and repel are different tools. A node selector or affinity pulls a Pod toward certain nodes, but does nothing to keep other Pods off those nodes. A taint pushes Pods away, but a toleration does not pull: it only says "I am allowed here", and the Pod may well land elsewhere. A dedicated node needs both.
  • An empty Pod side means "anything goes". A Pod with no selector fits every label. A Pod with no requests fits on a node that is already full. A Pod with no tolerations is refused by every tainted node, which is exactly why ordinary Pods do not land on a kubeadm control plane node.

Hard rules and soft rules

Hard (required)Soft (preferred)
Scheduler phaseFilterScore
If no node satisfies itThe Pod stays PendingThe Pod runs somewhere else
ExamplesnodeSelector, requiredDuringSchedulingIgnoredDuringExecution, requests, NoSchedule taints, cordonpreferredDuringSchedulingIgnoredDuringExecution, PreferNoSchedule taints

When a task says a Pod "must" or "should only" run somewhere, it wants a hard rule. When it says "should preferably" or "if possible", it wants a soft one. Using a hard rule where a soft one was asked for can leave the Pod Pending, and the other way round lets it run in the wrong place.

Under the hood · What admission quietly adds to your Pod

Compare a Pod you created with what kubectl get pod web -o yaml returns, and you will find scheduling fields you never wrote. They come from admission controllers that are enabled by default:

  • tolerations for node.kubernetes.io/not-ready and node.kubernetes.io/unreachable with tolerationSeconds: 300 (DefaultTolerationSeconds). This is why Pods stay bound to a node that went down for five minutes before they are evicted and replaced.
  • priority, the number behind priorityClassName, or the value of the global default class (Priority).
  • resources.requests and resources.limits, when the namespace has a LimitRange with defaults (LimitRanger). A Pod you wrote without requests may reach the scheduler with requests, and then not fit.

The DaemonSet controller does something similar to its own Pods: it adds a node affinity that matches exactly one node name, plus tolerations so that the Pod survives node problems. The default scheduler then places the Pod, and it has only one node to choose from.

Pods that never meet the scheduler

Who gives each Pod its nodeno nodeno node yetbindsdirectread from diskstartsDeployment PodnodeName emptykube-schedulerfilter, score, bindBest nodeall checks passedDaemonSet Podpinned to one nodePod with nodeNameset at creationkubeleton the named nodeContainersno filters ranStatic Podfile on the node
Who gives each Pod its node. Most Pods go through the scheduler, including the Pods of a DaemonSet. Two kinds do not: a Pod created with nodeName already set, and a static Pod that the kubelet reads from its own disk.

Parts:

  • Deployment Pod (nodeName empty)
  • kube-scheduler (filter, score, bind)
  • Best node (all checks passed)
  • DaemonSet Pod (pinned to one node)
  • Pod with nodeName (set at creation)
  • kubelet (on the named node)
  • Containers (no filters ran)
  • Static Pod (file on the node)

Connections:

  • Deployment Pod to kube-scheduler: no node
  • DaemonSet Pod to kube-scheduler: no node yet
  • kube-scheduler to Best node: binds
  • Pod with nodeName to kubelet: direct
  • Static Pod to kubelet: read from disk
  • kubelet to Containers: starts

The scheduler only handles Pods whose spec.nodeName is empty. Two kinds of Pod never are:

PodWho chose the nodeWhat is skipped
Created with spec.nodeName setYouEvery filter: labels, NoSchedule taints, cordon and the scheduler's resource check
Static Pod (a manifest in the kubelet's folder, /etc/kubernetes/manifests on kubeadm)The file's locationThe scheduler and the API server: the kubelet runs it on its own and only reports a read-only mirror Pod

A DaemonSet is often put in the same list, but it does not belong there. Its Pods are placed by the default scheduler like any other; the controller only narrows the choice to one node per Pod. That is why a DaemonSet Pod can be Pending with a FailedScheduling event, for example on a node with a taint it does not tolerate, and a static Pod never can.

Using it

Example · Find out where Pods run, and who put them there

Start every scheduling task by looking at the NODE column:

kubectl get pods -o wide                          # NODE <none> means not scheduled yet
kubectl get pods -A -o wide --field-selector spec.nodeName=node-1   # everything on one node
kubectl get pods -A --field-selector spec.nodeName=                 # everything without a node

For one Pod, the events tell you who placed it:

kubectl get events --field-selector involvedObject.name=web
LAST SEEN   TYPE     REASON      OBJECT    MESSAGE
12s         Normal   Scheduled   pod/web   Successfully assigned default/web to node-2
11s         Normal   Pulled      pod/web   Container image "nginx:1.29-alpine" already present on machine

A Scheduled event means the scheduler chose the node. A running Pod without one was placed by nodeName or is a static Pod (its name ends in the node name, such as etcd-controlplane).

Example · Look at a node the way the scheduler does

Before writing a rule, check the node half of each pair:

kubectl get nodes --show-labels                   # all labels (long)
kubectl get nodes -L disktype,topology.kubernetes.io/zone   # chosen labels as columns
kubectl describe nodes | grep -E '^Name:|^Taints:|^Unschedulable:'
kubectl describe node node-1 | grep -A 8 'Allocated resources'
Name:               node-2
Taints:             gpu=true:NoSchedule
Unschedulable:      false

Labels answer selectors and affinity, taints answer tolerations, Unschedulable is the cordon, and Allocated resources shows how much of the node's Allocatable is already promised to other Pods' requests.

Example · Read every scheduling field of a Pod

The Pod half is spread over a handful of fields. One command prints them all:

kubectl get pod web -o jsonpath='{.spec.nodeName}{"\n"}{.spec.nodeSelector}{"\n"}{.spec.tolerations}{"\n"}{.spec.priorityClassName}{"\n"}{.spec.schedulerName}{"\n"}{.spec.containers[*].resources}{"\n"}'

And when you need to write one and have forgotten the exact name or nesting, ask the cluster instead of the docs:

kubectl explain pod.spec | grep -iE -A 1 'nodeName|nodeSelector|affinity|tolerations|priorityClassName|schedulerName'
kubectl explain pod.spec.affinity.nodeAffinity --recursive
kubectl explain pod.spec.tolerations

Example · Predict where a Pod lands, then check

A cluster has three nodes:

NodeLabelTaint
controlplane(none)node-role.kubernetes.io/control-plane:NoSchedule
node-1disktype=hdd(none)
node-2disktype=ssdgpu=true:NoSchedule

You create this Pod. Where does it run?

apiVersion: v1
kind: Pod
metadata:
  name: web
spec:
  nodeSelector:
    disktype: ssd
  containers:
    - name: web
      image: nginx:1.29-alpine
      resources:
        requests:
          cpu: 500m

Nowhere. Take the nodes one at a time: controlplane is tainted, node-1 has the wrong label, and node-2 has the right label but a taint the Pod does not tolerate. The selector pulled the Pod toward node-2; it did not open the door.

kubectl describe pod web | tail -n 3
Warning  FailedScheduling  default-scheduler  0/3 nodes are available: 1 node(s) didn't match Pod's node
affinity/selector, 1 node(s) had untolerated taint {gpu: true}, 1 node(s) had untolerated taint
{node-role.kubernetes.io/control-plane: }.

The event counts each node once, under the first rule it failed. Add the missing half of the pair and the Pod is scheduled on node-2. Scheduling fields cannot be edited on a live Pod, so recreate it:

spec:
  nodeSelector:
    disktype: ssd
  tolerations:
    - key: gpu
      operator: Equal
      value: "true"
      effect: NoSchedule
kubectl replace --force -f web.yaml
kubectl get pod web -o wide                       # NODE is node-2

Tricks

Common mistakes

  • Using a toleration to send a Pod to a node. A toleration only removes an objection. To make the Pod go to the tainted node, add a node selector or node affinity as well.
  • Using a node selector to reserve a node. It steers your Pod, and leaves the node open to every other Pod. To keep others out, taint the node.
  • Confusing requests with limits. The scheduler places Pods by their requests. Limits play no part in choosing a node; they are enforced on the node while the container runs.
  • Putting DaemonSets and static Pods in the same box. Both give you "a Pod on a particular node", but a DaemonSet Pod goes through the scheduler and the API server, and a static Pod needs neither.
  • Expecting running Pods to follow a rule change. Relabelling a node or adding a NoSchedule taint affects only Pods scheduled afterwards. Only a NoExecute taint moves Pods that are already running.
  • Stacking hard rules until nothing fits. A selector, a required affinity, a large request and a tainted node are combined with "and". If the Pod is Pending, remove rules one at a time, or read the event.

Recap

  • A Pod's path: admission, the queue (priority), filter (hard rules), score (soft rules), bind, then the kubelet runs it.
  • Hard rules are pairs: selector or affinity with node labels, requests with allocatable, tolerations with taints. A node must pass all of them.
  • Selectors and affinity attract, taints repel. A dedicated node needs both.
  • Required means Pending when nothing matches; preferred means "somewhere else is fine".
  • nodeName and static Pods bypass the scheduler; DaemonSet Pods do not.
  • Rules are checked once, at scheduling time. To move a Pod, recreate it.

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.

Discussion

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