Install K3S on Raspberry Pi [Complete setup]

I hope you enjoy reading this!
Don’t forget to share this blog with your friends.

Table of Contents
Install K3S on Raspberry Pi [Complete setup]

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. 

8 Raspberries pi cluster
8 Raspberries pi cluster

Pre-requirements for this setup?

  1. Raspberry
  2. 32GB SDCard
  3. Power supply for raspberry
  4. A micro SDCard adapter

What is K3S?

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. 

Here is the Video tutorial for this.

If you aren’t interesting to read all the text here you can also watch this video below,

Install K3S on Raspberry Pi

Step 1: Setup Raspberry Pi SSH

  1. Plug your SDCard into your micro SDCard adapter.
  2. Now plug the adapter into your main PC.
  3. Download Raspberry Pi imager from their download page.
  4. Open Raspberry Pi imager
  5. Click on “Choose Image” and then “Raspberry Pi OS (other)”
  6. Then choose “Raspberry Pi OS lite”
  7. Now choose your micro SDCard by clicking “Choose Storage”
  8. Then click on write, (confirm the write by click on yes)
  9. When it finishes remove your SDCard from your computer and plug it into your Raspberry Pi.
  10. Boot your Raspberry Pi
  11. Wait (5 min) to boot up Raspberry Pi.
  12. Now again unplug the SDCard from Raspberry Pi and plug it back into your computer.
  13. This time when you plug this SDCard into your PC you see a “Boot” disk, open it
  14. Here look for the “cmdline.txt” file and open it with your perfected text editor.
  15. Add the following line to the end of the line.
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
  1. Save this file and close
  2. Open another file labeled “config.txt”
  3. Add the following line to the button of the file.
arm_64bit=1
  1. Save this file and close

Now one last thing is to enable SSH on Raspberry Pi 

  1. To do that open Powershell in windows and terminal in Linux and Mac.
  2. Navigate to the “boot” drive
  3. Exclude the following command
# For windows
new-item ssh


# For Linux and Mac
touch ssh
  1. Unplug the micro SDCard from the PC and plug it into your Raspberry Pi .
  2. Boot the Raspberry Pi 

Step 2: Prepare for K3S

  1. SSH into your Raspberry Pi using the following command.
$ sudo ssh [email protected][IP_YOU_ASSIGN_TO_RASPBERRY_PI]
$ sudo ssh [email protected]
  1. Enter the password for Raspberry Pi

In most cases, the default password is “raspberry”

  1. Enable IPTABLE (requied for k3s)
$ sudo iptables -F
  1. Reboot the system once
$ reboot

Of course, this will disconnect your ssh, reconnect after 5 min.

Step 3: Install K3S in Raspberry Pi

  1. Download and install k3s by executing the following command
$ sudo curl -sfL https://get.k3s.io | K3S_KUBECONFIG_MODE=”644” sh -

This commend download and install k3s on your system

  1. (Optional) Verify K3s is properly installed by executing the following command
$ sudo kubectl get nodes

Step 4: (Optional) Add more nodes (machines or Raspberry Pi)

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.

  1. Now you need a master token from your first node or Raspberry Pi, execute the following command.
$ sudo cat /var/lib/rancher/k3s/server/node-token
# My Output:

K1089729d4ab5e51a44b1871768c7c04ad80bc6319d7bef5d94c7caaf9b0bd29efc::node:1fcdc14840494f3ebdcad635c7b7a9b7
  1. Copy the output (called a token)
  2. Respect the step 1 and 2 to get another ssh Raspberry Pi with new Raspberry Pi

Note: Do not repeat step 3

  1. SSH into the new Raspberry Pi you want to add as the node
$ ssh [email protected][IP_YOU_ASSIGN_TO_RASPBERRY_PI]
$ ssh [email protected]
  1. Install k3s on new node (knows as worker node)

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 -
  1. Close the ssh by executing the ‘exit’ command
$ exit
  1. To make sure your node is added to the master node, go to the master node and execute the following command
$ sudo kubectl get node

Congrats you successfully configure your cluster now you can do all the crazy stuff of Kubernetes.

Leave a Comment

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

Get an AMAZING ARTICLE for FREE that cost me 100$
Get an AMAZING ARTICLE for FREE that cost me 100$
Get inside Data of your Industry for FREE
You are only 2 steps away from complete research-based data.
This site uses cookies to improve your user experience.