Roman KlimenkoBlogPhotography

Running Kubernetes on Raspberry Pi

November 26, 2022


Let's install Kubernetes on a Raspberry Pi 4 (8Gb).

There is plenty of Kubernetes distributions that work fine on Raspberry. I choose MicroK8s.

Install Snap

First of all, we need to install Snap - the app store for Linux from Canonical. Let's follow the official recommendations:

sudo apt update sudo reboot sudo snap install core

Install MicroK8s

Again, there's an official manual for this. The only thing is that it tells to change sudo vi /boot/firmware/cmdline.txt, but on my Raspberry Pi 4, I found this file in /boot/cmdline.txt.

So, open /boot/cmdline.txt in your editor of choice and add the following at the end of the line: cgroup_enable=memory cgroup_memory=1.

In example:

sudo vi /boot/cmdline.txt

Then, install microk8s:

sudo snap install microk8s --classic --channel=1.25 sudo usermod -a -G microk8s pi newgrp microk8s microk8s status

Install kubectl

sudo snap install kubectl --classic sudo chown -f -R pi ~/.kube microk8s config > ~/.kube/config

The following command will list your pods from all namespaces:

kubectl get pods -A

Now, to connect from another computer, copy ~/.kube/config to your computer and follow the recommendations.

In short, you can either store this file as a separate context file or merge/overwrite it to your ~/.kube/config. If you put it in a separate file, say, ~/.kube/pi-config.yml, you'd need to do one of the following:

  1. Pass the file's path when running kubectl, e.g.: kubectl --kubeconfig ~/.kube/pi-config.yml.
  2. Provide the file's path in the $KUBECONFIG environment variable.