A Raspberry Pi (rpi) could be used to create your own cloud platform. And the nice thing is it will do a great job for low cost.

I personally created this cluster to expand on my kubernetes knowledge before I take the CKA exam.

Building a cluster seemed like a good idea and allows more hands on / baremetal cluster experience.

Finding 4 pi’s for this project proved to be a challenge. The Covid-19 pandemic supply chain issues are still ongoing.

Luckily, I found https://www.rpilocator.com and scored a few rpis from the UK.

Cluster hardware:

My build is pretty simple, but I think it looks cool.

  • 4 Raspberry Pi 4B’s (at least 2GB of Ram)

  • Rpi cluster case

  • 4 PoE hats to power the pis

  • 5 port TP-Link PoE switch

  • 4 6in ethernet cables

  • 1 smart plug so I can turn the Pi off.

OS and Config

I prefer Arch variants of linux for my use. For this I installed Manjaro ARM edition (without the desktop environment). Which is a lightweight solution and a rolling release. (Latest software packages)

I plan to do often backups as rolling releases for servers are not the best idea because of potential stability issues. (unless it’s a dev environment) I haven’t had any issues yet. #KnockOnWood

Ansible

I am using Ansible to manage my cluster. I created a couple of playbooks to get things setup efficiently.

Inventory File

[all_rpis]
node1 ansible_host=192.168.100.55  
node2 ansible_host=192.168.100.56
node3 ansible_host=192.168.100.57  
node4 ansible_host=192.168.100.58

[all_rpis:vars]
ansible_python_interpreter = /usr/bin/python 
ansible_user=ansible 
ansible_ssh_private_key_file= "private key path"

[worker_nodes]
node2
node3 
node4

I created a symbolic link for the python interpreter path for manjaro.

Playbooks

First is to create the ansible user and password less sudo

- name: create ansible user with sudo 
  hosts: temp 
  become: true 
  tasks:
    - name: create ansible user 
      user: 
        name: ansible
        group: wheel 
        
    - name: copy ssh key 
      authorized_key: 
        user: ansible
        state: present
        key: "{{ lookup('file', 'path to pub key') }}"

    - name: Passwordless sudo for ansible user
      shell: "echo 'ansible ALL=(ALL) NOPASSWD:ALL' > /etc/sudoers.d/ansible"      

After those steps were complete, I installed the required packages and choose a k8s solution.

Choosing a kubernetes solution

I went with k3s. It’s a pretty lightweight package of kubernetes and optimized for ARM processesors (rpi’s use arm), while keeping most of the kubernetes features.

Getting started with K3s is easy.

Simple as running this command below. (Now you may want to view the script before installing)

curl -sfL https://get.k3s.io | sh -

My four pi’s ready for action!!

Exam

I will likely take the exam in the fall. So far I have deployed one of my python applications on the cluster. Eventually I will move all of my applications to the cluster!

You can also follow along with me on twitter.