# ricsanfre/pi-cluster architecture

> Architecture diagram of the GitHub repository ricsanfre/pi-cluster, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ricsanfre/pi-cluster
- Repository: https://github.com/ricsanfre/pi-cluster

## Overview

##### Main Components
- Hardware/Physical Layer:
– Raspberry Pi devices (ARM nodes) and refurbished x86 mini PCs that host the Kubernetes nodes.
– A separate firewall/router component (possibly running OpenWRT on a Raspberry Pi) to isolate the cluster.
- OS Provisioning and Bootstrapping:
– Cloud‑init configuration files (in the “metal” folder and in cloud‑init sub-directories) that prepare the nodes.
– PXE boot arrangements for x86 nodes.
- Configuration Management & Automation:
– Ansible playbooks and roles (located in the “ansible” and “ansible-runner” folders) that automate OS configuration, software installation, initial setup (DNS, certificates, etc.), and the deployment of Kubernetes (K3s) itself.
- GitOps and Kubernetes Application Management:
– FluxCD integration (with the Kubernetes manifests in the “kubernetes” folder and FluxCD templates) that applies helm charts and kustomizations to the cluster.
– The “kubernetes” folder organizes different clusters’ configurations, manifests for applications (e.g., cert-manager, keycloak, minio, longhorn, and others) for internal and external services.
- External Services and Integrations:
– External DNS, certificate management (Let’s Encrypt via Cert-Manager/Certbot), secrets management (Vault and External Secrets), and backup solutions (Velero/Restic).
– Additionally, legacy or externally hosted services (like a VM running Minio backup).

##### Relationships and Interactions
- “provisioning/bootstrapping” flow from the hardware to the node OS setup (cloud‑init, PXE).
– Cluster OS configuration,
– K3s installation, and
– External service configurations.
- How FluxCD is used as the GitOps engine that pulls manifests (from the “kubernetes” folders) and applies them to the K3s cluster.
- Direct interactions between cluster services (e.g., traffic flow from ingress controllers (NGINX vs. HAProxy) to services deployed on Kubernetes, integration with external DNS services, certificate authorities, and cloud backup providers).

##### Design Patterns and Architectural Principles
- Infrastructure as Code and GitOps methodology.
- Separation of concerns—distinct layers for hardware provisioning, configuration management (Ansible), and application deployment (FluxCD/Kubernetes manifests).
- Hybrid nature of the cluster (ARM and x86 nodes) and how network isolation is enforced by a dedicated firewall.

##### Relevant Technologies and Frameworks
- Cloud‑init, Ansible, K3s Kubernetes, FluxCD.
- Additional stack components: container runtime (containerd), CNI (Cilium), DNS (CoreDNS and ExternalDNS), load balancing (HAProxy, Ingress NGINX), storage (Longhorn, Minio), certificate management (Cert-Manager, Let’s Encrypt), secrets management (Vault, External Secrets), monitoring (Prometheus, Grafana, Loki, Fluentd/Fluent Bit, Tempo), service mesh (Istio), IAM (Keycloak, OAuth2 Proxy) and streaming/Kafka components.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Hardware/Physical Layer"
        A["Raspberry Pi Nodes (ARM)"]:::physical
        B["x86 Mini PCs"]:::physical
        C["Firewall/Router (OpenWRT)"]:::physical
    end

    subgraph "OS Provisioning and Bootstrapping"
        D["Cloud‑init Configuration"]:::bootstrap
        E["PXE Boot Files"]:::bootstrap
    end

    subgraph "Configuration Management & Automation"
        F["Ansible Automation (OS/K3s Deployment)"]:::automation
        G["Ansible Runner"]:::automation
        H["FluxCD CLI Integration"]:::automation
        I["External Services Automation"]:::automation
        J["Certbot Role (Let's Encrypt)"]:::automation
    end

    subgraph "K3s Cluster Management"
        K["K3s Kubernetes Cluster"]:::cluster
        L["FluxCD Operator (GitOps)"]:::cluster
    end

    subgraph "External Services & Integrations"
        M["DNS/Certificate Management"]:::external
        N["External Backup & Vault Services"]:::external
    end

    %% Hardware to Provisioning
    A -->|"provisions"| D
    C -->|"provisions"| D
    B -->|"triggers"| E

    %% Provisioning to Automation
    D -->|"initializes"| F
    E -->|"initializes"| F

    %% Automation internal support and flows
    G -->|"supports"| F
    F -->|"triggers"| H
    F -->|"deploys"| K
    F -->|"orchestrates"| I
    F -->|"orchestrates"| J

    %% GitOps Flow within Cluster Management
    L -->|"appliesManifests"| K

    %% Integration with External Services
    K -->|"integrates"| M
    K -->|"integrates"| N

    %% Click Events
    click A "https://github.com/ricsanfre/pi-cluster/tree/master/metal/rpi/cloud‑init/nodes"
    click B "https://github.com/ricsanfre/pi-cluster/tree/master/metal/x86/build"
    click C "https://github.com/ricsanfre/pi-cluster/tree/master/metal/rpi/cloud‑init/gateway"
    click D "https://github.com/ricsanfre/pi-cluster/tree/master/metal/rpi/cloud‑init"
    click E "https://github.com/ricsanfre/pi-cluster/tree/master/metal/x86/pxe‑files"
    click F "https://github.com/ricsanfre/pi-cluster/tree/master/ansible/"
    click G "https://github.com/ricsanfre/pi-cluster/tree/master/ansible‑runner/"
    click H "https://github.com/ricsanfre/pi-cluster/tree/master/ansible/roles/fluxcd‑cli"
    click I "https://github.com/ricsanfre/pi-cluster/blob/master/ansible/external_services.yml"
    click J "https://github.com/ricsanfre/pi-cluster/tree/master/ansible/roles/certbot"
    click L "https://github.com/ricsanfre/pi-cluster/tree/master/kubernetes/"

    %% Style Classes
    classDef physical fill:#a6e3a1,stroke:#333,stroke-width:2px;
    classDef bootstrap fill:#c3bef0,stroke:#333,stroke-width:2px;
    classDef automation fill:#a1cbe3,stroke:#333,stroke-width:2px;
    classDef cluster fill:#f3d1d1,stroke:#333,stroke-width:2px;
    classDef external fill:#f28e1c,stroke:#333,stroke-width:2px;
```
