Basic principles of kubernetes daemonset

1 Overview

The agent process needs to run on each node or multiple nodes. At this time, it can be realized by using kuberntes daemonset. In practice, agents and network plug-ins for log collection are generally deployed through daemonset.

2) General principles

The controller of the daemonset will monitor the daemonset object, pod object, and node object of kuberntes. The changes of these monitored objects will trigger the syncLoop cycle to let the kubernetes cluster evolve toward the state described by the daemonset object.

3) Implementation details

The controller will perform the following 5 steps every time syncLoop

1) Get the current state map: This map describes the daemonset pod
nodename located at each node --> [daemonPod 1, daemonPod 2 …]

2) Traverse each node:
podsShouldBeOnNode(node, map, ds) --> get two lists (the specific process will be affected by the preselection algorithm of the scheduler):
a. A node name list (not empty, it means the node Need to create a new pod)
b. A list of pods to be deleted on the node.

3) Consistency in the number of pods: Actually create and delete pods:
summarize the list of node names and the list of pods to be deleted, and finally enter the two into a method to actually call the apiserver interface to create and delete pods, so that’s it Reach the desired state.

4)
Pod version consistency: Call rollingUpdate(), essentially by deleting some running pods and non-Running pods to achieve update

5) Update the status field of the daemonset object

4) Key methods

                                |-> dsc.getNodesToDaemonPods()  //获取当前状态
                                |
                                |
                  |-> manage -->|-> dsc.podsShouldBeOnNode() --> dsc.nodeShouldRunDaemonPod	//汇总需要创建的pod和待删除的Pod
                  |             |
                  |             |
syncDaemonSet --> |             |-> dsc.syncNodes  //Pod数量一致性
                  |
                  |-> rollingUpdate  //Pod版本一致性
                  |
                  |
                  |-> updateDaemonSetStatus  //更新daemonset对象的status字段

5) Reference

  1. https://www.jianshu.com/u/a004b422adae

Guess you like

Origin blog.csdn.net/nangonghen/article/details/103640299