Installation of Kubernetes Cluster (1 Master & 2 Worker) in Container mode for Ubuntu OS 20.04 LTS  on t2.small AWS EC2 Instance.

Installation of Kubernetes Cluster (1 Master & 2 Worker) in Container mode for Ubuntu OS 20.04 LTS on t2.small AWS EC2 Instance.

What is Kubernetes?

It is a container orchestration and management tool.

You can imagine an Orchestra event wherein one person so-called Orchestrator is used to manage other people by giving instructions on how to play the instruments, managing the musical trends (high volume/low volume) etc…

Major Roles of Orchestration: -

1) Management (CLI/GUI)

2) Control

3) Schedule

4) Database

Problems in the Containers Life cycle: -

1) Centralized management is not available

-We are creating containers on a Docker host, if capacity used for a Docker host is getting utilized, we can take Docker host-2, Docker host-3…and so on, The number of Docker hosts is getting increased, All software, databases & applications are packed in a container and companies are increasing there workloads by deploying new microservices. Now the problem comes with “How to manage the Docker host” because we do not have centralized management to check RAM Status, what is the states of the Container, uptime, downtime, desired /current state etc. It is working in a Standalone mode in the Docker host.

  1. High availability /Failover/Clustering is not there

3. Scalability is not there

4. No User management in terms of Project specific privilege

Advantages of Kubernetes: -

1) Centralized management: - Now, we can manage all the Docker machines from a single site/machine/Orchestrator node, management is controlled in a centralized manner, We can trigger all the instructions regarding containers (Like creation, deletion, modification, networking, volume) from master

2) It manages Docker system state (current vs desired) and container states as well

3) Failover/HA is possible: - Now, we can move one machine container to another docker-machine manually or automatically.

4) Scalability:- Kubernetes supports Manual/Automatically scalability, Kubernetes supports Vertical and Horizontal scaling, Vertical means increasing the RAM/Memory usage on the same machine and Horizontal means increasing one or multiple machines with the same or different configurations.

5) Role-based user access control

6) Rolling out and Rollback update: Now with Kubernetes, we can upgrade our Application to a new container with Zero downtime.

What is Kubernetes Cluster:-

When we are managing our docker host via an orchestrator server, That group of machines is called a Kubernetes cluster, We may have one or many Master nodes and one or many worker nodes in that cluster depending on the business requirements.

Kubernetes cluster can be deployed on On-Premises (Physical, Virtualized [KVM/VMware/Openstack], Cloud-based.

Control Plane node: Master nodes

Worker node: Data plane nodes

Kubernetes Architecture: -

1) Master nodes/Orchestrator node: Management server which is controlling Docker machines /Worker nodes, It is also called a control plane node.

Four Components of Master node:-

a) Kube-API:- It is the command listener and checks for Authentication and Authorization validation.

b) Kube-etcd: It is the Database, It stores all information about the Cluster in ETCD if ETCD service is going down then the cluster will not work and API also will be going down, API depends on ETCD because without ETCD API can’t acknowledge anything, API’s all the information will be Read/write from ETCD, Works of ETCD is to store Information of API will Persistent form, We are taking backup of ETCD which contains all the deployment information of that cluster which contains container level data.

c) Kube-scheduler: Resource availability, Scheduling of containers

d) Kube-controller: it continuously checks the current state to Desired state if it is not matching then informs to API E.g., if suppose out of 10 nodes 2 nodes got failed then the controller will provide that 2 nodes information to the API, API talks to ETCD and check the database then API talks to Scheduler for checking where we can accommodate 2 nodes container as per resource availability and deploy it.

Worker nodes:-

It is the container host/data plane node which consists of 3 services.

1) Container runtime (dockerd / containerd / cri-o) – It is configured on the Worker node, containerd will not understand API instructions so we required a Kubernetes agent on the Worker node so-called Kubelet

2) Kubelet: Kubelet is an Agent of Kubernetes API which take instructions from the Master and then apply to container Runtime (containerd)

3) Kube-Proxy: It is used for networking

Installation of Kubernetes: -

User managed:- When someone creates Master and worker nodes by themselves by installing all the services on top of the OS manually, it is an Infrastructure as a service (IAAS) plus installation on top of it, we are responsible for all the infra operations as an IAAS.

Installation of Kubernetes Master node: -

1) Create AWS EC2 instance on Ubuntu OS image 20.04 LTS (Long term support) and take instance type as t2.small (1 VCPU and 2GB memory)

2) Create a new keypair/take the existing one if already there

3) Select the Security group & allow all traffic in the security group

4) Launce instance with other default settings.

5) Kubeadm utility Installation: Use this link for the documentation Installing kubeadm | Kubernetes

Command history for reference:

6) Docker/Containerd Installation: Setup it from the docker website link Install Docker Engine on Debian

Command history for reference:

7) Kubelet Installation: We will containerize below 4 services with the help of KUBEADM

a) API

b) Scheduler

c) ETCD

d) Controller

root@K8s-master:~# kubeadm init --ignore-preflight-errors=all

if you are getting an error due to API is not authenticated then run the below commands.

root@K8s-master:~# mkdir .kube

root@K8s-master:~# cp /etc/kubernetes/admin.conf .kube/config

Check kubectl service health status by kubectl get componentstatus

Installation of Kubernetes Worker node: -

1)Docker/Containerd Installation: Setup it from the docker website link Install Docker Engine on Debian

Command history for reference:

2)Kubelet Installation: Do not Initialize kubelet on Worker nodes as Join the Worker node with the Master node.

Command history for reference:

3) Create a token from the Master node:-

Copy the output command from the above snip to all the worker nodes so that Worker nodes Join the Master node.

Calico network command for changing the state from Not-Ready to Ready:- Run this on Master node

root@K8s-master:~# curl https://raw.githubusercontent.com/projectcalico/calico/v3.25.0/manifests/calico.yaml -O

root@K8s-master:~# kubectl create -f calico.yaml

Check the Kubernetes cluster information:-

You can see 1 Master and 2 Worker node setup is ready.