k8s 02: How kubelet works

I found it quite useful to make a kubernetes cluster from scratch, and check the outcome step by step. By doing so, I can see each component role very clearly.

For this purpose, I mainly followed excellent kubernetes how to from Kamal Marhabi’s blog.

First of all, I start exploring kubelet, which acts like a site supervisor of a pod.

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.

So we can make a pod running if we spin up kubelet. It can be illustrated as follows:

Here’s step by step guide:

Prepare for container runtime

1. Install docker


2. Confirm if it’s installed. You can run example container by running

#docker run hello-world

I have running container runtime now.

Prepare for kubelet

1. Install kubelet

kubelet can be installed via apt if you are using Ubuntu. Follow official document to install kubelet.

Now, kubelet is installed. But it’s not ready to serve yet.

2. Configure kubelet

Kubelet, as a supervisor of the pod, it receives a request from various ways. As depicted previously, kubelet receives requests usually from apiserver in complete kubernetes setup. But this time, the apiserver is not ready, so there are following options to interact with kubelet without apiserver.

– File … tell kubelet to check specific directory periodically for new manifest file. Change state if any changes in the directory.

– HTTP endpoint … tell kubelet to check specific URL periodically for new manifest file. Change state if any changes in the directory.

– HTTP server … it responds to some API requests for node/pod status

This time I tell kubelet to check local directory /work/manifests to manage pod.

Since I’m using systemd to start kubelet, I modify service file…

Now, kubelet is ready to serve for my request, which I’m just going to put a yaml file in /work/manifests directory.


Run a Pod

1. Create a test manifest in specified folder

Create a test pod manifest file. Refer official document for the elements. This example just run a simple nginx server.

That’s all I need to do.

Kubelet checks this directory every 20 seconds(by default) to see if there are any changes. And once it detects a new file, it creates a new pod.

I can ask kubelet for this pod status.

Or I can as well ask the container runtime directly

And finally I can confirm the nginx is serving on port80 as specified in the manifest file.

Network configuration of Kubernetes and docker is very confusing, and it requires third party integration(it works ok with basic deployment, but you need third party plugin to utilize full functionality of kubernetes). So I’m not going to write in detail here, but I will make a separate entries for this network topics.


That’s all. I just need to delete manifest file from the directory, and the pod will also be deleted.