Scheduler: filtering, scoring, and why a pod is Pending

Filter then score: predicates remove nodes that cannot host the pod, priorities rank the rest, then it is bound. Pending is nearly always requests, taints or a spread rule with nowhere left to go.

Read the briefing
About 4 min to read 8 drills

What to remember

  1. Scheduling uses requests, never limits. A pod requesting 2 CPU cannot land on a node with 1.8 allocatable, whatever the limit says.
  2. The FailedScheduling event is the answer. kubectl describe pod prints the per-predicate summary. Read it before theorising.
  3. Anti-affinity across hosts caps replicas at the node count. The classic 'only two replicas ever become Ready' bug.
  4. Allocatable is capacity minus reservations. The node's advertised size is not what you can schedule into.
  5. Preemption is not instant. Victims get their grace period, then reschedule elsewhere — possibly preempting again.

The big picture

The scheduler is the control-plane component that decides which node a new pod runs on. It watches for pods with no nodeName, filters out nodes that cannot host the pod, scores the survivors, and writes a binding. Nearly every "my pod is Pending" incident and every placement question in an interview comes back to those two phases and to what the FailedScheduling event tells you about them.

The mental model

Think of it as a two-stage sieve. Stage one, filtering, is a set of hard yes/no gates: does the pod's request fit the node's allocatable, does the nodeSelector match, are the taints tolerated, do required affinities hold, are the volumes attachable here? Stage two, scoring, ranks whatever survived (spread, image locality, least-allocated). If nothing survives stage one, the pod waits, and the event lists exactly how many nodes each gate removed.

In depth

How a pod gets a node

The scheduler runs a watch on pods whose spec.nodeName is empty. For each one it runs the filtering phase (historically "predicates"): NodeResourcesFit compares the pod's requests to the node's allocatable (capacity minus kube-reserved and system-reserved); NodeAffinity and NodeName handle selectors and required affinity; TaintToleration removes nodes with untolerated NoSchedule taints; InterPodAffinity and PodTopologySpread enforce pod-to-pod rules; VolumeBinding checks that the pod's PVCs can be bound on that node. Every plugin can veto.

The survivors go through scoring (historically "priorities"): spread pods across nodes and topology domains, prefer nodes that already have the image, prefer less-allocated nodes (or more-allocated, if you configure bin-packing), honour preferredDuringScheduling affinities. The highest score wins and the scheduler creates a Binding, which is what sets nodeName. Only then does the kubelet on that node see the pod and start it.

Requests, not limits, and not usage

The single most common misunderstanding: the scheduler places by requests, never by limits and never by actual usage. kubectl top showing a node at 30% CPU tells you nothing about whether a pod can schedule there; the question is whether the sum of requests already on the node plus this pod's request exceeds allocatable. That is why clusters "look empty" and still refuse pods (requests are over-provisioned), and why a pod with no requests can land on a saturated node and be starved.

Reading the FailedScheduling event

kubectl describe pod shows a line like 0/12 nodes are available: 3 Insufficient cpu, 5 node(s) had untolerated taint {dedicated: gpu}, 4 node(s) didn't match Pod's node affinity/selector. Read it as a ledger: each clause is one filter and how many nodes it removed; the counts add up to the cluster. It also reports preemption: preemption: 0/12 nodes are available: 12 No preemption victims found means even evicting lower-priority pods would not make room. This one event usually tells you the fix.

Priority and preemption

PriorityClass gives pods an integer priority. When a high-priority pod cannot be scheduled, the scheduler looks for a node where evicting lower-priority pods would make it fit, evicts them (graceful termination applies), and schedules the pod. PodDisruptionBudgets are respected best-effort during preemption, not absolutely, which surprises people. Preemption is how you guarantee critical system pods can always land; it is also how a badly chosen priority can evict production during an incident.

Constraints you will be asked to compare

