How To Setup Kubernetes Cluster (Master, Worker) Step By Step in Ubuntu 2021


At first, need to ready two virtual machine. One is for master (Minimum 2 cpus, 2GB Ram) and another one is for worker. Do same things in both vm (step 1 to step 3)

Step 1 : Install Docker

sudo apt-get update
sudo apt-get install docker.io
sudo systemctl enable docker 
sudo groupadd docker
sudo usermod -aG docker $USER
newgrp docker 
docker --version   

Step 2 : Configure cgroup of docker (Solution of kubelet failure)

sudo vi /lib/systemd/system/docker.service

Modifiy this line as below

ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock --exec-opt native.cgroupdriver=systemd

sudo systemctl daemon-reload
sudo systemctl restart docker
 

Step 3 : Install Tools and Configuration for Kubernetes Setup

curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add
sudo apt-get install curl
sudo apt-add-repository "deb http://packages.cloud.google.com/apt/ kubernetes-xenial main"
sudo apt-get install kubeadm kubelet kubectl -y
sudo apt-mark hold kubeadm kubelet kubectl
kubeadm version
sudo swapoff –a 
sudo sed -i '/ swap / s/^/#/' /etc/fstab 

Step 4 : Hostname Setup

sudo hostnamectl set-hostname master-node (For master node)
sudo hostnamectl set-hostname worker01 (For Worker Node)

Step 5 : Kubernetes Setup (Master)

Go to master node, check ip, replace the ip here <IP-of-Node> and run the below command

ip a

export MASTER_IP=<IP-of-Node>

kubeadm init --apiserver-advertise-address=${MASTER_IP} --pod-network-cidr=10.244.0.0/16

kubeadm join message will be shown. Note the message. Then create folder, copy config, and set permissions

mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config

Step 6 : Deploy Pod Network (Master)

sudo kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
kubectl get pods --all-namespaces

Step 7 : Join Master Node with Worker Node (Worker)

Go to worker node. Note the kubeadm join message, replace the token, cert, master ip with yours

kubeadm join --discovery-token your-token-value --discovery-token-ca-cert-hash sha256:your-cert-value Your-Master-Ip:6443
Go to Master Node to check
kubectl get nodes

Download Coding Interview Book and Get More Tutorials for Coding and Interview Solution: Click Here

Download System Design Interview Book and Get More Tutorials and Interview Solution: Click Here

Do you need more Guidance or Help? Then Book 1:1 Quick Call with Me: Click Here

Share on Google Plus

About Ashadullah Shawon

I am Ashadullah Shawon. I am a Software Engineer. I studied Computer Science and Engineering (CSE) at RUET. I Like To Share Knowledge. Learn More: Click Here
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment