<p>I'm trying to understand how kubelet watches changes from api server. I found a note over <code>syncLoop</code> function</p>
<pre><code>// kubernetes/pkg/kubelet/kubelet.go
// syncLoop is the main loop for processing changes. It watches for changes from
// three channels (file, apiserver, and http) and creates a union of them. For
// any new change seen, will run a sync against desired state and running state. If
// no changes are seen to the configuration, will synchronize the last known desired
// state every sync-frequency seconds. Never returns.
</code></pre>
<p>Does kubelet pulls events or api server pushes events to kubelet?</p>

zeromsi
<p>The kubelet is <strong>the primary &quot;node agent&quot; that runs on each node</strong>. It can register the node with the apiserver using one of: the hostname; a flag to override the hostname; or specific logic for a cloud provider.</p>
<p>On the Kubelet polling: The API server pushes events to kubelet. Actually, the API server supports 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>
<p>Kubelet can obtain Pod configurations required by the local node in multiple ways. The most important way is <strong>Apiserver</strong>. As indicated in the comments, the <strong>syncLoop</strong> function is the major cycle of Kubelet. This function listens on the updates, obtains the latest Pod configurations, and synchronizes the running state and desired state. In this way, all Pods on the local node can run in the expected states. Actually, <strong>syncLoop</strong> only encapsulates <strong>syncLoopIteration</strong>, while the synchronization operation is carried out by <strong>syncLoopIteration</strong>.</p>
<p>Refer <a href="https://dzone.com/articles/understanding-the-kubelet-core-execution-frame" rel="nofollow noreferrer">Understanding the Kubelet Core Execution Frame</a> for more information.</p>
