Scheduler Decision Cycle
A new Pod waits in Pending for a moment and then turns up on one Node out of many, though nobody told it where to go. How is that one Node chosen over the rest, and what rules some Nodes out first?
Play the animation 5 steps, animated, plays on a computer or a tablet
Scheduler Decision Cycle, step by step
-
A new Pod my-app-7d4-x2k9p reaches the Scheduler on its watch with spec.nodeName empty. Until that field is set, no Kubelet will start this Pod. The Scheduler pops it off the active queue and runs one scheduling cycle for it.
Play from step 1 -
Filter plugins test each Node against the Pod requirements, and in a large cluster they stop once enough Nodes fit. Node-1 carries a NoSchedule taint the Pod does not tolerate, and Node-2 lacks the requested memory. Both are dropped before scoring.
Play from step 2 -
Score plugins like NodeResourcesFit, NodeAffinity and PodTopologySpread rate the surviving Nodes. Each scores a Node 0 to 100, and their weighted sum ranks the Nodes. Node-3 sums to 78, Node-4 to 92. See the Pod Priority and Preemption card.
Play from step 3 -
Highest score wins, a tie is broken at random. The Scheduler assumes the Pod on Node-4 and counts its requests for the next Pod. Then it POSTs a Binding to the binding subresource, not a Pod patch. The API sets the Pod spec.nodeName in ETCD, and ETCD acks the Raft commit.
Play from step 4 -
The Kubelet on Node-4 watches /api/v1/pods?fieldSelector=spec.nodeName=Node-4, so this write reaches it as an ADDED event. Then the Kubelet pulls the image and starts the containers, and the Pod goes from Pending to Running.
Play from step 5