Share:
Twitter
LinkedIn
Facebook
Reddit
Whatsapp
Follow by Email
Reading Time: 7 minutes

I am currently studying for the Certified Kubernetes Administrator exam (CKA) and as a hands on learning I wanted to get down and dirty with Kubernetes. In my day job I work a lot with Azure Kubernetes Service (AKS) and I would say I am very comfortable with AKS and managing Kubernetes objects on an AKS cluster. But with AKS and other managed Kubernetes offerings the control plane is handle by the provider, so you don’t get to see it, or configure it. That’s a really good thing for businesses, but not for people who want to study.

I was going to use an old HPE Microserver I have, but the noise was just too much. I was then going to use VM’s in Azure, but I was running out of credits and wanted something a bit more hands on. So, I decided to try and build a Raspberry Pi cluster. I wanted to use Ubuntu as the operating system as that is what I know and what is used in AKS, although an older version in the cloud. They have just started with 18.04. Ubuntu 20.04 is the latest LTS version, so I decided to go with that.

For the runtime, recently Kubernetes made the decision to use containerd as the container runtime. So, I thought let’s do that to. If I chose to use docker then it would have been a lot easier. In fact, if I had chosen to use say k3s then again it would have been a lot easier, but I would not have a pure Kubernetes cluster and no etcd datastore.

Well, that’s the background to this blog post, enough with all the words let’s get on with the build.

Getting started

First things first, you need the hardware, below is what i am using.

Hardware

Software

  • Windows subsystem for Linux (wsl2)
  • Linux distro setup in wsl2. I prefer ubuntu or pengwin
  • Nmap or another tool to search for pi’s IP (sudo apt-get install nmap)
  • Raspberry Pi imager (https://www.raspberrypi.org/software/)

Awesome, so your laptop and kit are ready to go. I won’t go through building the case, but make sure you have that done and all Pi’s are connected to the network.

Installing the OS

Pop an SD card into your computer, you may need a memory card reader for this.

Open the raspberry pi imager and click Choose OS

Then choose Ubuntu LTS 64 bit. It is under other general-purpose OS

Then choose your SD card. Please make sure it’s the right one as you will be wiping it and installing an OS over it)

Then click write.

Once written pop it in a Pi that you want to be the master. I have chosen the top of my rack. And power on the Pi.

After a while, the Pi will bot and get an IP address from your DHCP server. (home router). Open windows terminal and go to your Linux distro. Next type, changing the IP range to match your home network.

Shell

Find one called ubuntu.local that’s the IP you will use to ssh into the Pi.

In the same window type the following to ssh into the Pi. The username will be ubuntu by default and the default password is ubuntu. Type yes when promoted.

Shell

Password ubuntu

Change password and then reconnect using the same ssh command, you can press the up arrow.

Advice

Turn off the leds.
sudo nano /boot/firmware/syscfg.txt
 
Add the lines below to end of file and then reboot sudo reboot
 
#——–Onboard LEDs——–
# Disable the ACT LED
dtparam=act_led_trigger=none
dtparam=act_led_activelow=off
# Disable the PWR LED
dtparam=pwr_led_trigger=none
dtparam=pwr_led_activelow=off

Setting up the OS

First, you need to update the OS. Use the two commands below to do that. If you get a lock out/time out when running the second command, just reboot and try it again.

Shell

Now it is time to change the host Name. As you are setting up the control plane first, I am going to call it k8s-control01. For the worker nodes I would change the host name to something like k8s-worker01.

Shell

Then you need to edit the hosts file also.

Shell

Add 127.0.0.1 and hostname.

Save the changes and exit nano. Next perform a reboot for the changes to take.

Shell

Set IP

Ssh back into the node after a short while. You can use the up arrow to get to the previous command.

Now it’s time to set a static IP address. You could do this via your router/dhcp server, but for this guide, I am going to set it via the Pi.

Shell

Copy the below into the file and save and close nano.

Shell

Now use the next command to actually set the IP address.

Shell

In this file copy the below text but change the details to match your IP range.

Shell

Apply the changes by using the next command.

Shell

Now you need to edit the cloud-init file and delete all text apart from the comments.

Shell

Install containerd for the container runtime.

This is nice and simple to install the package just use the following command.

Shell

Now you just need to do a little bit of configuration.

Shell

Install Kubernetes

You need to add the kubernetes repo and GPG key. To do that just use the following.

Add GPG key

Shell

Add the Kubernetes repository

Shell

Next, you need to install the kubeadm, kublet and kubectl packages. Use the following to do that.

Shell

Now it is time to configure the memory cgroup. without this you will not be able to complete the setup. Just use the following command.

Shell

You will also need to disable swap. Again, this is nice and easy when you know the command.

Shell

Now it is time to give the Pi another reboot.

Shell

A bit more configuration

Ssh back into your Pi. It will be on the new IP address you set up earlier in this guide. You will need to type yes again, as it is a new IP address.

Now copy and paste the following.

Shell

Give containerd one last restart to make sure it has picked up the changes.

Shell

Start Kubernetes (Master only)

Warning

