Menu Close

Raspberry Pi Kubernetes Cluster

The Raspberry Pi Cluster is a cheap way to build and understand your very own supercomputer. Using Kubernetes, you can turn a handful of these cheap single board computers into a powerful cluster, capable of working multiple tasks at the same time. The best bit about this type of cluster is that it is completely scale-able, you can add more and more Raspberry Pis to it as you go.

I will be using 3 Raspberry Pi Model 3B as workers and 1 Raspberry Pi Model 4B 4GB as the master for this cluster. There are 2 reasons I have gone for this combination…. 1) that’s what I own, and 2) if you are using different models/spec of device, the most powerful should be the master.

Before I go any further, I will state that Raspbian is a version of Debian Linux, and as such this project can be adapted to work with most versions of Linux, such as Ubuntu or CentOS, on pretty much any device.

Items Needed

  • Raspberry PI 2 Model B (at least 2)
  • Power Cable for each Raspberry Pi
  • Ethernet Cable
  • Micro SD Card (at least 8gb each)

Desirable Items

  • Raspberry PI 3 Model B (at least 4)
  • Gigabit Ethernet Switch
  • 4 Short Ethernet Cable
  • 1 Ethernet Cable (long enough to reach your router)
  • Short (1 ft) Power cable
  • USB Charging HUB (1 port per Raspberry Pi
  • Cluster Case
  • Micro SD Card (32gb each)



So the quickest way to set this up is to install and configure the SDs, Insert them into the Raspberry Pis, and bring them up 1 by 1 and configure the IPs/Hostnames.

To start with you will need to download and set up Etcher on your PC/Laptop. Next download the latest Raspbian Lite image and unpack it.
Now insert a MicroSD into the reader on your PC/Laptop and format it to FAT32. Once this is done, open Etcher, select the Raspbian image, select the MicroSD and click “Flash”. Once completed, add and empty file to the boot file system called “ssh”

Now connect to the Raspberry Pis using ssh. The first thing to do is change the hostnames by using the command below

nano /etc/hostname

I have called mine RPI-1 RPI-2, RPI-3 and RPI-4, but you can choose a name that suits you.

Next you need to set static IPs on all of your Raspberry Pis using the following command, then paste in the block below and modify it for your network.

nano /etc/dhcpcd.conf

interface eth0
static ip_address=
static routers=
static domain_name_servers=

Now reboot your Raspberry Pis, then log back into them using the new static IPs you have assigned. Use this command to switch to root

sudo su

Now we need to install Docker using the following

curl -sSL | sh && sudo usermod pi -aG docker && newgrp docker

And next disable swap memory, as swap will cause issues going forwards.

dphys-swapfile swapoff && dphys-swapfile uninstall && update-rc.d dphys-swapfile remove

Now we need to add the repository for Kubernetes by editing the following file and adding the line below

nano /etc/apt/sources.list.d/kubernetes.list

deb kubernetes-xenial main

Once saved, use the next command to download the keys

curl -s | apt-key add -

Now we need to update the repository and download Kubernetes

apt update && apt install -y kubeadm

Now reboot your Raspberry Pis and SSH back into them once they come back up

Master Node

We now need to pull the Master Node image

sudo kubeadm config images pull -v3

Now to initialise the cluster, this will give you a code at the end that you will need to run later

sudo kubeadm init --token-ttl=0

Next we run the configuration

mkdir -p $HOME/.kube

sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config

sudo chown $(id -u):$(id -g) $HOME/.kube/config

Now install the Weave Network drivers

kubectl apply -f "$(kubectl version | base64 | tr -d '\n')"

Worker Nodes

You will need to run the following on each worker using the code you got earlier)

sudo kubeadm join --token <token> <master-node-ip>:6443 --discovery-token-ca-cert-hash sha256:<sha256>

Now run the below command, and you should see a printout as below

kubectl get nodes

rpi-1   Ready    master   116m   v1.17.3
rpi-2   Ready    <none>   92m    v1.17.3
rpi-3   Ready    <none>   92m    v1.17.3
rpi-4   Ready    <none>   91m    v1.17.3

This guide is based on the work of Alex Ellis, and has been created step by step as I have carried out the setup myself

1 Comment

Leave a Comment

%d bloggers like this: