<< return

Portfolio

- Lui Crowie -

K8s Cluster on 4 Raspberry Pi's

Why?

I have had multiple cloud instances for development which are good and you can get a cheap instance for $5 (get $100 for 60 days on DigitalOcean and support me), but that money racks up. You have to make sure you stop (or in most cases, delete) those instances so you aren't billed for something you aren't using. You might say "spend more" but is it really worth it?


Incoming idea... I thought i'd invest into my own server, this idea isn't new by any means but a great project to do! I chose to use Raspberry Pi's as if/when I get a dedicated rack I can then repurpose them for many other uses that I might want to run agnostic of the rack. The ROI for the initial costs will be months but I will have tangible assests for ever!


Note - ROI calculated to be ~ 5 months for 13GB of RAM and ~5VCPU processing power, after that just power costs which is about 12pence/day @ full utilisation and around 5pence/day at idle/medium workload

What is it?

A Kubernetes cluster running all of my development and "prod" staging applications and services. It automatically scales, deploys, resolves and handles volumes across the 4 nodes. This is approximately the equivalent of 4 servers on a cloud provider. I have a Jenkins instance polling Github which handles all of the automated orchestration (building, tests, docker image creation, applying to kubes cluster, tagging etc.) from a push.


Also, when the cluster isn't in use, no SSH terminals have been opened or the utilisation of the individual Pi is less than 50% it will automatically spin up a custom-built miner image to mine a small amount of Crypto.


Some images of the final product;

Software

Below is a list of all of the software used/running on the cluster;

  • Kubernetes cluster on k3s by Rancher.
  • Docker - docker-compose, and self-hosted repository using a fully custom-made heirachy of images
  • Ubuntu 20.04 - Base OS
  • Lets Encrypt - Certificates and encryption
  • Jenkins (and a boat load of plugins) - Main orchestration
  • Qemu - For emulation of other architectures and OS'
  • ELK + Grafana Stack - Monitoring + Alerting
  • ServerSpec - Container/Image verification

Hardware

Below is a list of all of the hardware being used;

  • 3x Raspberry Pi Model 4b (4GB Edition)
  • 1x Raspberry Pi Model 3b (1GB Edition)
  • 5-Port L2 Netgear Managed Switch
  • 6-Port 60W Anker Power Supply
  • 4x 32GB SD Cards
  • 4x Custom length Cat5e Ethernet cables
  • 1x Micro HDMI + 1x HDMI (only used if needed to attach physically to a Pi)
  • 3x USB-C Power Cables + 1x Micro USB Power Cable
  • Zipties
  • 4-Rack Housing to hold the Pi's
  • 1x 256GB HDD in a USB 3.0 Housing

What did I do and learn?

A lot of scripting, from SD card burning, automating the whole setup of the instances for the worker and master nodes. A lot of configuration for it to all "talk nicely". Learning and understanding a lot of best practices for most of what I was implementing i.e. Dockerfiles.


Other things that I learnt was small low-level stuff like Kernel configuration and the pairing pattern of ethernet cables! I knew a lot of what I undertook before, but I went about implementing it in a secure, robust and best-practice manner which involved a bit of research and re-learning somethings that you might not have done in a number of months like parsing arrays in Shell!