Install K3S on Raspberry Pi, Nowadays Kubernetes is the most killer skill in IT, computer networking, or even in programming, I’ve been interested in building a Kubernetes cluster of Raspberry Pi(s). With Raspberry, we use k3s instead of k8s because k3s is lightweight and easy to set up.
So here in this tutorial, I am going to set up a cluster of 8 raspberries.
K3s is a lightweight version of Kubernetes that is all in a binary of less than 100 MB. K3s is developed by Rancher Labs on Feb 26, 2019. It’s highly available, fully CNCF (Cloud Native Computing Foundation) certified Kubernetes distribution designed for production workloads in unattended, resource-constrained, remote locations or inside IoT appliances.
If you aren’t interested to read all the text here you can also watch this video below,
Follow the given 3-step process.
cgroup_memory=1 cgroup_enable=memory ip=[ENTER_AN_IP_FOR_YOUR_RASPBERRY_PI]::[DEFULT_GATEWAY]:[SUBNET_MASK]:[NAME_FOR_RASPBERRY_PI]:[NETWORK_INTERFACE]:off
E.g:
cgroup_memory=1 cgroup_enable=memory ip=192.168.1.10::192.168.1.1:255.255.255.0:rpimaster:eth0:off
arm_64bit=1
Now one last thing is to enable SSH on Raspberry Pi
# For windows
new-item ssh
# For Linux and Mac
touch ssh
$ sudo ssh pi@[IP_YOU_ASSIGN_TO_RASPBERRY_PI]
$ sudo ssh pi@192.168.1.10
In most cases, the default password is “raspberry”
$ sudo iptables -F
$ reboot
Of course, this will disconnect your ssh, and reconnect after 5 min.
$ sudo curl -sfL https://get.k3s.io | K3S_KUBECONFIG_MODE=”644” sh -
This command download and install k3s on your system
$ sudo kubectl get nodes
NOTE: If you have only one Raspberry Pi then you properly skip this step, this step is all about adding more machines or Raspberry Pi in your k3s cluster.
$ sudo cat /var/lib/rancher/k3s/server/node-token
# My Output:
K1089729d4ab5e51a44b1871768c7c04ad80bc6319d7bef5d94c7caaf9b0bd29efc::node:1fcdc14840494f3ebdcad635c7b7a9b7
Note: Do not repeat step 3
$ ssh pi@[IP_YOU_ASSIGN_TO_RASPBERRY_PI]
$ ssh pi@192.168.1.11
Execute the following command
$ sudo curl -sfL https://get.k3s.io | K3S_TOKEN=”[THE_TOKEN_YOU_COPIED]” K3S_URL=”https://[YOUR_FRIST_RASPBERRY_PI]:6443” K3S_NODE_NAME=”[NAME_YOU_WANT]” sh -
# E.g:
$ sudo curl -sfL https://get.k3s.io | K3S_TOKEN=”K1089729d4ab5e51a44b1871768c7c04ad80bc6319d7bef5d94c7caaf9b0bd29efc::node:1fcdc14840494f3ebdcad635c7b7a9b7” K3S_URL=”https://192.168.1.10:6443” K3S_NODE_NAME=”rpi_worker_1” sh -
$ exit
$ sudo kubectl get node
Congrats you successfully configure your cluster now you can do all the crazy stuff of Kubernetes.
Now that I’ve got this cluster up and running, I can start playing around with all sorts of Kubernetes features and even use it for production purposes. It’s going to be a lot of fun experimenting with it all.
You also learned quite a bit about setting up Raspberry Pi and installing K3s on it. You even figured out how to add more nodes to the cluster and obtain the necessary tokens for it. It’s been a great learning experience overall.
If you’re looking for a fun project to try out, I highly recommend building your own Kubernetes cluster using Raspberry Pi. Not only will you get to work with Kubernetes firsthand, but you’ll also get to experiment with the capabilities of Raspberry Pi – it’s a win-win!
If you have any questions or comments, I’d love to hear from you. Just drop them in the comment section below. Happy coding, everyone!
This website uses cookies.
View Comments
How is storage handled on the cluster? Is, for example, the container for Minecraft replicated across all worker nodes, or is it migrated from one node to the next if the cluster decides to move it? I'm working on collecting the resources (RPIs) to build a K3s cluster, but was hoping there was a way to use shared storage, like a M.2 to USB HDD. Is there a better way to attach shared storage without a single point of failure?
This might answer your question if you haven't already gotten one....
https://llimon.github.io/post/k3s-nfs/