- Download VirtualBox: https://www.virtualbox.org/wiki/Downloads
- Download Ubuntu 20.04.3 LTS: https://ubuntu.com/download/desktop/thank-you?version=20.04.3&architecture=amd64
- Install Ubuntu three times so that we will have 3 nodes for Kubernetes cluster. One Master node and other two as worker nodes.
- Create a NAT Network in Virtual Box (e.g. “Kubernetes Network”) from Network preferences section. Use Network CIDR as 10.0.2.0/24

- Attach NAT network to all three instances

- Set the hostnames of VMs as following:
sudo hostnamectl set-hostname k8s-control
for Master node
sudo hostnamectl set-hostname k8s-worker1
for Worker node 1
sudo hostnamectl set-hostname k8s-worker2
for Worker node 2
- Edit /etc/hosts file to include IPs of all three nodes. For e.g.
10.0.2.4 k8s-worker1
10.0.2.15 k8s-control
10.0.2.5 k8s-worker2
- Run Following Commands in each of the nodes
cat << EOF | sudo tee /etc/modules-load.d/containerd.conf
overlay
br_netfilter
EOF
sudo modprobe overlay
sudo modprobe br_netfilter
cat <<EOF | sudo tee /etc/sysctl.d/99-kubernetes-cri.conf
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
net.bridge.bridge-nf-call-ip6tables = 1
EOF
sudo sysctl --system

- Install and configure containerd on all nodes
sudo apt-get update && sudo apt-get install -y containerd
sudo mkdir -p /etc/containerd
sudo containerd config default | sudo tee /etc/containerd/config.toml
sudo systemctl restart containerd

- Disable Swap on all three nodes
sudo swapoff -a
sudo sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab

- Install kubeadm, kubelet, and kubectl on all nodes
sudo apt-get update && sudo apt-get install -y apt-transport-https curl
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
cat << EOF | sudo tee /etc/apt/sources.list.d/kubernetes.list
deb https://apt.kubernetes.io/ kubernetes-xenial main
EOF
sudo apt-get update
sudo apt-get install -y kubelet=1.21.0-00 kubeadm=1.21.0-00 kubectl=1.21.0-00
sudo apt-mark hold kubelet kubeadm kubectl



- Initialize pod network, create cluster and setup Kubectl access – On the control plane (master) node only
sudo kubeadm init --pod-network-cidr 192.168.0.0/16 --kubernetes-version 1.21.0
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
kubectl get nodes


- Install the Calico network add-on.
kubectl apply -f https://docs.projectcalico.org/manifests/calico.yaml

- Get the join command (this command is also printed during kubeadm init), You can copy that too.
kubeadm token create --print-join-command
- Copy the join command from the control plane node. Run it on each worker node as root (i.e. with sudo ).

- On the control plane (master) node, verify that all nodes in the cluster are ready. Note that it may take a few moments for all of the nodes to enter the READY state.
kubectl get nodes

CONGRATULATIONS!! You have setup the cluster successfully..