<p>I'm trying to get a better view 'under the hood' of how the Kubernetes Pod scheduling and creation process works, with respect to the interaction between <code>kubelet</code> and <code>kube-apiserver</code>.</p>
<p>I understand that the Kubernetes scheduler chooses a node to allocate a new pod to and notifies the API server of this. However, I am unclear how the API server notifies the <code>kubelet</code> on the node in question to start the pod. Is there a polling process within <code>kubelet</code> that queries the API server for changes? Or is there an event listener / call-back type interaction?</p>
<p>If anyone knows the answer or could point me in the direction of some documentation that would be greatly appreciated!</p>

tDickinson
<p>Alibaba had a <a href="https://www.alibabacloud.com/blog/a-brief-analysis-on-the-implementation-of-the-kubernetes-scheduler_595083" rel="nofollow noreferrer">really insightful blog post on the inner workings of the scheduler</a>. From the blog:</p>
<hr />
<p>The scheduler basically works like this:</p>
<ul>
<li>The scheduler maintains a scheduled podQueue and listens to the APIServer.</li>
<li>When we create a Pod, we first write Pod metadata to etcd through the APIServer.</li>
<li>The scheduler listens to the Pod status through Informer. When a new Pod is added, the Pod is added to the podQueue.</li>
<li>The main process continuously extracts Pods from the podQueue and assigns nodes to Pods.</li>
<li>The scheduling process consists of two steps: Filter matching nodes and prioritize these nodes based on Pod configuration (for example, by metrics like resource usage and affinity) to score nodes and select the node with the highest score.</li>
<li>After a node is assigned successfully, invoke the binding pod interface of the apiServer and set pod.Spec.NodeName to the assigned pod.</li>
<li>The kubelet on the node also listens to the ApiServer. If it finds that a new Pod is scheduled to that node, the local dockerDaemon is invoked to run the container.</li>
<li>If the scheduler fails to schedule a Pod, if priority and preemption is enabled, first a preemption attempt is made, Pods with low priority on the node are deleted and Pods to be scheduled will be scheduled to the node. If the preemption is not enabled or the preemption attempt fails, related information will be recorded in logs and Pods will be added to the end of the podQueue.</li>
</ul>
<hr />
<p>On the Kubelet polling: Actually, the API server support a &quot;watch&quot; mode, which uses the WebSocket protocol. In this way the Kubelet is notified of any change to Pods with the Hostname equal to the hostname of the Kubelet.</p>
