Microk8s on Raspberry Pi
I have written a few post on running Kubernetes on Raspberry Pi’s. The size of the platform is perfect for tinkerers to developers wanting to learn more. You can cluster them, as I wrote before or you can use them as a single cluster. For the price they give someone the ability to run a small home server for around $50.
But this time I am setting up a new cluster to run my Twitter bot. Sure I don’t need another Raspberry Pi 4. And $50 is a bit pricy for a single use Pi. But I had a few Pi’s laying around so I thought this would be a great use of one of them. I have a few idea’s for my Twitter bot and this gives me a small platform to expand upon.
I have a few post on how I have set up Kubernetes on Raspberry Pi 4s. This post I want to organize this to a one pager to get started. We are going to use MicroK8s on a Raspberry Pi. And of course we are going to use a 64-bit OS. Where we are going to depart from my other post is going to focus on getting our app running. So I am going to use some tools that have long term support or LTS.
- Raspberry Pi 4 Model B - 4GB DDR4
- Raspberry Pi 4 Official 15W Power Supply US - Black
- SanDisk Ultra PLUS 32GB microSDHC
- GeeekPi Raspberry Pi 4 Case
Yes the price of everything listed is over $50. I did benefit from a few sales at Micro Center. So to save a few bucks I recommend you shop around. The case is arguably needed. I love this case, the fan is quiet and keeps my Pi cool with ease. The microSDHC is another splurge but this one is necessary. Going cheap on a microSDHC card will cause problems in the long run.
Prepping the Drive
First let’s get the OS. Where from my first post on doing a 64-bit OS I used Ubuntu 19.10 for this one we are going to roll to Ubuntu 20.04 LTS. We moving to long term support operating systems. I don’t want too update these if I don’t have to.
So to install the OS to the drive. Nothing new here same thing we did previously.
# unmount disk diskutil unmountdisk /dev/disk2 # flash sd card sudo dd if=ubuntu-ubuntu-20.04-preinstalled-server-arm64+raspi.img of=/dev/disk2 bs=2m
When the dd command is done you should see something like:
1479+1 records in 1479+1 records out 3102821376 bytes transferred in 769.989419 secs (4029694 bytes/sec)
I added another step to this:
Setting up the Pi
Once the flash drive is done we need to log in to the Pi. So insert the flash drive in to the Pi and power it up. To log in the default username and password is both
ubuntu. This is a perfect time to change it so do so now. You will need to plug an ethernet cable in to your router and Pi. Next we need to update so run the following commands:
sudo apt update sudo apt upgrade
This will take a few minutes to run.
For me I don’t have the space to keep my Pi close to my router. I need to configure the networking but I am going going make sure WIFI is set up so I can move my Pi to a better spot in my office. With this version of Ubuntu the netplan file is located here /etc/netplan/50-cloud-init.yaml from the terminal find this directory and file. Then run this command:
sudo nano 50-cloud-init.yaml
This will require a password of the
ubuntu user. The file should look like this:
network: ethernets: eth0: addresses:  dhcp4: true version: 2
I will not go in to detail on what is in this file and what you need to add, I wrote that up before but you are going to want to set some static IP address for both the ethernets and wifis. This file should look like this when you are done:
network: ethernets: eth0: addresses: [192.168.1.5x/24] # note the x here is supposed to be a number I masked it in my example gateway4: 192.168.1.1 nameservers: addresses: [188.8.131.52,184.108.40.206] dhcp4: no wifis: wlan0: dhcp4: no dhcp6: no addresses: [192.168.1.5x/24] # note the x here is supposed to be a number I masked it in my example gateway4: 192.168.1.1 nameservers: addresses: [220.127.116.11,18.104.22.168] access-points: "network_ssid": password: "xxxxxxxxxxxxxxxxxx" version: 2
Few things to note
network_ssid is the name of your WIFI network, you will need the quotes around it, as with you need the quotes around the password for that network.
Save the file or hitting
control + X and then hit
enter. From there run the following command:
sudo netplan try
If you have your
yaml spacing correct all should work well. Feel free to remove the ethernet cable.
We need to enable cgroups and to do so we need to add a line to the
nobtcmd.txt to do so run the following command:
sudo nano /boot/firmware/cmdline.txt
Add this to the end of the file:
Save the file and reboot the Pi to do this run this command:
Now we are ready to use Snap to install MicroK8s:
sudo snap install microk8s --classic --channel=1.18/stable
This will take a few minutes. After this is done we can configure the network around this:
sudo iptables -P FORWARD ACCEPT
Next we need to upgrade the permission of the user
ubuntu so run the following command:
sudo usermod -a -G microk8s ubuntu logout
Once you logged back in to your Pi, you can start up MicroK8s:
We need to enable a few things as well:
microk8s.enable dns microk8s.enable storage microk8s.enable helm3
This post is an organized post of a few that I did in getting Kubernetes running on a Raspberry Pi. As I am using this for my Twitter bot I wanted to write this up for anyone following my project. MicroK8s on a Raspberry Pi is an easy place to run our Twitter bot.