Setting up Kubernetes in your local — System Design (part 4)

Chetan Dwarkani
6 min readJan 19, 2022

So we have discussed basics about how to develop a simple hello world API service, set up a simple load balancer in our system, and dockerize the project on our previous blogs. I am attaching the link for your reference below. It would be good to know the below concepts before you start working on Kubernetes

  1. System Design Overall -System Design (part 1)
  2. Setting up Load Balancer -System Design (part 2)
  3. Setting up Docker and debugging inside the Docker container — System Design (part 3)

In this blog we are going to setup Kubernetes in order to manage our docker containers. Please watch the below video which explains everything in this blog in a clear manner if you do not feel like reading through the text

What’s Kubernetes?

Kubernetes is a container orchestration tool that helps you manage and scale your containers. It is an amazing framework that runs with no downtime and helps you to simplify the process to observe and manage downtime of your services and also to maintain replicas to restore it on the same state.

So here’s the Kubernetes architecture

As you can see in the image, everything in Kubernetes is inside a cluster and there can be multiple clusters as well. A cluster can have one or more master nodes whose primary responsibility is to manage all the worker nodes. So everything you wish inside a Kubernetes cluster environment is through a master node. We will set this master node up below to understand in a detailed manner.

Master nodes have the following components

API server: It’s responsible to do any kind of task. It holds API which helps to perform the tasks. Kube API server can be accessed via Kubectl and UI.

etcd: Backing store brain of Kubernetes cluster

Controller manager: The controller manager is responsible for the creation and maintenance of PODS, cluster, worker nodes. All requests of such goes to the controller manager.

Scheduler: Looks after which nodes are empty in cluster based on resource occupancy and helps further in allocating pods to a particular node.

Worker Node on the other hand has the below components:

Container Runtime: Owns an environment to run containers such as Docker.

Kubelet: It helps to manage and deploy pods inside the container.

pods: They form the smallest unit and holds the container

Apart from that we also have other components in Kubernetes such as

Services: They act as a load balancer and help in communication between pods or to distribute the data between the pods which have their replications.

ConfigMap: This stores the IP address mapping of pods so that one node can refer to that IP address rather than changing the IP address its referring to when the other pod goes down.

Secret Key: This is responsible for storing authenticated data information such as passwords globally. They can be accessed via pods.

Let’s roll down into implementation of Kubernetes in our local system and then we’ll look into all of these aspects as and then we code

Step 1: Enable Kubernetes in Docker Desktop

You can also use the option of using minikube and it’s a very simple tool to create a cluster in your local but if you have followed my previous blog then you will know that we were using Docker desktop to create containers. I will use the same for starting Kubernetes engine in my local as well

So simply open Docker desktop app → Select settings → Click on Kubernetes option in left list → Select Enable Kubernetes

and that’s it, you are done.

Docker engine will then create the whole setup of Kubernetes requirements and dependencies such as proxy, API servers etc., in a separate container and start the containers. Once you see the green color as in the image, it means your Kubernetes master node is ready. You can further see the status in the below section

Also, now, kubectl command will become accessible in your local system so you can type the below command to check what nodes has been created

kubectl get nodes

and you’ll find that a cluster has been created with the role of master.

Step 2: create deployments and run an image inside POD

Everything in Kubernetes is done via deployment. Deployment is like a wrapper for pods and containers in Kubernetes. The first step is to create a deployment for our image using the below kubectl command

Please make sure that you have build a image locally with 0.1 tag in order to run the above. If you are not aware on how to build an image then please refer my docker video to understand — here

Once you do the above, you need to type

kubectl get deployments

and you’ll find your deployment there

A pod will automatically get created which will hold the container running the image you specified in your deployment command above. To see the pods, please type

kubectl get pods

and you’ll see the pod list

Every pod has a YAML config file which is holding all info about your pods such as which image is the container of your pod running and all the other status of ports and pod replica factors etc., To see the config for the above pod which has the pod name — simple-node-backend-86f694b75b-l2sp2 , please type the below command

kubectl get pod simple-node-backend-86f694b75b-l2sp2 -o yaml > my-new-pod.yaml

Please check the below link which got generated in my local. You must find a similar file getting generated when you type the above command. You need to make sure that container port is correctly set as seen in the image.

https://gist.github.com/cdwarkani/34c2680ac0ffe0d17a95ccb232131b58

containerPort says about the port you need to expose from inside the container.

If you wish to edit and reupload the file in the pod then simply use the below command

kubectl apply -f my-new-pod.yaml

Next, we need to create service with the below command

This will create a service, link it with your deployment and host it in 1221. To check if service got created please type

kubectl get svc

Next, you can access your service from your system via browser and you’ll see the below image

and you are done with kubernetes setup.

--

--

Chetan Dwarkani

Tech experience in System Design | Java Script Framework | Android framework | ReactJS | JAVA | DB Design | chetandwarkani.com