Why kubelet runs as a system service in Kubernetes cluster and not as pod/daemonsets?

This article was originally published by the author on Medium. We are republishing it here.

Many people have this question in mind when they deploy Kubernetes cluster. While I was delivering a training on k8s, one of the participants asked this question, but he asked it a bit early when I was explaining each component of k8s cluster i.e. api-server, controller, scheduler, etcd, kube-proxy, kube-dns and kubelet etc.

With the promise to answer him after explaining how we can create pods in k8s cluster and how each and every component works to deploy a pod on the scheduled node I continued. That moment a thought struck me and I thought to write about this to answer everyone facing same.


Download our ebook – A Deep-Dive On Kubernetes For Edge, focuses on current scenarios of adoption of Kubernetes for edge use cases, latest Kubernetes + edge case studies, deployment approaches, commercial solutions and efforts by open communities.


Above mentioned k8s components can run as system service or pods in k8s cluster. When we deploy a cluster using “kubeadm init” all these components except kubelet runs as pod and only kubelet runs as system service, so the question arises… WHY?

Okay, so to understand the reason we need to understand how a pod is deployed in k8s cluster, but since this blog is not to discuss this in detail (I am planning to write an entire series on “Kubernetes” and “Networking and container security using CNI in k8s cluster” stay tuned for that) hence for now let’s discuss the only reason for kubelet to run as system service.

I am assuming that you have some basic knowledge about k8s and how it works. Let’s take a quick recap about the events while deploying a pod is below:

  1. When you deploy a pod in k8s cluster API serverreceives REST request from client i.e. kubectl in most cases, you can write your own client as well using “k8s.io/client-go/Kubernetes” package.
  2. Apiserver forwards this request for authentication/authorization (and some additional module like mutating admission controller/webhook, schema validation, validation admission controller, etc.) and store resource into etcd the centralize datastore in Kubernetes.
  3. Once resource (here resource means Pod) gets stored in etcd, scheduler (another pod running in a cluster) gets a notification (How? all control plane component keeps watch on API server, hence they get notification for the events they subscribe) and it schedule the pod on one of the suitable nodes in the cluster.
  4. Once scheduler assigns the node to the pod now etcd have updated pod spec with node assign. hence API server sent an event to kubelet running on that particular node.
  5. And now the answer starts of the question asked i.e. “why kubelet runs as a system service?”. Kubelet receives the pod details and create a sandbox container and attach the volume to it to run an application container. It also calls IPAM and CNI to provide networking to this sandbox container. And then it downloads the docker image mentioned in the pod spec and then runs a container inside the pod. So, in a simple term, kubelet is the creator (one who creates) of pod on a specific node, so how can it be a pod. Let’s make it clearer if you still are dicey about this.

Whenever you deploy k8s cluster using “kubeadm init” on master node, the very first thing kubeadm spawn is kubelet as a systemd service see the below code present in k8s repo.:

From the above code, kubeadm first call GetInitSystem() on line 28 to get InitSystem for the current system and then it checks whether kubelet is running or not on line 34 by method ServiceExists(“kubelet”) and then it calls ServiceRestart(“kubelet”) on line 40 to start kubelet as systemd service.

Once kubelet is running, then kubeadm deploy other control plane component (apiserver, etcd, kube-proxy, scheduler, etc.) as pod.

In the same way, when you run “kubeadm join” on a worker node, it spawns kubelet on the worker node also.

Hope now you can understand why we cannot run kubelet as pod/daemonsets in k8s cluster and it runs as a system service.

If you have some more thoughts or have some observations on the details I shared above, please add the same in the comment section.

If you are new to k8s or container then read my other small article on the same: https://link.medium.com/iblDswkzzZ

 
Share:

Related Posts

A Deep Dive into 5G Service-Based Architecture (SBA)

5G technology roll out signifies an immense revenue opportunity for telecom industry.

Share:
Technical Documentation

Technical Documentation Review and Tips

Technical reviews are vital for effective and quality documentation. To make this happen, have documentation and its reviews listed as one of the deliverables – just like development or testing. This will place priority on the process, and ensure everyone involved understands the importance of proper and thorough reviews.

Share:
Technology Trends 2024

Technology Trends 2024- The CXO perspective

In the rapidly evolving landscape of 2024, technology trends are reshaping industries and redefining business strategies. From the C-suite perspective, executives are navigating a dynamic environment where artificial intelligence, augmented reality, and blockchain are not just buzzwords but integral components of transformative business models. The Chief Experience Officers (CXOs) are at the forefront, leveraging cutting-edge technologies to enhance customer experiences, streamline operations, and drive innovation. This blog delves into the strategic insights and perspectives of CXOs as they navigate the ever-changing tech terrain, exploring how these leaders are shaping the future of their organizations in the era of 2024’s technological evolution.

Share:
Technology Trends 2024

The Winds of Technology Blowing into 2024

As 2023 draws to a close, the digital landscape is poised for a seismic shift in 2024. Generative Artificial Intelligence (Gen AI) continues its integrative streak, disrupting industries from B2B to healthcare. Networking trends emphasize simplicity, while the synergy of cloud and edge computing with Gen AI promises real-time workflows. Quantum computing, cybersecurity, intelligent automation, and sustainable technology are key players, reshaping the technological fabric. Join us as we navigate the transformative currents of 2024, unraveling the impact on enterprises in our forthcoming article. Stay tuned for the tech evolution ahead!

Share:
Generative AI Shaping Future Industries

[Infoblog] Generative AI Shaping Future Industries

Generative AI is at the forefront of innovation, harnessing the power of machine learning algorithms to create new and original content, from images and music to entire virtual environments. This infographic depicts how Gen AI is evolving industries and shaping its future.

Share:

Enhancing vCenter Capabilities with VMware vCenter Plugins: A Deep Dive

 vCenter Server is one of the most powerful tools in VMware’s product portfolio, enabling efficient management of virtualized environments. One of the most used features in vCenter is the vCenter plugin, which extends the capabilities by providing custom features such as 3rd Party system discovery, and provisioning, providing a unified view, allowing administrators to manage vSphere, and 3rd Party systems seamlessly.

Share: