Kuberntes is a platform for the managing of containerised workloads and services, that is akin to a declarative infrastructure as code type platform. It allows developers to deploy containerised applications quickly and easily and in such a way that infrastructure system administrators can manage the infrastructure for the applications to be as adaptable and flexible as the applications require.
To avoid repeating what is already there read the What is Kubernetes? article on the Kubernetes website for more information.
Now, MicroK8s is a small easy to deploy version of Kubernetes and in this guide we’ll be installing it onto Raspberry Pi computers. You can install onto a single Raspberry Pi, but for this example we’ll be installing on 3 x Raspberry Pi 4’s with 2GB RAM each, 4GB is recommended but not essential.
Install Ubuntu 20.04 onto Raspberry Pi
Firstly download the Ubuntu 20.04 Raspberry Pi image x64 version. Flash the image to the memory card, you’ll need at least 16GB memory card, ideally 32GB, a tool like Rufus is ideal.
Once the device has booted, determine its IP address, normally the easiest way is to find this from your DHCP server.
SSH to the device username: ubuntu, password: ubuntu, you’ll be prompted to change the password and then be disconnected. Reconnect via SSH using the new password you just set.
Edit the hostname file:
Set the hostname as per one the following:
Edit the hosts file:
Replace the “127.0.0.1 localhost” line with the new hostname so: “220.127.116.11 k8s-master localhost” for example.
Reboot the server.
Set Timezone and NTP
sudo dpkg-reconfigure tzdata sudo timedatectl timedatectl show-timesync
apt update apt upgrade reboot
Preparation for Microk8s
We need to configure the memory settings for Kubernetes to operate correctly, node this needs to be done to all the nodes that are going to run MicroK8s.
Then at the end of the line add:
Reboot and repeat for each of your nodes if you’re setting up a cluster for MicroK8s.
Run the following on all nodes to install Microk8s:
snap install microk8s --classic
Once installed on all the nodes, run on the node you want to be master:
You’ll see a token on the screen, make a note of this, you’ll need it for the next worker nodes:
You may also need to enable your firewall to allow communication:
sudo ufw allow in on cni0 && sudo ufw allow out on cni0 sudo ufw default allow routed
Enable Kubernetes Add-Ons
We want to enable a load of add-ons, you can see which are enabled with:
Lets turn some things on, the main ones to explain are “storage” that gives you persistent volumes, “metallb” that provides a load balancer for accessing your pods services e.g. HTTPS, and the “registry” for the storage and management of images.
microk8s enable dns microk8s enable storage microk8s enable metallb (You’ll be prompted for a range of IP addresses here, pick one on the same subnet as the Kubenetes nodes) microk8s enable ingress microk8s enable dashboard microk8s enable registry
You may need to wait a while for all the pods to be created. You can check on progress with:
microk8s kubectl get pods --all-namespaces -o wide
When all are done then you are ready to continue to the next part.