How a Pod Gets a Node
How a Pod Gets a Node
A pod with no spec.nodeName waits in the scheduling queue. The leader-elected scheduler processes it in two phases:
- Filtering — discard nodes that break hard constraints: insufficient
resources.requestscpu or memory, node condition pressure or unschedulable taints, selector/affinity mismatches, taints without a matching toleration. - Scoring — rank survivors using heuristics like PodTopologySpread, NodeResourcesFit, and image locality.
The winner is written into spec.nodeName, which ends scheduling for that pod's lifetime. Scheduling is edge-triggered: when capacity frees or a node appears, queued pods are reconsidered rather than the whole cluster being re-scored.
Influencing Placement
Influencing Placement
Three levers, from softest to hardest:
nodeSelector:
disktype: ssd
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- { key: topology.kubernetes.io/zone, operator: NotIn, values: [zone-a] }
tolerations:
- { key: dedicated, operator: Equal, value: batch, effect: NoSchedule }
Reserve capacity with resources.requests — a pod asking cpu: 2 cannot land where allocatable is 1.5. Soft preferences use preferredDuringSchedulingIgnoredDuringExecution with weights when you want a nudge, not a rule.
Pending Pods and Controller Loops
Pending Pods and Controller Loops
Pitfall 1 — reading Pending without events. kubectl describe pod shows the scheduler's exact verdict: "0/3 nodes are available: 3 Insufficient cpu." Fix requests, add capacity, or relax constraints — hand-setting nodeName bypasses the scheduler entirely and breaks future rescheduling.
Pitfall 2 — blaming the scheduler for controller work. Replication, rollouts, and node lifecycle belong to controller-manager loops watching the API; the scheduler only binds pods once.
Interview-ready: explain filter, score, bind, then a scenario — a pod stuck Pending after autoscaling usually means label or taint mismatch, not missing nodes. Mention leader election and that scheduler decisions appear as Events on the pod.
Quiz
1. Which scheduler phase discards nodes that cannot fit the pod?
2. How does a pod become assigned to a node?
3. A Pending pod reports "Insufficient memory". What should you change first?
Flashcards
Question
Scheduler phases
Click to reveal answer
Answer
Filter nodes by hard constraints, score survivors, then bind the pod by writing spec.nodeName.
Question
controller-manager
Click to reveal answer
Answer
Runs reconciliation loops: Deployment, ReplicaSet, Node, Job, Service endpoints, and more.
Question
nodeAffinity vs taints
Click to reveal answer
Answer
Affinity attracts pods to labeled nodes; taints repel pods that lack matching tolerations.
Question
Where placement failures are explained
Click to reveal answer
Answer
kubectl describe pod — Events show the scheduler's filtering reasons.
Revision Notes
Key Takeaways
- 1. Requests and constraints filter first; heuristics only break ties
- 2. The scheduler binds once; controllers own everything after
- 3. Pending pods are diagnosed through events, not speculation
Interview Tips
- • Say filter → score → bind and name one predicate and one priority function
- • For autoscaling scenarios, check labels and taints before assuming capacity is missing
Cheat Sheet
Filter (requests, taints, affinity) → score (spread, fit) → bind (spec.nodeName). Placement errors live in describe pod Events; controllers—not the scheduler—maintain replicas.