Setup master and worker node VM's

Setup VPS and install docker (all nodes)

Refer: https://projects-srv2.kondgekar.com/projects/cbofferwall/wiki/0000-preliminary-setup

Fix swap (all nodes)

Installing kubernetes needs swap should be disabled. Check if swap is enabled and then disable if swap is enabled.

Disable swap

sudo swapoff -a

Remove / comment out respective swap entry from fstab file

sudo nano /etc/fstab

image-1621422218303.png

Install kubeadm, Kubelet And Kubectl (all nodes)

Refer: https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/install-kubeadm/

sudo apt-get update
sudo apt-get install -y apt-transport-https ca-certificates curl
sudo curl -fsSLo /usr/share/keyrings/kubernetes-archive-keyring.gpg https://packages.cloud.google.com/apt/doc/apt-key.gpg
echo "deb [signed-by=/usr/share/keyrings/kubernetes-archive-keyring.gpg] https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list
sudo apt-get update
sudo apt-get install -y kubelet kubeadm kubectl
sudo apt-mark hold kubelet kubeadm kubectl

Update Kubernetes Configuration (all nodes)

sudo nano /etc/systemd/system/kubelet.service.d/10-kubeadm.conf

This will open a text editor, enter the following line after the last “Environment Variable”:

Environment=”cgroup-driver=systemd/cgroup-driver=cgroupfs”

image-1621422742852.png

Start kubernetes cluster (on master)

We are going to use Flannel as a networking for pods

sudo kubeadm init --apiserver-advertise-address=<ip-address-of-kmaster-vm> --pod-network-cidr=10.244.0.0/16
  1. You will get the below output. The commands marked as (1), execute them as a non-root user. This will enable you to use kubectl from the CLI
  2. The command marked as (2) should also be saved for future. This will be used to join nodes to your cluster

image-1621423604564.png

Execute commands as mentioned above.

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

Verify if cluster is running (on master)

kubectl get pods -o wide --all-namespaces

image-1621424004202.png

Notice that all pods are running except coredns. It will be running once we setup pod network in the next step

Install POD network (Flannel) (on master)

kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml

image-1621424554088.png

kubectl get pods -o wide --all-namespaces

image-1621424641282.png

Notice that all pods are now running

Install Kubernetes Dashboard (on master)

Refer: https://kubernetes.io/docs/tasks/access-application-cluster/web-ui-dashboard/

Check available nodes (on master)

kubectl get nodes

image-1621425332028.png

Notice that only one node is available which is a master node.

Add worker node (on worker node)

Use below command to join Kuberneter cluster from worker node

kubeadm join <master-node-ip-address>:6443 --token <generated-token> \
    --discovery-token-ca-cert-hash <generated-hash>

image-1621425842025.png

Check if node is added in cluster (on master)

Initially worker node will show status as not ready

image-1621425912746.png

Wait for some time and it will be shown as Ready

image-1621425989576.png

 

Kubernetes cluster is now running. You can now run containerized applications and make it available over web using specific setup