nodeSelector is a hard label match. nodeAffinity adds expressions and a preferred (soft) form. Taints live on nodes and repel pods unless tolerated; NoSchedule blocks placement, PreferNoSchedule discourages it, NoExecute also evicts running pods. Pod affinity/anti-affinity relates pods to each other by topology key; the required anti-affinity form caps replicas at the number of topology domains. topologySpreadConstraints are the modern tool for even distribution with maxSkew and a soft whenUnsatisfiable: ScheduleAnyway option.

Myths and facts

Myth: The scheduler looks at CPU and memory limits.

Fact: Filtering uses requests against allocatable. Limits are enforced later by the kubelet through cgroups.

Myth: If a node has free CPU in kubectl top, a pod can be scheduled there.

Fact: Usage is irrelevant; the sum of requests is what fills a node from the scheduler's point of view.

Myth: A NoSchedule taint evicts pods that are already running.

Fact: Only NoExecute evicts. NoSchedule and PreferNoSchedule affect placement only.

Myth: PodDisruptionBudgets make pods immune to preemption.

Fact: PDBs are honoured best-effort during preemption; they are absolute only for the Eviction API (drains).

Myth: Required pod anti-affinity is the right way to spread replicas.

Fact: It caps replicas at the number of topology domains and blocks scheduling beyond that; topologySpreadConstraints with ScheduleAnyway is the safer default.

How pros do it

  • Set requests from observed p95 usage for every container; scheduling is only as honest as the requests are.
  • Read the FailedScheduling event before touching anything; it names the filter and the fix.
  • Use topologySpreadConstraints for spreading and reserve required anti-affinity for true one-per-host needs.
  • Give system and latency-critical workloads a PriorityClass and make preempted workloads preemption-safe (Jobs with retries, checkpoints).
  • Use taints for dedicated pools and always pair them with tolerations in the workloads that belong there; alert on Pending pods older than a few minutes.

Questions people ask

Why is my pod Pending when nodes have plenty of free CPU?

Say 'requests, not usage' first: the scheduler counts the sum of requests already on each node against allocatable, and other pods' requests already fill it. Then name the evidence you would read: the pod's FailedScheduling event and the Allocated resources table in kubectl describe node. Ask 'free by usage or by requests?' out loud; it shows you know the distinction is the whole topic.

Does the scheduler move pods to rebalance a cluster?

Say no: scheduling happens once, at placement. Then say what rebalancing actually takes: the descheduler, or a rollout that recreates pods. Candidates who assume pods move on their own reveal they have not watched a skewed cluster stay skewed.

What happens to a Pending pod when I add a node?

Say the scheduler retries unschedulable pods when cluster state changes, so a new node that passes the filters gets the pod within seconds. Then connect it: the cluster autoscaler works by making exactly this happen, which is why Pending pods with Insufficient cpu are its trigger.

Why did my high-priority pod evict something even though a PDB existed?

Say that preemption honours PDBs best-effort: the scheduler prefers victims whose eviction keeps budgets intact, but if no victim set satisfies the PDB it may still preempt. Then say where PDBs are absolute: the Eviction API, so drains and autoscaler scale-down. Use PDBs for drains and choose priorities carefully.

Can I run two schedulers?

Yes: pods choose with spec.schedulerName. Then temper it: custom schedulers are rare in practice, because scheduling profiles and plugins cover most needs. Say that, and you sound like someone who has considered it and not needed it.

How many pods can the scheduler place per second, and does it matter?

Say 'hundreds per second on a healthy control plane' and that it only matters in large batch bursts. Then give the diagnostic rule: if pods sit Pending with no FailedScheduling event, look at the scheduler's health and leader lease, not at capacity.

Further reading

Drills · 8

Answer in your head, or out loud, before you reveal. Mark each one: "Again" brings it back, "Got it" counts on your desk.

1 Pick the strongest answer

