Kubernetes implements a cluster computing background everything works from inside a Kubernetes Cluster, This cluster is hosted by one node acting as the ‘Master’ of the cluster, The other nodes as ‘nodes(Worker Nodes)’ which do the actual ‘Containerization’. Below is a diagram showing the same.
Kubernetes Components:
Web UI (Dashboard)
The dashboard is a web-based Kubernetes user interface. You can use Dashboard to deploy containerized applications to a Kubernetes cluster, troubleshoot your containerized application, and manage the cluster itself along with its available resources.
Kubectl
Kubectl is a command-line configuration tool (CLI) for
Kubernetes used to interact with a master node of Kubernetes. Kubectl has a config file called kubeconfig. This file has the information about the server and authentication information to access the API Server.
Master Node
● The master node is responsible for the management of the Kubernetes cluster
API Server:- Kube API Server interacts with API, its frontend of the Kubernetes cluster plane.
Scheduler:- Scheduler watches the pods and assigns the pods to run on specific hosts.
Controller Manager:- Controller manager runs the controllers in the background which runs different tasks in the Kubernetes cluster, performs cluster-level functions (replication, keeping track of worker nodes, handling nodes failures…).
Etcd:- Kubernetes uses etcd as its database to store all cluster data.
Worker Nodes
Worker nodes are the nodes where the application is actually running in the Kubernetes cluster, Each worker node are controlled by the master node using a kubelet process.
Kubelet:- Kubelet is the primary node agent that runs on each node and reads the container manifests which ensures that containers are running and healthy.
Kube-proxy:- It helps us to have a network proxy and load balancer for the services in a single worker node. Worker nodes can be exposed to the internet via Kube proxy.
Installation
Different ways to install Kubernetes
● GCP - Google Kubernetes Engine (GKE)
● AWS - Amazon EKS
● Azure - Azure Kubernetes Services (AKS)
● Minikube → Using Minikube we can setup single node K8s cluster,
kubeadm → we can setup multi-node k8s cluster
KOPS → Kubernetes operations, it is a software using which we can set up highly available Kubernetes clusters in AWS
Kubernetes Setup Using Kubeadm In AWS EC2 Ubuntu Servers
Prerequisite:
=============
2 - Ubuntu Serves (Minimum Required)
1 - Manager (4GB RAM , 2 Core) t2.medium
1 - Workers (1 GB RAM, 1 Core) t2.micro
Open Required Ports In AWS Security Groups.
# After launching the Two instances try to connect through Mobaxterm or Putty or Powershell etc,,,
1. Master Node
2. Worker Node
Then we will try to setup some required packages
# First, login as ‘root’ user because the following set of commands need to be executed with ‘sudo’ permissions.
sudo su -
# Install Required packages and apt keys.
apt-get update -y
apt-get install -y apt-transport-https
# Above command helps you to download through Internet Secure Protocol
# Adding GPG Key
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -
cat <<EOF >/etc/apt/sources.list.d/kubernetes.list
deb https://apt.kubernetes.io/ kubernetes-xenial main
EOF
apt-get update -y
#Turn Off Swap Space
swapoff -a
sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab
# Installing Docker
apt install docker.io -y
usermod -aG docker ubuntu
# Restart docker with the following command
systemctl restart docker
# Enable docker service, it is done with the following command
systemctl enable docker.service
# update the existing packages
apt-get update
# Install the Kubelet, Kubeadm, and Kubectl
apt-get install -y kubelet kubeadm kubectl
# Now reload daemon
systemctl daemon-reload
# Start kubelet, this can be done with the help of the following command
systemctl start kubelet
# Enable kubelet service, this can be done with the help of the following command
systemctl enable kubelet.service
==========COMMON FOR MASTER & SLAVES END=====
===========In Master Node Start====================
# Steps Only For Kubernetes Master
# Switch to the root user.
sudo su -
# Initialize Kubernetes master by executing below command.
kubeadm init
# It is clear that the Kubernetes master has successfully initialized. Now to use this cluster please run the above three commands mentioned
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
# To verify, if kubectl is working or not, run the following command.
kubectl get pods -o wide –all-namespaces
# You will notice from the previous command, that all the pods are running except one: ‘core-dns’. For resolving this we will install a # pod network. To install the weave pod network, run the following command:
kubectl apply -f "https://cloud.weave.works/k8s/net?k8s-version=$(kubectl version | base64 | tr -d '\n')"
kubectl get nodes
kubectl get pods --all-namespaces
# Get token
kubeadm token create --print-join-command
=========In Master Node End====================
Add Worker Machines to Kubernetes Master
=========================================
Copy kubeadm join token from and execute in Worker Nodes to join to cluster