Kubernetes - API Server / etcd 如何知道每个 Pod 的状态?

day*_*oli 2 kubernetes kubelet kube-apiserver

我知道它kubelet负责获取 PodSpecs(通常来自 API 服务器)并运行 Pod。

Kubernetes 组件 > 节点组件 > kubelet

“kubelet 采用一组通过各种机制提供的 PodSpecs,并确保这些 PodSpecs 中描述的容器正在运行和健康。”

但是 API Server 如何跟踪每个 Pod 的状态(例如运行/失败)?是否kubelet向 API 服务器发送常规请求?还是 API Server 会kubelet定期轮询?还是其他什么机制?

sur*_*ren 7

kubelet does everything on the node. A typical process to create a pod would be the following:

  1. By default, kubelet is hooked up to api-server through this "thing" called watch. It's a sort of pub/sub. So kubelet would be subscribed to "create pod" event, and api-server would notify it when a pod needs to be created.
  2. kubelet would get the container runtime (docker or rkt), along with other pod specifications, and would create the pod.

注意:这里涉及更多组件,例如调度程序和控制器管理器(在您的帖子中提到了各种机制),但我将跳过它们。

  1. kubelet 将进行必要的活跃度和就绪度探测,并将状态报告给 api-server。说成功!
  2. api-server 将更新 etcd(通过添加 pod 的元数据)以跟踪集群中发生的事情。

此时 kubelet 将负责这个 pod。如果 pod 宕机,kubelet 会报告 api-server,api-server 会发出杀死 pod 的命令,将启动一个新的 pod,并再次更新 etcd 服务器。

需要指出的一件事是,k8s 中的所有组件都直接与 api-server 通信。因此,控制器管理器或调度器不会告诉 kubelet 要做什么。相反,他们对 api-server 说,api-server 对 kubelet 说。