A Deployment's pods request cpu: 2 with no CPU limit. Every node reports allocatable.cpu: 1900m. The pods have been Pending for ten minutes. Walk me through why.

  1. The kubelet rejected the pod because it would exceed the node's CPU quota. The kubelet admits pods only after the scheduler binds them; a Pending pod has not reached any kubelet.
  2. The pod needs a PriorityClass to be scheduled when resources are tight. PriorityClasses affect preemption order; a pod with no PriorityClass schedules normally when resources fit.
  3. The scheduler compares the pod's CPU limit to node capacity; with no limit set it cannot schedule. Limits are enforced by the kubelet/cgroups at runtime; scheduling only looks at requests.
  4. The scheduler filters nodes by the pod's CPU request against node allocatable, and no node has 2 allocatable. Filtering uses requests against allocatable capacity (capacity minus system reservations), not limits and not raw capacity.
In short

The scheduler places a pod by its CPU request against the node's allocatable CPU, not by its limit.

Why

The scheduler's filtering phase removes every node whose allocatable resources cannot satisfy the pod's requests. Allocatable is capacity minus kube- and system-reserved amounts, so a "4-core" node may only offer 3800m. Limits play no part in placement; they are enforced later by the kubelet via cgroups. The FailedScheduling event on the pod lists how many nodes failed each filter ("0/3 nodes are available: 3 Insufficient cpu").

The common mistake

Saying the pod has no CPU limit, so it cannot be placed. Limits play no part in placement at all.

Read the docs

2 Answer out loud

How does the scheduler decide where a pod runs, and what are the two most common reasons a pod stays Pending in a healthy cluster? Two to five sentences; I am timing you.

In short

A strong answer says filtering uses requests against allocatable, then scoring picks a node, and Pending means requests or constraints fit no node.

What a strong answer does
  • mechanism: Names filtering (predicates) then scoring, binding, and that requests (not limits) against allocatable drive fit; mentions at least one constraint family (taints, affinity, spread).
  • pending causes: Insufficient requests vs allocatable, unsatisfiable constraints (selector/affinity/taint), and notes unbound PVCs or preemption as a third.
  • communication: Leads with the mechanism, then the causes, no filler, correct vocabulary used precisely.
Why

Interviewers listen for requests vs allocatable, the phase structure, and whether you reach for the event as evidence. Saying "limits" where you mean "requests" is the single most common tell that someone has used Kubernetes without reading how it places work.

The common mistake

Saying 'limits' when you mean 'requests', or reaching for kubectl top. The scheduler never looks at usage or at limits; it sums requests against allocatable.

3 Read the output

What does kubectl get pod show for this pod one minute after creation, and what will the FailedScheduling event say?

$ kubectl get nodes -L disktype
NAME     STATUS   ROLES    AGE   VERSION   DISKTYPE
node-a   Ready    <none>   40d   v1.30.2   hdd
node-b   Ready    <none>   40d   v1.30.2   hdd
node-c   Ready    <none>   40d   v1.30.2   ssd

$ kubectl describe node node-c | grep -A2 Taints
Taints:             dedicated=batch:NoSchedule

# pod spec (excerpt)
spec:
  nodeSelector:
    disktype: ssd
  containers: [...]
  1. Running on node-c — nodeSelector takes precedence over taints. Taints and selectors are independent filters; a pod must pass all of them.
  2. Evicted — the taint evicts pods that do not tolerate it. NoSchedule prevents placement; only NoExecute evicts running pods.
  3. Pending — '0/3 nodes are available: 1 node(s) had untolerated taint {dedicated: batch}, 2 node(s) didn't match Pod's node affinity/selector.' nodeSelector eliminates node-a and node-b; node-c matches the selector but carries a NoSchedule taint the pod does not tolerate.
  4. Running on node-a or node-b — the scheduler falls back to any node when the selector cannot be satisfied. nodeSelector is a hard requirement (unlike preferredDuringScheduling affinity).
In short

The pod stays Pending because node-c has a taint the pod does not tolerate and the other two nodes fail the selector.

Why

