(1/8) Build your very own self-hosting platform with Raspberry Pi and Kubernetes - Introduction

Preface

Self-hosting is a new trend which attracts more people every day, whether you are looking for more privacy, or disapprove big SaaS companies methods to monetize your data or simply because you enjoy hacking things at home and challenge yourself. This series is for you!

The concept of self-hosting is usually defined by hosting an open-source software at home on your own machine and under your own network instead of relying on a third-party SaaS provider which usually comes with terms and conditions you might read and agree with or not. On one hand, SaaS/Cloud solutions are simple and easy, everything is taken care for you (hosting, maintenance, support) but at the cost of being sustainable which generally means for the end users: selling personal data (targeted advertising) or paying monthly subscription fees. On the other hand, depending on what software you will self-host, it could require strong technical IT knowledge, especially in networking and security to ensure your data are safe. But, as we all know, With great power comes great responsibility !

Another important concept is open-source software (OSS), giving access to anyone to the code of your software is ultimately the most transparent and effective way to insure security. It often relies on a community of passionate engineers to quickly respond to security holes without bureaucracy but bear in mind you need to pick a reputable open-source software which has both good code quality and an active community.

Here is a metaphor I really like about self-hosting:

Having a hosted website is like being a renter, rather than a homeowner.

On the one hand, you have a place to live and your landlord takes care of certain fees and maintenance.

On the other hand, you depend on the mercy of the landlord to keep things liveable for you, and you can’t redesign the house as you please.

source



Introduction

As I mentioned, self-hosting can be quite complicated and require knowledge. So in this series of articles, we will learn how to setup a Kubernetes cluster of Raspberry Pi computers to ensure the following properties for our containerized applications:

Before starting, let me explain a few important concepts here.


Container

As most modern software engineers can attest, containers have offered a dramatically more flexible way to run applications on virtual and physical environments. A container is a unit of software that packages up code and all its dependencies, it is portable from one environment to another, lightweight and secure (isolation by default).

Docker is currently the most known container software in the industry.


Why Kubernetes?

Now we know, it is easy to run containerized applications, we need an orchestrator to manage our applications across multiple hosts (machines), this will help automating most of the maintenance tasks (reboot after application or host crash, scaling, load balancing, configuration management, etc.).

Kubernetes (k8s) from Google is the market leader in container orchestration, it offers:

For those reasons, Kubernetes is a good choice to orchestrate our future self-hosting / homelab infrastructure!

Kubernetes comes with a lot of tools that aren't necessarily needed or optimized for ARM devices like the RaspberryPi so the company Rancher launched k3s, a lightweight Kubernetes ideal for IOT and Single-Board computers.


Why Raspberry Pi

A Raspberry Pi (RPI) is Single-Board Computer (SBC) initially launched in 2012 as an educational tool to learn programming but it actually quickly became very popular in the hardware and hacking communities and people now use RPI for hardware projects, home automation, robotics and much more...


Since 2012, the Raspberry Pi foundation launched several generations:

Product SoC Speed RAM USB Ports Ethernet Wireless Bluetooth
Raspberry Pi Model A+ BCM2835 700MHz 512MB 1 No No No
Raspberry Pi Model B+ BCM2835 700MHz 512MB 4 100Base-T No No
Raspberry Pi 2 Model B BCM2836/7 900MHz 1GB 4 100Base-T No No
Raspberry Pi 3 Model B BCM2837A0/B0 1200MHz 1GB 4 100Base-T 802.11n 4.1
Raspberry Pi 3 Model A+ BCM2837B0 1400MHz 512MB 1 No 802.11ac/n 4.2
Raspberry Pi 3 Model B+ BCM2837B0 1400MHz 1GB 4 1000Base-T 802.11ac/n 4.2
Raspberry Pi 4 Model B BCM2711 1500MHz 1GB 2xUSB2, 2xUSB3 1000Base-T 802.11ac/n 5.0
Raspberry Pi 4 Model B BCM2711 1500MHz 2GB 2xUSB2, 2xUSB3 1000Base-T 802.11ac/n 5.0
Raspberry Pi 4 Model B BCM2711 1500MHz 4GB 2xUSB2, 2xUSB3 1000Base-T 802.11ac/n 5.0
Raspberry Pi Zero BCM2835 1000MHz 512MB 1 No No No
Raspberry Pi Zero W BCM2835 1000MHz 512MB 1 No 802.11n 4.1
Raspberry Pi Zero WH BCM2835 1000MHz 512MB 1 No 802.11n 4.1

Raspberry Pi - Hardware history


The main benefits of using Raspberry Pi are:


Keep Control and Enjoy!

I have been hosting stuff by myself for a while now and I've always struggled with maintenance in the long run (service not working correctly on ARM, machine freeze, configuration management mess). So when I recently decided to migrate everything on Kubernetes, it has been quite challenging but finally got it working and I haven't touched it since, every single services are running like a charm, they may have crashed a couple of times but Kubernetes recovered everything without me noticing the downtime.



Hardware requirement

In order to build our self-hosting platform, we need the following hardware materials:


The result looks like this on my side for a total cost around $250 approximately:



Table of content

Alright, now we defined what we gonna do and why, let's get started!

  1. Introduction
  2. Install Raspbian Operating-System and prepare the system for Kubernetes
  3. Install and configure a Kubernetes cluster with k3s to self-host applications
  4. Deploy NextCloud on Kuberbetes: The self-hosted Dropbox
  5. Self-host your Media Center On Kubernetes with Plex, Sonarr, Radarr, Transmission and Jackett
  6. Self-host Pi-Hole on Kubernetes and block ads and trackers at the network level
  7. Self-host your password manager with Bitwarden
  8. Deploy Prometheus and Grafana to monitor a Kubernetes cluster

If you'd like to see an article in this series: please contact me on Twitter @gregjeanmart




References