MicroK8s (Kubernetes) – Raspberry Pi Ubuntu Linux Basic Setup Guide – Part 1 (Getting Started)

Kubernetes Linux

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.

Set Hostname

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:

vi /etc/hostname

Set the hostname as per one the following:

  • k8s-master
  • k8s-worker-01
  • k8s-worker-02
  • k8s-worker-03

Edit the hosts file:

vi /etc/hosts

Replace the “127.0.0.1 localhost” line with the new hostname so: “172.0.0.1 k8s-master localhost” for example.

Reboot the server.

Set Timezone and NTP

sudo dpkg-reconfigure tzdata

sudo timedatectl

timedatectl show-timesync

https://www.linuxuprising.com/2019/07/how-to-set-timezone-and-enable-network.html

Perform Updates

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.

vi /boot/firmware/cmdline.txt

Then at the end of the line add:

cgroup_enable=memory cgroup_memory=1

Reboot and repeat for each of your nodes if you’re setting up a cluster for MicroK8s.

Install 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:

microk8s.add-node

You’ll see a token on the screen, make a note of this, you’ll need it for the next worker nodes:

microk8s.join <master_ip>:<port>/<token>

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:

microk8s status

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.

Image Attribution

Leave a Reply

Your email address will not be published. Required fields are marked *