I'm trying to understand how kubelet watches changes from api server. I found a note over syncLoop
function
// 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.
Does kubelet pulls events or api server pushes events to kubelet?
CodePudding user response:
The kubelet is the primary "node agent" that runs on each node. 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.
On the Kubelet polling: The API server pushes events to kubelet. Actually, the API server supports a "watch" 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.
Kubelet can obtain Pod configurations required by the local node in multiple ways. The most important way is Apiserver. As indicated in the comments, the syncLoop 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, syncLoop only encapsulates syncLoopIteration, while the synchronization operation is carried out by syncLoopIteration.
Refer Understanding the Kubelet Core Execution Frame for more information.
CodePudding user response:
Following K8s documentation has few details