Kubernetes - How does API Server / etcd know the status of each Pod?

6/4/2018

I understand that kubelet is responsible for taking PodSpecs (usually from the API Server) and running the Pod.

Kubernetes Components > Node Components > kubelet

"The kubelet takes a set of PodSpecs that are provided through various mechanisms and ensures that the containers described in those PodSpecs are running and healthy."

But how does the API Server keep track of the status of each Pod (e.g. running / failed) ? Does kubelet send regular requests to the API Server? Or does the API Server poll kubelet regularly? Or some other mechanism?

-- dayuloli
kube-apiserver
kubelet
kubernetes

1 Answer

6/4/2018

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.

Note: There are more components involved here, like scheduler and controller manager (mentioned in your post as various mechanisms), but I will skip them.

  1. kubelet will make the necessary liveness and readiness probes and report back to api-server the status. Say success!
  2. api-server will update etcd (by adding the metadata of the pod) to keep the track of what is going on in the cluster.

At this point kubelet will be in charge of this pod. If the pod goes down, kubelet will report api-server, api-server will give the order to kill the pod, will spin up a new one, and again will update etcd server.

One thing to point out is that all components in k8s talk to api-server directly. So, controller manager or scheduler do not say kubelet what to do. Rather they say it to api-server, and api-server to kubelet.

-- suren
Source: StackOverflow