# mrsauravsahu/kube-homelab architecture

> Architecture diagram of the GitHub repository mrsauravsahu/kube-homelab, 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/mrsauravsahu/kube-homelab
- Repository: https://github.com/mrsauravsahu/kube-homelab

## Overview

##### Main Components

a. Infrastructure Layer (Physical/Network):
- Hardware nodes: Raspberry Pi 4 and Raspberry Pi 5, Ubuntu Server running Docker.
- Operating system and prerequisites (systemd, key-based SSH, Docker).

b. Cluster Provisioning (Molecule: k3s):
- The “molecules/k3s” directory contains Terraform scripts for setting up k3s—a lightweight Kubernetes distribution.
- This module configures the control plane and node configuration.

c. Cluster Resources (Molecule: cluster-resources):
- The “molecules/cluster-resources” directory holds Terraform modules that define applications and other Kubernetes resources.
- It includes submodules for specific apps (e.g., Jellyfin, Nocodb, OwnCloud) and configuration for external services (Ingress controllers, databases, monitoring tools, etc.).
- It also makes use of Helm charts (e.g., in the “lib” and “apps” directories) for deploying some cluster applications.

d. Configuration & Deployment:
- Global configuration files (in “config”) and environment files (such as “.envrc” and “template.envrc”) for configuring Terraform backends or local state.
- CI/CD or deployment pipeline aspects might be implied by the segregation of modules/molecules.

##### Relationships and Interactions

- The system is structured in a layered manner where each layer depends on the components deployed in the prior, lower layer:
- The infrastructure layer (physical nodes) provides the underlying hardware and OS requirements.
- The k3s module sets up the Kubernetes cluster using Terraform.
- Once the cluster is ready, the cluster-resources module deploys various applications and service configurations on top of the running Kubernetes cluster.

- How Terraform orchestrates each molecule.
- The dependency of “cluster-resources” on the successful deployment of the “k3s” cluster.
- Interactions between external components (such as ingress controllers, databases, and external access endpoints) and the applications running inside the Kubernetes cluster.

##### Architectural Patterns and Key Principles

- Layered Architecture: Each deployment step (from infrastructure to cluster provisioning to running applications) is clearly separated.
- Modularity & Reusability: The use of “atoms” (small reusable pieces) and “molecules” (composed Terraform modules) allow for modular deployments.
- Infrastructure as Code (IaC): All configurations are defined in Terraform scripts with emphasis on structured module usage, environment segregation via separate backend state files, and clear file organization.
- Declarative Configuration: Both Kubernetes configurations (YAML files for pods, services, ingress, etc.) and Terraform definitions represent the desired state of the infrastructure.

## Diagram (Mermaid)

```mermaid
flowchart TD

    %% Documentation Section
    subgraph "Documentation"
        docs["Documentation"]:::docs
    end

    %% Configuration & Deployment
    subgraph "Configuration & Deployment"
        configNode["Global Configuration & Env Files"]:::config
    end

    %% Infrastructure Layer
    subgraph "Infrastructure Layer"
        infra1["Raspberry Pi 4 (Ubuntu Server, Docker)"]:::infra
        infra2["Raspberry Pi 5 (Ubuntu Server, Docker)"]:::infra
    end

    %% Cluster Provisioning
    subgraph "Cluster Provisioning"
        k3s["k3s Cluster Provisioning (Terraform)"]:::k3sModule
    end

    %% Cluster Resources
    subgraph "Cluster Resources"
        CR["Cluster Resources Module"]:::clusterRes
        subgraph "Apps Deployment"
            jellyfin["Jellyfin App"]:::app
            nocodb["Nocodb App"]:::app
            owncloud["OwnCloud App"]:::app
        end
        subgraph "External & Helm"
            externals["External Configurations"]:::external
            ingress["Ingress Helm Chart"]:::helm
            persistence["Persistence Helm Chart"]:::helm
            pv["Persistent Volume Helm Chart"]:::helm
        end
    end

    %% Connections
    configNode --> k3s
    infra1 --> k3s
    infra2 --> k3s
    k3s --> CR
    CR --> jellyfin
    CR --> nocodb
    CR --> owncloud
    CR --> externals
    CR --> ingress
    CR --> persistence
    CR --> pv

    %% Click Events
    click docs "https://github.com/mrsauravsahu/kube-homelab/blob/main/docs/images/kube-homelab.drawio.svg"
    click configNode "https://github.com/mrsauravsahu/kube-homelab/tree/main/config/"
    click k3s "https://github.com/mrsauravsahu/kube-homelab/tree/main/molecules/k3s"
    click CR "https://github.com/mrsauravsahu/kube-homelab/tree/main/molecules/cluster-resources"
    click jellyfin "https://github.com/mrsauravsahu/kube-homelab/tree/main/molecules/cluster-resources/apps/jellyfin"
    click nocodb "https://github.com/mrsauravsahu/kube-homelab/tree/main/molecules/cluster-resources/apps/nocodb"
    click owncloud "https://github.com/mrsauravsahu/kube-homelab/tree/main/molecules/cluster-resources/apps/owncloud"
    click externals "https://github.com/mrsauravsahu/kube-homelab/tree/main/molecules/cluster-resources/config/externals"
    click ingress "https://github.com/mrsauravsahu/kube-homelab/tree/main/molecules/cluster-resources/lib/helm-chart-homelab-ingress"
    click persistence "https://github.com/mrsauravsahu/kube-homelab/tree/main/molecules/cluster-resources/lib/helm-chart-openebs-persistence"
    click pv "https://github.com/mrsauravsahu/kube-homelab/tree/main/molecules/cluster-resources/lib/helm-chart-openebs-pv"

    %% Styles
    classDef docs fill:#D3D3D3,stroke:#333,stroke-width:2px
    classDef config fill:#FFD700,stroke:#333,stroke-width:2px
    classDef infra fill:#FF7F50,stroke:#333,stroke-width:2px
    classDef k3sModule fill:#87CEFA,stroke:#333,stroke-width:2px
    classDef clusterRes fill:#98FB98,stroke:#333,stroke-width:2px
    classDef app fill:#FFB6C1,stroke:#333,stroke-width:2px
    classDef external fill:#E0FFFF,stroke:#333,stroke-width:2px
    classDef helm fill:#FFFACD,stroke:#333,stroke-width:2px
```
