Kubernetes: Whats, Whys, and Hows of Kubernetes with Demonstration
Tags: kubernetes, webdev, devops, tutorial
Published: 2022-12-25 07:37:45

## 📍 Why we need Kubernetes?

🙂 When It comes to heavy traffic on our website then we need to scale our App to handle more traffic. Also, It was a challenge earlier to make the App platform independent to ease the testing or usage on other machines. 

🎉 [Docker](https://dev.to/lovepreetsingh/what-is-docker-and-how-it-works-devops-424n) came as our life saver which made the dependencies and App package in a single container along with Hardware resources allocated for that container. 

Docker Made the following things easy:-
- We can run our App in containers that are machine independent
- It made the implementation of Micro-services Architecture easy
- Load Balancers can be used to distribute the load between the containers (For ex. Software Load balancers like [NGINX](https://dev.to/lovepreetsingh/nginx-advanced-load-balancer-web-server-reverse-proxy-4i23))

🎯 Now we know we can balance the load between the containers as:-

![Nginx and Docker](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8gl1c6l58i8gk6k0hwqd.png)

![Wohoo Meme](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5ks5qy479iydpsf4tugb.png)

😅 But But But!!! What If the load on one container increases? Then we need the Scaling of containers. And What if containers need to communicate with each other? 

😌 These challenges are overcome using Container management or orchestration tool called Kubernetes (Also known as K8s).

## 📍 What is Kubernetes?

Kubernetes is a Container management tool which provides us the various features to manage the containers. It facilitates the Micro-services Architecture.

![Monolithic and Micro-services Architecture](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n7ivz3u9lrd2ayl2arqf.png)

🔥 Features of K8s:-
- Automatic Bin-packing (It allocates the required resources to the container automatically)
- Load Balancing (If one node is down or having high traffic then the incoming traffic will be re-directed to another container)
- Self Healing
- Batch Execution
- Horizontal Scaling

🤜 Don't worry, we'll look into it if you haven't understood some.

![Docker meme](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7zozux6hwat7sh0tp0jk.png)

## 📍 Architecture of Kubernetes

![Kubernetes Architecture](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w0laic25q0bh5yzq4jh1.png)

🙂 It follows the Master-Slave Architecture where the manifest file (YAML file that describes each component or resource of your deployment and the state you want your cluster to be in once applied) is stored inside the Master. K8s API and Master interacts with the Nodes and deploys the pods.

👉 Pods are the fundamental units of k8s. Containers always resides inside the pods and Containers don't have their networking means they don't have their own IP or address, They will share the pod's IP and address.

![Kubernetes or k8s Architecture](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ida6xkr2j0kyuxo5dkv0.png)

- Master controls the cluster and the nodes inside it
- Nodes hosts the containers inside them and containers are inside the separate pods.
- In the above picture we have one cluster having three nodes

## 📍 Setup of Minikube and What is KubeCTL?

![Production cluster setup](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7j3zqkzdoom78103oudw.png)

🙂 In the above picture you can see that in production we have many resources such that we can make different clusters. But to test on our local machine we can use minikube.

![Minikube](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ub2wzm6ndgjiat0z2x1z.png)

🎯 Minikube will create a virtual box in our machine and Node will run in that virtual Box (Virtual Node). In other words, Minikube is a one node k8s cluster that runs in a virtual box in our laptop.

😅 To interact with the cluster we need KubeCTL (Kubernetes command line tools)

![k8s architecture](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vzsz70a4r3apb3awx0ih.png)

😇 In the above picture you can see that Master process communicate with the API server. It does that either using UI, API or CLI (KubeCTL). Note that we are talking about the virtual node in the local machine.

😌 KubeCTL can be used for both the Local machine Node or the cloud cluster.

![Kubectl usage](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5hw5pjxxb6j4k4f5ojex.png)

- **[Install](https://minikube.sigs.k8s.io/docs/start/) Minikube**

Note:- You need to install HyperKit or some kind of Hypervisor first.

- **After Installation of MiniKube, Type Minikube in the CommandLine**

![Minikube](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d9u6q0ke16eyha5z51gn.png)

- Now, type Minikube start but make sure you start the Docker first.

Now, you can use Minikube and Follow this [Cheat Sheet](https://minikube.sigs.k8s.io/docs/handbook/controls/) for Basic commands.

----

🎉 Follow for more interesting blogs. Drop a like and save for future.