Kubernetes(K8s) is now commonplace in most organisations.  If it’s not, then it’s definitely being looked at as an option for the near future.  There is still an air of magic around deploying to the “cluster” which takes just a simple yaml file containing the all to common docker image.  As simple to produce locally as it is via any major vendor, your scaleable, self healing application is then published to the world.

As Kubernetes has become more refined over the past 5 years, more lightweight options have turned up making it even more viable to “own your own” K8s cluster on just a set of Rasp. Pi’s lying around.  Steps below show how you can put one together.

Key steps:

Setup a Raspberry Pi

  • Flash a 16Gig SD using the Raspberry Pi Imager
  • Boot up and setup on your network
    • SSH on
    • Change hostname
    • Change password
    • Locale settings

Prepare for Kubernetes

Originally tried to use microk8s setup on Ubuntu, but wasted a lot of time setting up and configuring Ubuntu for K8s only to find out microk8s took ages to respond.  This may have just been my setup or a lack of familiarity with Ubuntu but long story short used k3s instead.

Super simple to setup k3s even has a utility to check to make sure your Rasp. Pi is correctly configured.  Be sure to note the section on raspbian setup this i’ve covered in the steps below but may have changed at the point of reading.

Steps taken from K3s documentation and advice from check-config scripts to prepare were as follows:

sudo systemctl disable dphys-swapfile.service

sudo iptables -F
sudo update-alternatives --set iptables /usr/sbin/iptables-legacy
sudo update-alternatives --set ip6tables /usr/sbin/ip6tables-legacy

sudo vi /boot/cmdline.txt
cgroup_memory=1 cgroup_enable=memory

sudo reboot

Install K3s

This was so super easy its criminal.  The only problem I found was due to the latest version at the time [1.20] which seems to have certificate issues and as a result despite the services starting nothing is able to communicate together.  As a result I installed it using a specific version, which in this instance was 1.19.5.

curl -sfL https://get.k3s.io | INSTALL_K3S_VERSION=v1.19.5+k3s2 sh -

Once this has installed K3s will be running on the box and you can issue a kubectl command to see the available node.  This is all detailed at in the K3s quick start guide.

Connect to K8s remotely

To then connect to the instance locally steal the credentials from

/etc/rancher/k3s/k3s.yaml

and add them to your local ~/.kube/config file

Add another K8s node

This is also super easy.  Once you have another Rasp.Pi instance up and running on your network with the steps above obtain the token from the first instance

sudo cat /var/lib/rancher/k3s/server/node-token

Then on your new instance install K3s referencing the IP of the initial instance

curl -sfL http://get.k3s.io | INSTALL_K3S_VERSION=v1.19.5+k3s2 K3S_URL=https://<<IP-ADDRESS>>:6443 \
K3S_TOKEN=<<TOKEN>> sh -

Buy a swanky box

This was probably the best bit.  An exceptional dude in California has put together the sweetest box you have ever seen to house all your hard work.

 

References

Run Kubernetes on a Raspberry Pi with k3s

Zebra Bramble Cluster Case (4-stack)

Next …. Kafka on K8s