Deploying Kubernetes to a Raspberry Pi
The Raspberry Pi 4 is revolutionary. It is the perfect balance between power and affordability.
However, as with most electronics impulse-buys, I’ve had difficulty putting it to good use. I thought I’d bring up a kubernetes cluster to host my personal blog(this). There will be a series of posts related to that, this being the first.
There are a few lightweight kubernetes offerings around these days. microk8s was one I tried, but shortly after k3s appeared on the scene. It was impressive that it requires nearly no system level dependencies (microk8s requires snap).
One decision k8s made that I don’t prefer is the use of the
traefik ingress controller. I prefer the ingress-nginx controller, but it’s not that difficult to switch one out for the other.
I’m assuming that you have a Raspberry Pi booted with some sane Linux distro. I prefer Arch for Arm. And also that you have docker installed and running.
Then, initiate the super simple k3s install script with particular options.
curl -sfL https://get.k3s.io | INSTALL_K3S_EXEC=" --no-deploy=traefik --docker" sh -s -
--no-deploy=traefik instructs the installer to skip the in-built
traefik install, the
--docker instructs k3s to use plain docker instead of the newer
containerd. I prefer it because it fits in with my workflows. If you have a super simple setup you can likely omit this option and stick with
After the cluster is bootstrapped, you should have a functioning cluster, try executing
kubectl get pods --all-namespaces. You should see familiar pods like
Nginx Ingress Install
Now, this is the most infuriating thing about Kubernetes on ARM. All setup guides and a vast majority of examples assume you’re running
amd64 hardware, so most new users will be puzzled why they’re getting
CrashLoopBackoff on their pods. Will this is because your little Raspberry Pi is trying to execute binaries that are built to run on your Intel Desktop. You can likely see log messages like
invalid exec format or similar.
Some of the time you’ll be lucky and the project in question will have
arm images available, but more likely than not you will have to build
arm images yourself.
Gotcha: Although the Raspberry Pi 4 is 64bit capable, most distros for it are still 32bit. Watch out for
arm64 images that wont run.
ingress-nginx project has an
arm build that we can use, however the default manifests from the setup guide use
For this reason I created a new repo that has manifests that are ready to go on a Raspberry Pi.
You can install the nginx ingress controller by issuing the following commands:
kubectl apply -f https://raw.githubusercontent.com/dmarkey/kube-rpi/master/ingress-nginx/mandatory.yaml kubectl apply -f https://raw.githubusercontent.com/dmarkey/kube-rpi/master/ingress-nginx/cloud-generic.yaml
This should bring up a single replica deployment, also with k3s, it will bring up a small pod that acts as a load balancer to forward traffic, you should get an nginx 404 page when going to your Raspberry Pi’s IP address.
At this point you’re ready to install some apps and get the ingress controller to forward some traffic.