Building a Kubernetes Cluster with Raspberry Pi (Part III)

Oct 14, 2020·
Diego Castro
Diego Castro
· 2 min read
blog
Warning

This series remained unfinished and I currently have no plans to continue it. Still, the published content may be useful.

This is the third part of a series of posts in which I explain how I built a Kubernetes cluster using Raspberry Pi. Here I show how I install Kubernetes using k3s.

PartTitle
P01Hardware
P02Operating System and Docker
P03K3S Cluster
P04Power Consumption

K3s

K3s is a certified Kubernetes distribution designed for the IoT and Edge Computing world. K3s has been optimized for ARM (ARM64 and ARMv7), and this is what made me choose this distribution to install Kubernetes on the Raspberry Pi cluster. K3s drastically reduces dependencies, making it possible to distribute it as a single binary of less than 40 MB. Reducing dependencies also simplifies the installation process.

Installation

The installation is very simple, since the K3s team has created an Ansible playbook to perform it. I based my setup on that playbook and applied a few small adaptations/improvements.

The first thing I did was adapt the inventory file to the playbook’s requirements. To do this, I defined the groups:

  • k3s_master: includes the master node
  • k3s_node: includes the worker nodes
  • k3s_cluster: includes all cluster members
[k3s_master:children]
rpicluster01

[k3s_node:children]
rpicluster02
rpicluster03
rpicluster04
rpicluster05

[k3s_cluster:children]
k3s_master
k3s_node

(You can see the full file here)

Below is the installation playbook:

- hosts: k3s_cluster
  gather_facts: true
  become: true
  roles:
    - role: prereq
    - role: download
    - role: ubuntu

- hosts: k3s_master
  become: true
  roles:
    - role: k3s/master

- hosts: k3s_node
  become: true
  roles:
    - role: k3s/node

As you can see, it is based on the use of roles. There are 3 preparation roles (prereq, download, and ubuntu) that will run on all members of the cluster. These roles enable certain necessary system configurations and download the correct binary depending on the architecture being targeted.

Additionally, there is a role that runs on the master node and another that runs on the worker nodes. These roles are the ones that actually create the K3s cluster.

(You can see the full playbook here)

Conclusion

Thanks to the K3s development team, who provides an Ansible playbook, it is possible to create a Kubernetes cluster in a very simple way.

Diego Castro
Authors
Computer Engineer

I am a computer engineer with over 15 years of experience, during which I have worked in a wide variety of environments and taken on different roles throughout the development lifecycle. This journey has allowed me to gain a broad understanding of the industry and to adapt easily to different technical and organizational contexts.

I have worked at large multinational consulting firms, participating in projects of various natures and collaborating with teams distributed across multiple countries. I have also experienced working in an early-stage startup, which gave me the opportunity to be involved in building a product from scratch and to gain firsthand insight into the challenges of the business world.

I am passionate about programming and maintain a continuous learning mindset. For me, the key is not mastering a specific language or framework, but the ability to learn, evolve, and deeply understand problems in order to provide robust solutions. Along this learning path, I have explored areas such as Data Science and Big Data, completing a master’s program that reflects my interest in broadening my horizons and understanding new technological perspectives.