Read the FailedScheduling event as a ledger of filters: each clause counts nodes eliminated by one filter. nodeSelector is a hard filter, taints are a separate hard filter, and a pod must survive all of them. NoSchedule never evicts; NoExecute does, honoring tolerationSeconds.

4 Find what's broken

The cluster has two worker nodes. Only two replicas ever become Ready. Which line is responsible, and what would you change?

apiVersion: apps/v1
kind: Deployment
metadata:
  name: api
spec:
  replicas: 3
  selector:
    matchLabels: { app: api }
  template:
    metadata:
      labels: { app: api }
    spec:
      affinity:
        podAntiAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            - labelSelector:
                matchLabels: { app: api }
              topologyKey: kubernetes.io/hostname
      tolerations:
        - key: dedicated
          operator: Equal
          value: batch
          effect: NoSchedule
      containers:
        - name: api
          image: registry.example.com/api:1.4.2
          resources:
            requests: { cpu: "1", memory: 512Mi }
            limits:   { cpu: "1", memory: 512Mi }
In short

The required anti-affinity rule on hostname blocks a third pod on a two-node cluster, so use a soft rule or a spread constraint.

What's broken
  • Line 15: Required pod anti-affinity on hostname with 3 replicas and 2 nodes means the third replica has no node it is allowed on.
Why

requiredDuringScheduling anti-affinity is a hard filter: with topologyKey: kubernetes.io/hostname it forbids two app: api pods on one node, so replicas can never exceed node count. The toleration (line 19) is harmless — tolerating a taint does not restrict placement. Equal requests and limits (line 27) give Guaranteed QoS and are fine. The interview signal here is knowing that "required" means never schedule otherwise, and reaching for topology spread constraints as the modern tool.

5 Scenario: what do you do next?

It is 09:20. A deploy of the checkout service went out at 09:10. Alerts: checkout availability SLO burn rate 14x. kubectl get pods -n shop shows 6/10 checkout pods Running, 4 Pending. Nodes are all Ready. Cluster autoscaler is enabled.

Step 1. You have one command before the incident commander asks for a status. What do you run first?

  1. kubectl rollout undo deployment/checkout -n shop Mitigation may be right, but you do not yet know the deploy caused it; and 6 pods are serving. Read the event first — it takes ten seconds.
  2. kubectl describe pod -n shop and read the Events The FailedScheduling event tells you which filter eliminated which nodes — the fastest single source of truth.
  3. Restart the scheduler pod in kube-system Nothing yet suggests the scheduler is unhealthy; Pending pods with events are the scheduler working correctly.
  4. kubectl top nodes Utilization is not what the scheduler looks at; requests vs allocatable are. top can look fine while requests are exhausted.

Step 2. The event reads: '0/12 nodes are available: 12 Insufficient memory. preemption: 0/12 nodes are available: 12 No preemption victims found for incoming pod.' The new image bumped requests.memory from 1Gi to 6Gi. Autoscaler logs show 'max node group size reached'. What is your mitigation?

  1. Delete the 4 Pending pods so the Deployment recreates them. They will be recreated with the same request and stay Pending.
  2. Roll back the Deployment to the previous revision now; investigate the memory request afterwards. Mitigate first: the previous revision fit. Root cause (why 6Gi, whether it is needed) can wait until the SLO stops burning.
  3. Add a PriorityClass to checkout so it preempts other workloads. The event already says no preemption victims fit; and preempting other services during an incident spreads the outage.
  4. Raise the autoscaler max node group size. Possible, but slower (node boot), costs money, and may not be allowed on the spot. Rollback restores capacity in seconds.

Step 3. Rollback completes; 10/10 Ready, burn rate falling. The developer says the 6Gi request was a mistake — they meant 6Gi limit. For the postmortem, what is the systemic fix you propose?

  1. Tell developers to be more careful with resources. Blame-shaped and unenforceable; postmortems propose mechanisms, not intentions.
  2. Double the cluster size. Expensive and does not stop the next 6Gi typo from being 60Gi.
  3. A pre-merge check (policy or CI) that flags request changes above a threshold and requires a capacity note; plus a LimitRange/ResourceQuota in the namespace. Prevents recurrence at the source; quota makes the failure visible at apply time, not at 09:20.
In short

Read the Pending pod's events first, roll back to restore capacity, and then add a check that catches big request changes.

Why

The shape interviewers score: read the scheduler's event before acting; mitigate (rollback) before root-causing; propose a mechanism, not a reminder. Insufficient memory in filtering is about requests vs allocatable, which is why kubectl top (actual usage) would have misled you.

6 Design round

You run a 40-node cluster shared by latency-sensitive API services and nightly batch jobs. Batch jobs keep starving API pods of capacity during the night, and API autoscaling events fail. Design the scheduling and capacity policy that stops this, and say how you would prove it works.

  • No new clusters; one cluster is a hard constraint from finance.
  • Batch must still finish by 06:00.
In short

A strong answer gives API pods a higher PriorityClass than batch, caps batch with a quota, and makes batch safe to preempt.

A strong answer covers
  • Separates workloads with PriorityClasses (API > batch) so API pods can preempt batch.
  • Uses taints/tolerations or node pools to reserve a floor of capacity for API, or a ResourceQuota per namespace to cap batch.
  • Makes batch preemptible/restartable (Jobs with retries, checkpointing) so preemption is safe.
  • Sets PodDisruptionBudgets on API and discusses their interaction with preemption.
  • States how to verify: a load test at night, scheduler metrics (pending pods, preemption count), SLO burn during batch windows.
  • Names a tradeoff explicitly (batch tail latency vs API headroom, cost of reserved floor).
What a strong answer does
  • design quality: Priority + preemption, capacity floor or quota, preemption-safe batch, PDBs, and verification plan.
  • tradeoffs: Two or more tradeoffs with a decision made.
  • communication: Requirements, numbers or constraints restated, design, failure modes, verification, decision.
Why

The scheduling primitives interviewers expect: PriorityClasses and preemption, quotas or dedicated pools for a floor, PDBs, and the realization that preemption is only acceptable if the preempted work is designed to be interrupted.

7 Quick recall

Follow-up: which taint effect actually evicts pods that are already running?

In short

NoExecute is the taint effect that evicts running pods that do not tolerate it.

Accepted

NoExecute · noexecute · no execute

Why

NoSchedule and PreferNoSchedule only affect placement; NoExecute evicts running pods, optionally after tolerationSeconds.

8 Pick the strongest answer

A high-priority pod is Pending. The scheduler finds a node where evicting two low-priority pods would make room, but one of those pods is protected by a PodDisruptionBudget that the eviction would violate. What does the scheduler do?

  1. The pod stays Pending forever; PDBs are never violated by the scheduler. PDBs are absolute for voluntary disruptions via the Eviction API (drains), not for scheduler preemption.
  2. The low-priority pods are throttled instead of evicted. Preemption deletes pods; there is no throttling mechanism in scheduling.
  3. The PDB is ignored entirely; preemption only considers priority. The scheduler does consider PDBs when choosing victims; it just cannot always satisfy them.
  4. The scheduler prefers nodes where preemption does not violate a PDB; if no such node exists it may still preempt, because PDB support in preemption is best-effort. Preemption tries to honor PDBs but does not guarantee it; this surprises many candidates.
In short

The scheduler tries to keep PDBs intact during preemption, but it may still break one because PDB support in preemption is best-effort.

Why

PodDisruptionBudgets are enforced by the Eviction API used by kubectl drain and the cluster autoscaler. The scheduler's preemption logic respects them on a best-effort basis: it prefers victims whose eviction keeps PDBs intact, but will violate a PDB if that is the only way to place the higher-priority pod.

Next lesson Workload controllers: StatefulSets, DaemonSets, Jobs and CronJobs
Drill · Scheduler
0:00

Loading…