Kubernetes Architecture & Setup with Minikube & App Deployment.

What is Kubernetes?

Kubernetes is an open-source platform for automating the deployment, scaling, and operations of application containers. It is also called the Container Orchestration tool. It was designed by Google and is now maintained by the Cloud Native Computing Foundation (CNCF).

Kubernetes is important because it makes it much easier to deploy and manage complex applications across different environments and infrastructures. By providing a consistent platform for containerized applications, Kubernetes allows developers to focus on building and improving their applications. Kubernetes provides features like self-healing, and horizontal scaling, which make it easier for organizations to adopt container technologies.

Docker-Swarm vs Kubernetes

Docker Swarm and Kubernetes are both container orchestration platforms. - - Kubernetes is generally considered to be more powerful, scalable, and complex than Docker Swarm.

  • Docker Swarm can’t do auto-scaling.

- Kubernetes has a more advanced architecture, networking features, and resource utilization controls, and it is better suited for large, complex deployments.

  • Docker Swarm is simpler and easier to use, it is a good choice for smaller or less complex deployments.

- Kubernetes can deploy rolling updates, & does automatic rollbacks.

  • Docker Swarm can deploy rolling updates, but not automatic rollbacks.

- Kubernetes has built-in tools for logging and monitoring.

  • Docker Swarm uses tools like ELK stack for logging and monitoring.

- In Kubernetes, manual intervention is needed for load-balancing traffic between different containers and pods.

  • Docker Swarm does auto-load balancing of traffic between containers in the cluster.

    What are the features of Kubernetes?

The features of Kubernetes are:

  • Automated Scheduling
  • Self-Healing Capabilities

  • Automated rollouts & rollback

  • Horizontal Scaling & Load Balancing

  • Offers environment consistency for development, testing, and production

  • Infrastructure is loosely coupled to each component and can act as a separate unit

  • Provides a higher density of resource utilization

  • Offers enterprise-ready features

  • Application-centric management

  • Auto-scalable infrastructure

  • You can create predictable infrastructure

Kubernetes Architecture

Kubernetes works on the Master and Worker node architecture.

Master Node

  • API Server

-This enables all the communication between APIs.

-It takes the request and sends it to other services. We can use Kubectl CLI to manage the Kubernetes Cluster. Kubectl sends the request to the API server and then API Server responds.

  • ETCD: A distributed key-value store used to persist the configuration data of the cluster.

-Kube API Server stores all the information in Etcd and other services also read and store the information in the Etcd storage**.**

-It should be backed up regularly.

-It stores the current state of everything in the cluster here at the ETCD server.

  • Controller Manager: A component responsible for tracking the desired state of the cluster. such as replicating pods, and handling failures. It keeps track of what's happening in the cluster gives updates to API servers and then the API server takes actions accordingly. There are different types of controllers and are all part of the Controller Manager.

    -Node controller----{responsible for checking the status of the node}

    -Replication controller--{maintaining the correct number of pods}

    -Endpoints controller--{services,pods}

    -Service Account and Token Controllers--{create default accounts and API Access Tokens for new namespace}

  • Scheduler: As the name suggests, it helps to schedule a particular job at a particular time. It is responsible for scheduling pods onto nodes based on available resources and constraints. It is responsible for distributing the workload.

Worker Node

  • Kubelet: An agent that runs on each node and communicates with the API server to ensure that containers are running as expected. It acts as a receiver for Kubctl [Kubectl gives the instructions to API Server and API Server delivers the information and Kubelet interprets the information and implements in Worker Nodes.]

  • Kube proxy: kube-proxy runs on each node and talks to API-server to get the details of the services and endpoints present. Based on this information, kube-proxy creates entries in iptables, which then routes the packets to the correct destination.

  • Container Runtime: Kubernetes supports several container runtime.

    - Docker

    - Containerd

    - cri-o

    Setup with Minikube & Deployment.

A Kubernetes cluster can be deployed on either physical or virtual machines. To get started with Kubernetes development, you can use Minikube. Minikube is a lightweight Kubernetes implementation that creates a VM on your local machine and deploys a simple cluster containing only one node. Minikube is available for Linux, macOS, and Windows systems. The Minikube CLI provides basic bootstrapping operations for working with your cluster, including start, stop, status, and delete.

It cannot be used on a production cluster, it’s a single-node machine with no high availability.

STEP-1

Launch an instance EC2 on AWS

Install docker, for containerization we need docker to be installed. Using the command(for installation of Docker FOllow this link****

(https://docs.docker.com/engine/install/ubuntu )

STEP-2

Installation and setup of MINIKUBE

follow this link https://minikube.sigs.k8s.io/docs

  • download Minikube on your system

    • To start minikube cluster, which will boot the instance, Use the command

$ minikube start

It will take some time because it needs to boot up the instance.

If Minikube fails to start running these commands(setting up a compatible container or virtual machine manager.)

Minikube has set up the Kubernetes cluster. There are two CPUs in which one is used for the Master node and all the required components such as the controller, scheduler, etcd etc are installed in the Master node.

Verifying if Cluster is up and running

STEP-3

Internal architecture of local Kubernetes

Kubernetes is running inside Minikube hence, to verify all the Kubernetes components we can use

$ minikube ssh

this command will enable us to interact with the Shell of Minikube

we are inside the minikube shell, by

$ docker ps

we can see all the containers running inside Minikube. These containers are nothing but all the components as described earlier

We are inside Minikube SSH and all the containers shown above are running inside it.

STEP-4

Installing kubectl

kubectl is a command line tool that helps us to interact with master node of Kubernetes

$kubectl

$sudo snap install kubectl --classic

To Install kubectl we can use this command. snap is used when we want to install containerized applications and kubectl itself is a containerized component of Kubernetes.

STEP-5

Define Namespace

Namespaces provides a mechanism for isolating groups of resources within a single cluster.

Kubernetes automatically creates the following namespaces: default (for user workloads) and three namespaces for the Kubernetes control plane: kube-node-lease, kube-public, and kube-system. Kubernetes also allows admins to manually create custom namespaces.

Creating a Namespace

Now, we can create a pod and run the django app under this newly created namespace called django-todo-app.

Creating a POD & Running a Node app inside it

To create a pod we have to write a YAML configuration as shown below.

our pod is successfully up and running. Also, check from

$minikube ssh

Deleting a Pod

Syntax:$ kubectl delete pod --namespace=nameOfTheNamepace pod name

$ kubectl delete pod --namespace=django-todo-app node-todo-pod

Finally, our pod is deleted.

Thanks for reading!!

Hope it will help all beginners to start their journey with Kubernetes(Minikube).