How Kubernetes decides where pods run

ExplainedKubernetesDevOps, Hands OnBy Cloud Hands On

The scheduler's two steps, and the labels, affinities, taints and spreads you use to steer it.

When you create a pod, it starts Pending with no node. The scheduler picks one in two steps. Filtering removes nodes that can't take it: not enough free CPU or memory for its requests, a taint it doesn't tolerate, a required affinity it doesn't meet, a volume in another zone. Scoring ranks the rest, preferring spread-out pods, preferred affinities and balanced use. The kubelet on the winning node then starts the containers.

If no node passes filtering, the pod stays Pending and an event says why, for example 0/3 nodes are available: 1 node(s) had untolerated taint, 2 Insufficient memory. That message is the first thing to read when pods won't schedule.

Your tools: nodeSelector and node affinity pull pods to labelled nodes; taints and tolerations push pods away from nodes; pod affinity and anti-affinity place pods near or away from other pods; topology spread constraints balance copies across nodes and zones; priority classes let important pods evict less important ones when space is short.

Cost. Free to learn on a local kind cluster.

Use it when

How it works

Requests
The scheduler only counts requests, not real use, when deciding if a pod fits.
Filter then score
Rule out nodes that can't take the pod, then rank the rest.
Pull and push
Affinity pulls pods to nodes; taints push them away unless tolerated.
Spread
Anti-affinity and topology spread keep copies apart.
Priority
Higher-priority pods can preempt lower ones when the cluster is full.

Options

nodeSelector
Simplest: an exact label match.
Node affinity
Richer rules, required or preferred.
Taints and tolerations
Reserve nodes for certain pods.
Topology spread
Even spread across failure domains.

Example. Tollmere Logistics' route-planning pods sat Pending after a release raised their memory request to 6Gi on nodes with 4Gi free. The event said Insufficient memory; they added a larger node pool and a node affinity so the planner runs there.

Don't confuse it with

Cluster autoscaler
Adds nodes when pods are Pending for lack of room; the scheduler only places pods on nodes that exist.
Resource quotas
Limit how much a namespace may request in total; they don't choose nodes.

Words to know

Pending
A pod that hasn't been given a node yet.
Filtering
The scheduler step that removes nodes a pod can't run on.
Preemption
Evicting lower-priority pods to make room for a higher-priority one.

Where to look

  1. kubectl describe pod
  2. kubectl get events

Practise it

Read it in the guide, next to the tasks and labs.

Open in DevOps, Hands On

Keep going