# K8 on RPi

Running Kubernetes on RaspberryPi

Cool things about K8 on the RPi

rak8s is a project I forked from someone else (Chris Short who did an excellent job getting this started) and I have made some slight adjustments for my needs. I really like the idea of using Ansible, but I will say it took lots of work to get my cluster up and running. Below is my process that I went though to make it as painless as possible.

## the hardware

• 4 x Raspberry Pi ver 4 B
• 4 x SD cards
• 4 x Power over Ethernet Hats
• 4 x Short Ethernet Cable
• 1 x Power over Ethernet Hub
• 1 x Cluster kit hardware to stack Pi’s
• 1 x Micro HDMI to regular HDMI

## the discoveries

Very quickly, I found out that every experiment of iterating with Ansible to configure the Pi’s resulted in re-imaging of Raspbian OS Server. This got old really really quick and I tried to use CloneZilla to clone the SD cards as best as I could. If you have a really good SD card reader(s) for doing multiple writes, then I think you will be well advisided to invest a little bit of time or money into writing to multiple SD cards.

## from 0 to 100

My process was not straight out of the box to then be up and running, but rak8s sure did help. I started with the hardware and:

### hooked up wires

Experimented with a couple of different PoE hats, but landed on the one by Raspberry Pi for a couple of reasons:

1. less high pitched noise
2. has a fan that was relativly quiet
3. compatible with the frame i bought

As for the PoE switch, I dont think my choice was a good one. The software on the switch was nice, but seemed really old. But it delivers the amount of power I need for the 4 SBCs. Going with a 8 Port switch was also a good idea because of the following port mapping:

• Port 1: pi 1
• Port 2: pi 2
• Port 3: pi 3
• Port 4: pi 4
• Port 5: (future)
• Port 6: (future)
• Port 7: Phililps Hue

As you can see I really filled up the ports and can always add a couple more if I see the need.

I really like the short ethernet cable. This makes the package nice and neat and since I am using PoE, there are no power supplies to manage.

### configure the home network

Once I got the first pi 1 hooked up to the network, I assigned it a static IP address with my wifi network. This is important because K8 needs known hosts to be registered. I have a feeling this could be delt better with a real K8 cluster, but this is a Raspberry Pi cluster and by no means should be treated with production level expectations.

I then went on to configure the other PIs to have static IP addresses. It really helps to have these in sequential order. Just makes things super simple. I choose the following number convention:

last ip octethostnamerole
.70node-0manager
.71node-1node
.72node-2node
.73node-3node

### setup

Downloaded the Raspian OS Arm 64bit version as Kubernetes needs this for operation. The steps you want to complete on the raspian os, they are as follows:

1. install ssh key
2. set ssh to start on boot
# run the following on your remote-host
# you know, the one that is not the raspberry pi
#
# generate a private key
#
# when prompted of where you want to store the file,
# makes two files: k8_id_rsa, and k8_id_rsa.pub
ssh-key-gen
#
# now copy the key to the raspberry pi
# using the ip address you set for the pi.
# you should be prompted for the password
# that you choose during pi boot up
ssh-copy-id -i ~/.ssh/k8_id_rsa [email protected]
#
# now the following command is to test you
ssh -i ~/.ssh/k8_id_rsa [email protected]


After your all done with ssh work, lets move on to setting the raspberry pi ssh to start:

1. ssh into your raspberry pi
2. sudo raspi-config
3. interface -> ssh
4. accept yes to start ssh on boot

### cloning

This step is for closing the SD cards to the other 3 Raspberry Pis. Now that we have our SSH key to connect to each one, we are ready to boot up each node and have them ready to recevie further configuration. After you are done with all of the changes you are ready to clone the SD cards, I tried using VirtualBox, but after some painful hours of trying to attach my SD card reader and having 0 success, I found two options:

1. use the tool dd which is pretty slow and works
pbpaste > $HOME/.kube/config  ### test kubectl Lets make sure kubectl works! Listing the nodes is always my favorite. kubectl get nodes NAME STATUS ROLES AGE VERSION node-0 Ready master 8h v1.17.0 node-1 Ready <none> 8h v1.17.0 node-2 Ready <none> 8h v1.17.0 node-3 Ready <none> 8h v1.17.0  ### networking All of my networking or routing was done with rak8s-metallb which involves updating the configuration yaml file with your reserved IP address pool. The instructions for installing metallb are in the README.md and assume you have kubectl configured. Make sure you update the config.yaml file with the ip addresses of your nodes. ### shutdown (if you want to) Now that your done setting up Kubernetes, you might want to turn it off some day if you are not using it to save a little bit of power (even though it would cost about $2 a year to power it) you can call upon ansible to shut all of your pis down safely with the following command.

ansible all -a "shutdown -h now" -i inventory


## conclusion

You now have a kubernetes cluster up and running in your own home. While this cluster does not have tons of power, I find it great for experimenting with Kubernetes.