In short, Kublai? The main function of is to get the expected status of pod/container on the node (what container to run, how many copies to run, how to configure the network or storage, etc.). ) call the corresponding container platform interface from somewhere regularly to achieve this state.
In addition to this core function, kubelet has many other functions:
* Report the current node status to apiserver regularly for scheduling.
*? Clean up the mirrors and containers to ensure that the mirrors on the nodes do not occupy all the disk space, and the exiting containers do not occupy too many resources.
* Run the HTTP server to provide node and pod information, including debugging information (if in debugging mode).
* Wait ...
In the cluster state, kubelet will read the information from the master node, but in fact, kubelet can also obtain the pod information of the node from other places. Currently, kubelet supports three data sources:
*? Local file
*? Get information from addresses on the network through url.
*? Apisherver: Get information from the kubernetes master node.
As far as managed objects are concerned, kubelet currently supports docker and rkt, and uses docker by default.
Pod management
In the design of kubernetes, the most basic management unit is pod, not container. Pod is a layer of packaging of kubernetes on containers, which consists of a group of one or more containers running on the same host. If a container is compared to a process on a traditional machine (it can perform tasks and provide some external functions), then a pod can be compared to a traditional host: it contains multiple containers and provides them with some resources.
The reason why we take pains to provide this layer of encapsulation is mainly because the recommended usage of the container is that only one process runs in it. Generally speaking, an application is composed of multiple components.
The biggest feature and benefit of all containers in pod is that * * * enjoys a lot of resources, such as cyberspace. All containers under pod * * * enjoy network and port space, that is, they can pass through? Local host? Access and communication, the way of external communication is the same, which saves a lot of trouble in container communication.
In addition to the network, the volumes defined in the pod can also be mounted in multiple containers to achieve * * *.
Finally, the resource restrictions (such as CPU and memory) defined in pod are also shared by all containers.
Container health inspection
After creating the container, kubelet should also check whether the container is working properly. If the container is not running correctly, it should be handled according to the set restart strategy. There are three main ways to check whether the container is healthy: executing the command, and integrating the es project into kubelet without additional configuration. By default, you can use? localhost:4 194? See the management interface of cAdvisor for the address.
In addition to the CPU, memory, storage and network used by the system, cAdvisor also records the above resources used by each container.
entry program
cmd/kublet/kubelet.go? -& gt; ? chief method
1. Create kubeletFlags data structure (corresponding to kubelet command line parameters);
2. Create a library to delete the configuration data structure;
3. Create a kubeletServer data structure, including kubeletFlags and kubeletConfigration;;
4. Start the kubelet configuration controller, and start the cyclic synchronization of configuration and status;
5. Create kubeletDeps data structure;
initiator
cmd/kubelet/app/server.go? -& gt; ? Operation method
1. judge whether kubelet runs in stand-alone mode;
2. create objects kubeClient and evnetClient to communicate with apiserver. HeartbeatClient, externalkubeClient, ContainerManager and set up OOM.
3.? Call Ron Cooper Brett. Run kubelet, this function will start goroutine to run all the time, and this is where the kubelet core function is executed.