How to build a Raspberry Pi Kubernetes cluster using MicroK8s
This tutorial will be a brief walk through the process of getting MicroK8s up and running on Raspberry Pi, and joining multiple Pis to form a production-grade Kubernetes cluster.
MicroK8s is a lightweight, fast, enterprise-grade Kubernetes. Whether you’re new to K8s or a power user, MicroK8s will help you save time and space on any embedded device or IoT projects.
This setup can be entirely headless or using an HDMI screen and USB keyboard to control nodes of your cluster.

Each Pi will need an Ubuntu server image and you’ll need to be able to SSH into them.
SSH into your first Pi and there is one thing we need to do before we get cracking. We need to enable c-groups so the kubelet will work out of the box. To do this you need to modify the configuration file /boot/firmware/cmdline.txt:
sudo nano /boot/firmware/cmdline.txt
And add the following options:
cgroup_enable=memory cgroup_memory=1
The full line for this particular raspberry pi looks like this:
cgroup_enable=memory cgroup_memory=1 net.ifnames=0 dwc_otg.lpm_enable=0 console=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait
Now save the file in your editor and reboot:
sudo reboot
Once that’s done we can now Install the MicroK8s snap:
sudo snap install microk8s --classic

MicroK8s is a snap and as such it will be automatically updated to newer releases of the package, which is following closely upstream Kubernetes releases.
To follow a specific Kubernetes upstream series it’s possible to select a channel during installation. For example, to follow the v1.17 series:
sudo snap install microk8s --classic --channel=1.17/stable
Channels are made up of a track (or series) and an expected level of stability, based on MicroK8s releases (Stable, Candidate, Beta, Edge). For more information about which releases are available, run:
snap info microk8s
Now that you have MicroK8s installed on all boards, pick one is to be the master node of your cluster.
On the chosen one, run the following command:
sudo microk8s.add-node
this command will generate a connection string in the form of
Now, you need to run the join command from another Pi you want to add to the cluster:
microk8s.join <master_ip>:<port>/<token>
You should be able to see the new node in a few seconds on the master with the following command:
microk8s.kubectl get node

For each new node, you need to run the microk8s.add-node command on the master, copy the output, then run microk8s.join
To remove a node, run the following command on the master:
sudo microk8s remove-node <node name>
The name of nodes are available on the master by running the microk8s.kubectl get node command.
Alternatively, you can leave the cluster from a leaf node by running:
sudo microk8s.leave
You are now in control of your Kubernetes cluster: once Pis are setup with MicroK8s, adding and removing nodes is easy and you can scale up or down as you go.
