Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

In-depth understanding of the core implementation framework of Kubelet

2025-01-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

Kubernetes has become the de facto standard for large-scale deployment of containerized applications in the cloud environment, and Kubelet, as the node agent in the Kubernetes cluster, that is, the guardian of the node, will be specifically responsible for the life cycle management of its node, ensuring that all container applications run smoothly as expected. It will first obtain the configuration information of the bod assigned to this node, and then call the underlying container runtime, such as Dokle or PouchContainer, according to the configuration information to create specific bodes and monitor them to ensure that all Pod on the node run as expected. In this paper, combined with the Kubelet source code, the above process is analyzed in detail.

Author Yao Zengzeng, alias Ritchie, senior contributor to Kubernetes community and maintainer of PouchContainer, the open source rich container engine of Ali Group, led and promoted the design and implementation of CRI interface in PouchContainer container technology. Engaged in cloud native related technology areas, focusing on container technology, orchestration technology, operating system kernel. At present, he is a graduate student in SEL Lab of Zhejiang University, and he personally advocates the concept of open source.

1. Get Pod configuration

Kubelet has several ways to obtain the configuration information of the pods that this node needs to run. The most important thing is the API server, which can also be obtained by specifying the directory of the configuration file and accessing a specific HTTP port. Kubelet will access them regularly to get updates on the Bode configuration and adjust the running status of the Pod located on this node in a timely manner.

A PodConfig object is created when Kubelet is initialized as follows:

/ / kubernetes/pkg/kubelet/config/config.go

Type PodConfig struct {

Pods * podStorage

Mux * config.Mux

/ / the channel of denormalized changes passed to listeners

Updates chan kubetypes.PodUpdate

...

}

PodConfig is essentially a multiplexer of Pod configuration information. The included mux monitors the sources of various Pod configuration information, including apiserver,file and http, and periodically synchronizes the current Pod configuration status of each source. In pods, the Pod configuration status of each source at the time of the last synchronization is cached. After mux compares the two, you can get the Pod with a change in configuration. Then, it classifies different Pod according to the type of change, and each type of Pod is injected into a PodUpdate structure:

/ / kubernetes/pkg/kubelet/types/pod_update.go

Type PodUpdate struct {

Pods [] * v1.Pod

Op PodOperation

Source string

}

The Op field defines the Pod change type described above. For example, its value can be ADD or REMOVE, indicating a corresponding addition to the Pod defined in Pods. Finally, various types of PodUpdate are injected into PodConfig's updates. Therefore, as long as we monitor the updates channel, we can get all the updated information about the Pod of this node.

two。 Synchronize Pod

When the Kubelet initialization is complete, the syncLoop function as shown below will eventually be called:

/ / 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.

Func (kl * Kubelet) syncLoop (updates

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 277

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report