Controlling pods kubelet vs. controller in control plane

3/9/2021

I'm a little confused, I've been ramping up on Kubernetes and I've been reading about all the different objects ReplicaSet, Deployment, Service, Pods etc.

In the documentation it mentions that the kubelet manages liveness and readiness checks which are defined in our ReplicaSet manifests.

Reference: https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/

If this is the case does the kubelet also manage the replicas? Or does that stay with the controller?

Or do I have it all wrong and it's the kubelet that is creating and managing all these resources on a pod?

Thanks in advance.

-- elyakshaver
kubernetes

2 Answers

3/9/2021

When starting your journey with Kubernetes it is important to understand its main components for both Control Planes and Worker Nodes.

Based on your question we will focus on two of them:

  1. kube-controller-manager:

Logically, each controller is a separate process, but to reduce complexity, they are all compiled into a single binary and run in a single process.

Some types of these controllers are:

  • Node controller: Responsible for noticing and responding when nodes go down.

  • Job controller: Watches for Job objects that represent one-off tasks, then creates Pods to run those tasks to completion.

  • Endpoints controller: Populates the Endpoints object (that is, joins Services & Pods).

  • Service Account & Token controllers: Create default accounts and API access tokens for new namespaces.

  1. kubelet:

An agent that runs on each node in the cluster. It makes sure that containers are running in a Pod.

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. The kubelet doesn't manage containers which were not created by Kubernetes.

So answering your question:

If this is the case does the kubelet also manage the replicas? Or does that stay with the controller?

No, replication can be managed by the Replication Controller, a ReplicaSet or a more recommended Deployment. Kubelet runs on Nodes and makes sure that the Pods are running according too their PodSpecs.

You can find synopsis for kubelet and kube-controller-manager in the linked docs.

EDIT:

There is one exception however in a form of Static Pods:

Static Pods are managed directly by the kubelet daemon on a specific node, without the API server observing them. Unlike Pods that are managed by the control plane (for example, a Deployment); instead, the kubelet watches each static Pod (and restarts it if it fails).

Note that it does not apply to multiple replicas.

-- WytrzymaƂy Wiktor
Source: StackOverflow

3/9/2021

Basically kubelet is called "node agent" that runs on each node. It get notified through kube apiserver, then it start the container through container runtime, it works in terms of Pod Spec. It ensures the containers described in the Pod Specs are running and healthy.

The flow of kubelet tasks is like: kube apiserver <--> kubelet <--> CRI

To ensure whether the pod is running healthy it uses liveness probe, if it gets an error it restarts the pod.

kubelet does not maintain replicas, replicas are maintained by replicaset. As k8s doc said: A ReplicaSet's purpose is to maintain a stable set of replica Pods running at any given time. As such, it is often used to guarantee the availability of a specified number of identical Pods.

See more of ReplicaSet

For more info you can see: kubelet

-- Sahadat Hossain
Source: StackOverflow