K8s Architecture

K8s Architecture

What is Kubernetes?

Kubernetes, also known as K8s, is the most popular open-source container orchestration tool for automating deployment, scaling, and management of containerized applications in different deployment environments.

What problem does it solve?

Increased use of microservices and containers technologies, resulted in managing huge amounts of containers across multiple environments. That became more complex to manage so the container orchestration technologies we developed.

What Orchestration tools offer?

  • High Availability or no downtime

  • Scalability or high performance

  • Disaster Recovery or backup & restore

Kubernetes Architecture

K8s is a distributed system, which means it has different components that are spread across multiple platforms like servers, virtual machines, bare metal and instances of cloud . This complete setup with its components is called a Kubernetes Cluster.

Each cluster must consist of one Control Panel and worker node, but it supports multiple nodes as well.

There are two main components

  1. Control Panel

  2. Worker Nodes

Control Panel

  • Also known as Master Node

  • It maintains records of all Kubernetes objects.

  • It is responsible for Container orchestration(meaning: harmonious organization) and maintaining the desired state of the cluster

  • It has the following components.

    1. kube-apiserver

    2. etcd

    3. kube-scheduler

    4. kube-controller-manager

    5. cloud-controller-manager

Worker Node

  • Also known as nodes or compute nodes.

  • A virtual or physical machine that contains the services necessary to run containerized applications.

  • This has the following components:

    1. kubelet

    2. kube-proxy

    3. Container runtime

Kubernetes Control Plane Components

  1. Kube-apiserver

    • It is the only entry point for the entire cluster

    • It exposes RESTful API endpoints for communication with other components of the cluster and tracks the state of all cluster

    • It only can communicate with ETCD

    • It is reponsible for authorisation and authentication

  2. ETCD

    • It is an open-source, consistent, distributed, and highly-available key-value store.
  3. kube-scheduler

    • The kube-scheduler is responsible for scheduling pods on worker nodes.

    • When you deploy a pod, you specify the pod requirements such as CPU, memory, affinity, taints or tolerations, priority, persistent volumes (PV), etc. The scheduler’s primary task is to identify the create request and choose the best node for a pod that satisfies the requirements.

    • It watches API Server for new work tasks.

  4. kube-controller-manager

    • It is a process that monitors various components within the system and brings back the system to desired functioning state

    • There are different controller

      • Node Controller

      • Replication Controller - monitors replica sets and pods

      • Cron job

      • Service account controller

      • Namespace Controller

      • Endpoint-Controller, etc

  5. Cloud-controller-manager

    • The cloud controller manager integrates with the underlying cloud technologies in your cluster when the cluster is running in a cloud environment.

    • The cloud controller manager only runs controllers that are specific to your cloud provider.

Kubernetes Node Components

Node components run on every node, maintaining running pods and providing the Kubernetes runtime environment.

  1. kubelet

    • It is sole point of contact with the nodes. Kubelet is an agent component that runs on every node in the cluster.

    • It is responsible for registering worker nodes with the API server and working with the podSpec (Pod specification – YAML or JSON) from the API server & schedulers.

  2. kube-proxy

    • It manages IP translation and routing.

    • In a cluster every pod can communicate with another pod, it is done via pod network or via services

    • Services don't come under the pod's network. It is a virtual component

    • Service should be accessed by all clusters. To accompany this Kube-proxy runs on each pod. It checks for new services and when service is created, kube-proxy creates rules/ ip table rules to forward traffic heading to ip of service to ip of POD.

  3. Container runtime

    • The container runtime is the software that is responsible for running containers (in Pods).

    • To run the containers, each worker node has a container runtime engine.

    • It pulls images from a container image registry and starts and stops containers.

    • K8s support several containerization technologies like docker, containerd, CRI-O that are compliant with Container Runtime Interface (CRI)

Installation of Configuration of Minikube

What is minikube

Minikube is a tool that runs a single-node Kubernetes cluster in a virtual machine on your personal computer. Minikube is available for Linux, macOS, and Windows systems.

Why minikube

There's no specific reason for not installing all of the Kubernetes cluster parts on the host (using kubeadm), but it will be trickier to maintain. It may or may not conflict with local Docker use, and it is hard to uninstall or upgrade it. If you run Minikube in a VM (or Kind in a Docker container) then all of the parts are preinstalled for you, and you can easily stop or delete the VM (or container) when you don't need it anymore.

Install Minikube in windows

Step 1: Pre-requisites

Install Hyper-V:

Type systeminfo in cmd and verify below. It means Hyper-V is enabled in windows

Hyper-V Requirements:     VM Monitor Mode Extensions: Yes
                          Virtualization Enabled In Firmware: Yes
                          Second Level Address Translation: Yes
                          Data Execution Prevention Available: Yes

If not enable Hyper-V in Windows-11 Home using this document.

Install Docker:

To run in a terminal,
"Docker Desktop Installer.exe" install

Verify the docker version via command prompt,
docker --version

After installation, when you open docker desktop icon, it might ask to run wsl kernel update

wsl --update

For more info, check this document

Install Minikube:

Go to this site and choose the necessary details.

I choose to install Minikube via Windows Package Manager

Run winget install minikube in PowerShell as Administrator

Start Cluster

From a terminal with administrator access (but not logged in as root), run:

minikube start

Interact with Cluster

minikube can download the appropriate version of kubectl and you should be able to use it like this:

minikube kubectl get po -A

For additional insight into your cluster state, minikube bundles the Kubernetes Dashboard, allowing you to get easily acclimated to your new environment:

minikube dashboard

open the dashboard in browser, it may be blank initially.

Deploy Application:

Create a sample deployment and expose it on port 8080:

kubectl create deployment hello-minikube --image=kicbase/echo-server:1.0 kubectl expose deployment hello-minikube --type=NodePort --port=8080

This will create deployment, pod and a service

kubectl get services hello-minikube - Check the deployed service

minikube service hello-minikube - to access this service is to let minikube launch a web browser. Now the dashboard from local will open with details of deloyment, pod , rs

Alternatively, use kubectl to forward the port:

kubectl port-forward service/hello-minikube 7080:8080

Your application is now available at http://localhost:7080/.

View deployment - kubectl get deployments

View pods - kubectl get pods

View events - kubectl get events

View kubectl configuration - kubectl config view

View Services - kubectl get services

Stop Minikube - stops minikube

For more information on deleting the minikube , refer these documents.

https://kubernetes.io/docs/tutorials/hello-minikube/

https://minikube.sigs.k8s.io/docs/start/#what-youll-need