Platformer Blog

Kubernetes Multi-Node Cluster with Multipass on Ubuntu 18.04 Desktop

Stormy Sunday 5th April, 2020 Melbourne, Australia what best to do is to create yet another Kubernetes Cluster (yakc). Ooops did I invented another acronym?

This time my target is to see how fast I can create a yakc on my Ubuntu 18.04 Desktop with Multipass.

Few housekeeping items to consider, for most of you should be okay with the exception of if you are running on a limited resource Laptop.

Check to make sure that you have sufficient CPU, RAM and Disks storage for the 3 x nodes we are going to create (1 x Master Node and 2 x Worker Nodes)

On the 5th Sunday I ran into resource limitations (disk space mainly, I was left with only 5GB which wasn’t enough to run 3 x nodes). Unfortunately had to stop at this point as priority calls from family front.

Week later on Sunday 12th April 2020, I am back on track again after claiming more disk space for my Ubuntu Laptop (gparted is a handy tool if you do need to resize partitions without losing data).

Step 1: Install Multipass
In the event if you haven’t Install Multipass, please follow the following instructions to install multipass on your Ubuntu Desktop.

#snap install multipass

Step 2: Create the 3 x nodes
The following commands will help you create 3 x nodes. 1 x master and 2 x worker nodes. If you have sufficient CPU, RAM and Disk you can create more. However in this example I have create three.

#multipass launch --name master-k8s --cpus 2 --mem 2048M --disk 5G
#multipass launch --name worker-1-k8s --cpus 2 --mem 2048M --disk 5G
#multipass launch --name worker-2-k8s --cpus 2 --mem 2048M --disk 5G

List to check if you have all three nodes are running okay

#multipass list
Image for post

Step 3: Install Docker and Kubeadm

--Install Docker ---
#curl -sSL get.docker.com | sh && \
sudo usermod pi -aG docker-- Add Repo to the list and install Kubeadm
#curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add - && \
echo "deb http://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list && \
sudo apt-get update -q && \
sudo apt-get install -qy kubeadm

Step 4: Turn off Swap

#sudo swapoff -a

Step 5: Initialize the Master Node

#sudo kubeadm init --pod-network-cidr=10.244.0.0/16

If your master node initialization is successful you should see a message similar to the following.

Image for post

Step 6: Run the above instructions on Master Node
With the exception of running the kubeadm join command


#multipass shell master-k8s
#mkdir -p $HOME/.kube
#sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
#sudo chown $(id -u):$(id -g) $HOME/.kube/config--I am going to apply Flannel CNI
#sudo kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml

Step 7: Connect the two worker nodes

--first worker node --
#multipass shell worker-1-k8s
#sudo kubeadm join 10.158.117.108:6443 --token 1liumq.jz56jwd81qqxfplb \
--discovery-token-ca-cert-hash sha256:<TOKEN-YOU-HAVE-FROM-ABOVE>
#exit--second worker node --
#multipass shell worker-2-k8s
#sudo kubeadm join 10.158.117.108:6443 --token 1liumq.jz56jwd81qqxfplb \
--discovery-token-ca-cert-hash sha256:<TOKEN-YOU-HAVE-FROM-ABOVE>
#exit

If all successful you should see the below from your Master node

Image for post

Congratulations there you go you now have a fully functional yakc 😉

Additional Steps
1. Setup metrics server
2. Deploy your first pod and check to make sure you can actually deploy something in this cluster

--clone the metrics server
#git clone https://github.com/kubernetes-sigs/metrics-server---install the metrics server in your cluster
* if not already fixed, you will have to edit the 
#vi /home/ubuntu/metrics-server/deploy/kubernetes/metrics-server-deployment.yaml 
and change extensions/v1beta1 to apps/v1#kubectl apply -f ~/metrics-server/deploy/kubernetes/--wait for 2 x minutes or so and check if it was successful
#kubectl top nodes 
#kubectl top po --all-namespaces--run nginx pod in your cluster
#kubectl run nginx --image=nginx --restart=Never--check to see if your pod is running
#kubectl get pods
Kubernetes
Kanchana Wickremasinghe • 1/12/2021