Pi Kubernetes Cluster

pi-cluster-1.0

K3S Kubernetes Cluster at home automated with Ansible and FluxCD

This is an educational project to build a hybrid x86/ARM Kubernetes cluster at home, using Raspberry Pi and refurbished x86 mini PCs, learn to deploy basic kubernetes services and automate its deployment and configuration applying IaC (infrastructure as a code) and GitOps methodologies.

The entire process for creating this cluster at home, from cluster design and architecture to step-by-step manual configuration guides, has been documented and it is published in the project website: https://picluster.ricsanfre.com.

This repository contains all source code used to automate all manual tasks described in the documentation: Cloud-init’s configuration files, Ansible’s source code (playbooks/roles), and packaged Kubernetes applications (helm and kustomize) to be deployed using FluxCD.

Since its deployment is completely automated, the cluster can be re-deployed in minutes as many times as needed for testing new cluster configurations, new software versions or just take you out of any mesh you could cause playing with the cluster.

Scope

The scope of this project is to build a hybrid x86/ARM kubernetes cluster at home, using low cost Raspeberry PIs and old refurbished mini PCs, and automate its deployment and configuration applying IaC (infrastructure as a code) and GitOps methodologies with tools like Ansible, OpenTofu / Terraform, cloud-init and Flux CD.

As part of the project, the goal is to use a lightweight Kubernetes flavor based on K3S and deploy cluster basic services such as:

Also deployment of services for building a cloud-native microservices architecture are include as part of the scope:

  • Service mesh architecture, Istio
  • API security with Oauth2.0 and OpenId Connect, using IAM solution, Keycloak
  • Streaming platform, Kafka

Technology Stack

The following picture shows the set of opensource solutions used so far in the cluster, which installation process has been documented and its deployment has been automated with Ansible/FluxCD:

NameDescription
AnsibleAutomate OS configuration, external services installation and k3s installation and bootstrapping
FluxCDGitOps tool for deploying applications to Kubernetes
OpenTofuAutomate the provisioning of external services (Vault, DNS, S3 buckets, etc) required for the cluster operation
Cloud-initAutomate OS initial installation
UbuntuCluster nodes OS
OpenWRTRouter/Firewall OS
K3SLightweight distribution of Kubernetes
containerdContainer runtime integrated with K3S
cilium logoCiliumKubernetes Networking (CNI) and Load Balancer
CoreDNSKubernetes DNS
ExternalDNSExternal DNS synchronization
Kube-VIPKubernetes API Load-balancer
Envoy GatewayKubernetes Gateway API Controller
LonghornKubernetes distributed block storage
RustFSS3 Object Storage solution
Cert-managerTLS Certificates management
Hashicorp VaultSecrets Management solution
External Secrets OperatorSync Kubernetes Secrets from Hashicorp Vault
KeycloakIdentity Access Management
VeleroKubernetes Backup and Restore solution
ResticOS Backup and Restore solution
PrometheusMetrics monitoring and alerting
FluentdLogs forwarding and distribution
FluentbitLogs collection
LokiLogs aggregation
ElasticsearchLogs analytics
KibanaLogs analytics Dashboards
TempoDistributed tracing monitoring
GrafanaMonitoring Dashboards
IstioKubernetes Service Mesh
Strimzi KafkaKubernetes Operator for running Kafka streaming platform
CloudNative PosgreSQLKubernetes Operator for running PosgreSQL
MongoDB Kubernetes OperatorKubernetes Operator for running MongoDB
Valkey OperatorKubernetes Operator for running Valkey (Redis-compatible memory database)

Deprecated Technology

The following technologies have been used in previous releases of PiCluster but they have been deprecated and not longer maintained

NameDescription
Metal-LBLoad-balancer implementation for bare metal Kubernetes clusters. Replaced by Cilium CNI load balancing capabilities
TraefikKubernetes Ingress Controller. Replaced by NGINX Ingress Controller
ArgoCDGitOps tool. Replaced by FluxCD
FlannelKubernetes CNI plugin. Embedded into K3s. Replaced by Cilium CNI
HAProxyKubernetes API Load-balancer. Replaced by Kube-VIP
NGINX Ingress ControllerKubernetes Ingress Controller. Replaced by Envoy Gateway
OAuth2 ProxyOAuth2.0 Proxy. Replaced by Envoy Gateway with OIDC integration with Keycloak
MinIOS3 Object Storage. Replaced by RustFS after progressive degradation of open-source community edition

External Resources and Services

Even whe the premise is to deploy all services in the kubernetes cluster, there is still a need for a few external services/resources. Below is a list of external resources/services and why we need them.

Cloud external services

ProviderResourcePurpose
LetsencryptTLS CA AuthoritySigned valid TLS certificates
IONOSDNSDNS and DNS-01 challenge for certificates

NOTE: These resources are optional, the homelab still works without them but it won’t have trusted certificates

Alternatives:

  1. Use a private PKI (custom CA to sign certificates).
    Currently supported. Only minor changes are required. See details in Doc: Quick Start instructions.
  2. Use other DNS provider.
    Cert-manager / Certbot, which are the tools that automatically obtain certificates from Let’s Encrypt, can be configured to use other DNS providers. It will need further modifications in the way cert-manager application is deployed (new providers and/or webhooks/plugins might be required).
    Currently only acme issuer (letsencytp) using IONOS as dns-01 challenge provider is configured. Check list of supported dns01 providers.

Self-hosted external services

There is another list of services that I have decided to run outside the kubernetes cluster, self-hosting them.

External ServiceResourcePurpose
RustFSS3 Object StoreCluster Backup
Hashicorp VaultSecrets ManagementCluster secrets management

Vault and RustFS services are running in one of the cluster nodes, node1, to keep them locally accessible to the cluster and to avoid exposing them to the public internet.

Cluster architecture and hardware

Home lab architecture, showed in the picture below, consist of a Kubernetes cluster of ARM (Rasbperry PI) and x86 (HP elitedesk 800 G3 mini PCs) nodes and a firewall, built with another Raspberry PI, to isolate cluster network from your home network.

See further details about the architecture and hardware in the documentation

Official Site

You can browse more information about Pi Cluster Project on https://picluster.ricsanfre.com/.

The content of this website and the source code to build it (Jekyll static based website) are also stored in this repo: /docs folder.

Usage

Check out the documentation Quick Start guide to know how to use and tweak cloud-init files (/cloud-init folder), Ansible playbooks (/ansible folder) and packaged Kubernetes applications ( /kubernetes folder) contained in this repository, so you can use in for your own homelab.