Kubernetes 控制平面通信

Kubernetes Control Plane communication

本人在研究K8s架构,重点研究系统中pod spinning的流程

我在想how(即是谁发起的通信)和控制平面的不同组件相互通信时。

我关注了 Jérôme Petazzoni 在 LISA 2019 上的精彩演讲 (here) to understand the architecture of the control plane, and read the concepts on kubernetes.io.

但是,我仍然没有找到以下问题的答案:

  1. 每个节点的资源检查由谁发起,在documentation中写着:

Node objects track information about the Node's resource capacity: for example, the amount of memory available and the number of CPUs. Nodes that self-register report their capacity during registration. If you manually add a Node, then you need to set the node's capacity information when you add it.

但是,没有说明何时在 etcd 更新,以及谁发起定期更新(除了 heartbeat 更新节点)。

另外,调度器的缓存什么时候更新?

  1. 谁将新的待处理请求通知不同的组件?也就是说,controller-manager/scheduler “知道” 什么时候应该完成它的工作? kube-api-server 将每个请求作为清单写入 etcd,但这些组件并未直接连接到 etcd

这是否意味着 API-Server 需要将每个新请求通知每个组件?

我有很多可能的答案,但没有具体确认当前K8s架构中的真实过程。

回答您的问题:

每个节点的资源检查是谁发起的?

负责的组件是 "Node Status Manager",它是“SyncLoop” 的 sub-control 循环这是一个 kubelet agent 组件。

更详细的答案在这篇文章中:Kubernetes Deep Dive: Kubelet:

As you can see, the core of kubelet’s work is a control loop, namely: SyncLoop.

For example, the Node Status Manager is responsible for responding to changes in the status of the Node, and then collecting the status of the Node and reporting it to the APIServer through Heartbeat.

回答第二部分:

谁将新的待处理请求通知不同的组件?也就是说,controller-manager/scheduler "knows" 应该如何工作?

负责的组件是 Kubernetes' controllers and Scheduler itself. Good examples and explanations are in this article: What happens when ... Kubernetes edition!

基本上在 Kubernetes 验证请求(身份验证、授权、准入控制等)后,它会保存到数据存储区 (etcd),然后由 initializers which may perform some additional logic on the resource (not always), after that it's visible via kube-server. Main part that may interest you is Control loops 获取。他们不断检查数据存储中是否存在新请求,如果是,他们将继续进行。示例 - 当您部署新部署时:

  • Deployments controller 正在接受一个请求 - 它会意识到没有关联的 ReplicaSet 记录,它将 roll-out 新的
  • ReplicaSets controller,就像部署控制器一样,它会接受一个请求和 roll-out 新的 pods
  • Pods 已准备就绪,但处于待定状态 - 现在 Scheduler(就像以前的控制器一样,不断侦听来自数据存储的新请求 - 这是你问题的实际答案)将找到合适的节点并将 pod 调度到节点。现在,节点上的 kubelet 代理将创建一个新的 pod。

有关详细信息,我强烈建议阅读前面提到的文章 - What happens when ... Kubernetes edition!

这是否意味着 API-Server 需要将每个新请求通知每个组件?

它以不同的方式工作 - kube-apiserver 使请求可见,控制器(循环)正在检测新请求并开始处理它们。