Stop here. The next bit is only needed to be done on the master. One time only. If you are joining a node, skip the next bit and go to Worker Nodes section.

First, you need to pull the container images needed for Kubernetes. You will be using kubeadm for this.

Shell

Now it is time to create the cluster. Kubeadm will do all the work for us. All you need to do is specify the pod network cidr.

Shell

Once it has been setup you will get an output like below. Keep it safe.

Shell

You will see from the output that you need to run some commands. Go ahead and run them.

The output also says you need to deploy a pod network to the cluster. I am using Flannel. You can instal it with the following.

Shell

After a short while check everything is up and running by using the following.

Shell

You are now ready to join the worker nodes.

Worker Nodes

Now repeat this guide till you get to the Start Kubernetes (Master only) section. Once you have gotten there come back here.

Adding worker node to the Cluster

So, when you created the control node you were given a command to use to join the workers to the cluster. You just now need to run that, but make sure you put sudo in front.

Shell

Now ssh back to the Control node and run kubectl get nodes -o wide to see the new worker node.

Continue to add the rest of your worker nodes to the cluster. You now have your very own Kubernetes cluster running on Raspberry Pi’s! How cool is that.

Thanks for reading. Let me know if you have any questions or comments and why not let me know what you are planning to do with your cluster.

Share:
Twitter
LinkedIn
Facebook
Reddit
Whatsapp
Follow by Email

Pixel Robots.

I’m Richard Hooper aka Pixel Robots. I started this blog in 2016 for a couple reasons. The first reason was basically just a place for me to store my step by step guides, troubleshooting guides and just plain ideas about being a sysadmin. The second reason was to share what I have learned and found out with other people like me. Hopefully, you can find something useful on the site.

13 Comments

Plamen · April 14, 2021 at 3:54 pm

Really good article! I’m going to do a similar setup very soon and I”ll definitely refer back to your blog.
I’m wondering will it work on the default raspberry pi OS instead of using Ubuntu?

    Pixel Robots. · April 15, 2021 at 4:51 pm

    I am not too sure, but I feel like it will. Let me know if you try.

Steven Dillon · July 7, 2021 at 7:30 pm

I just read this article and ordered this. Can’t wait to get started. Great article, thanks Steve

    Pixel Robots. · July 7, 2021 at 7:35 pm

    Awesome news. Let me know how you get on.

      Steven Dillon · August 3, 2021 at 8:59 pm

      Got me a 4 node K8s cluster ta very much. Great article, got anything on installing and configuring ISTIO.

        Pixel Robots. · August 5, 2021 at 12:31 pm

        I don’t have anything on ISTIO unfortunately. Do you really need it? Maybe look at Linkerd instead. I’s much more light weight.

        Alvaro · September 16, 2021 at 5:42 pm

        Hi,

        Not yet…

        https://github.com/istio/istio/issues/21094

        Thanks a lot

Alvaro · September 16, 2021 at 5:40 pm

Hi,

With this Raspberry PI CLuster…How you can simulate StorageClass???

I need learn this one for the CKA Certification too 😀

Thanks a los,

will · November 26, 2021 at 3:08 am

this command:
containerd config default /etc/containerd/config.toml

should contain the redirect to the file:
containerd config default > /etc/containerd/config.toml

Will · November 26, 2021 at 4:38 am

Also found I had to run:
sudo apt install linux-modules-extra-raspi && reboot
at a point in the middle to make sure that vxlan kern module was loaded.
this issue manifested by displaying:
The connection to the server x.x.x.x:6443 was refused – did you specify the right host or port?
at the point I was trying to install flannel on the system.
I also installed netstat, and firewall-cmd to troubleshoot, and added 6443 to my allowed ports:
sudo firewall-cmd –permanent –add-port=6443/tcp
and had to reboot after that.
That all seemed to do the trick as then the commands you had above worked fine.

I had bought the set of 3 raspberry pis with the intent to learn more about kubernetes in general.
Thanks for the tutorial, even with the additions this was by far the easiest one I came across.

    Will · November 26, 2021 at 4:41 am

    I think my other comment deleted my first one, here goes again:
    containerd config default /etc/containerd/config.toml

    should be:
    containerd config default > /etc/containerd/config.toml

Will · November 26, 2021 at 4:42 am

containerd config default /etc/containerd/config.toml
should have been written like this:
containerd config default > /etc/containerd/config.toml
Also found I had to run:
sudo apt install linux-modules-extra-raspi && reboot
at a point in the middle to make sure that vxlan kern module was loaded.
this issue manifested by displaying:
The connection to the server x.x.x.x:6443 was refused – did you specify the right host or port?
at the point I was trying to install flannel on the system.
I also installed netstat, and firewall-cmd to troubleshoot, and added 6443 to my allowed ports:
sudo firewall-cmd –permanent –add-port=6443/tcp
and had to reboot after that.
That all seemed to do the trick as then the commands you had above worked fine.

I had bought the set of 3 raspberry pis with the intent to learn more about kubernetes in general.
Thanks for the tutorial, even with the additions this was by far the easiest one I came across.

Borey · December 13, 2021 at 5:15 am

Great article! Thanks!

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *