# bashfulrobot/libvirt-talos architecture

> Architecture diagram of the GitHub repository bashfulrobot/libvirt-talos, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-18). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/bashfulrobot/libvirt-talos
- Repository: https://github.com/bashfulrobot/libvirt-talos

## Overview

##### Project Type and Purpose
This is an Infrastructure as Code (IaC) project that deploys a Talos Linux-based Kubernetes cluster using libvirt (KVM) virtualization. The project is designed to be consumed as a Terraform module.

##### Main Components

A. Infrastructure Layer:
- LibVirt/KVM Hypervisor
- Virtual Network (NAT/Route mode)
- Storage Volumes for VMs

B. Cluster Components:
- Control Plane Nodes (Multiple instances)
- Worker Nodes (Multiple instances)
- Virtual IP (VIP) for API Server
- Cilium CNI (Optional component)

C. Configuration Management:
- Talos Configuration System
- Machine Secrets
- Kubernetes Configuration

**┌─ Infrastructure Layer ─────────────────────┐**
- ┌─ LibVirt/KVM ──────────────────────────┐ │
- ┌─ Virtual Network ─────────────────┐   │ │
- (172.16.16.0/24)                │   │ │
- ┘   │ │
- ┌─ Storage ──────────────────────────┐ │ │
- VM Volumes                        │ │ │
- ┘   │ │
- ┘ │
- ┘

**┌─ Cluster Layer ──────────────────────────┐**
- ┌─ Control Plane ────┐ ┌─ Workers ─────┐ │
- CP1 CP2 CP3       │ │ WK1 WK2      │ │
- (172.16.16.10-12) │ │ (172.16.16.20+)│ │
- ┘ └───────────────┘ │
- ┌─ Network ────────────────────────────┐ │
- VIP: 192.168.1.79                   │ │
- Cilium CNI (Optional)               │ │
- ┘ │
- ┘

**┌─ Configuration Layer ────────────────────┐**
- ┌─ Talos ─────────┐ ┌─ Kubernetes ────┐ │
- Machine Secrets │ │ Kubeconfig     │ │
- Node Configs    │ │ API Endpoint   │ │
- ┘ └────────────────┘ │
- ┘

##### Important Relationships
- Network connections between nodes
- VIP relationship with control plane nodes
- Configuration flow from Talos to nodes
- Cilium's integration points

##### Additional Elements
- Version information for key components (Talos v1.9.1, K8s v1.31.3)
- IP address ranges and network details
- Resource specifications (CPU, Memory, Disk) for nodes

##### Notes for Implementation
- Clear labels for all components
- Optional nature of Cilium CNI
- State management consideration (local vs. remote)
- Factory image integration points

Remember to include a note about the sensitive nature of the configuration files (kubeconfig, talosconfig) and their state management considerations, as mentioned in the README.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Style Definitions
    classDef infrastructure fill:#a8d1f0,stroke:#2c3e50
    classDef cluster fill:#a8e6cf,stroke:#2c3e50
    classDef config fill:#ffd3b6,stroke:#2c3e50
    classDef network fill:#d4a5a5,stroke:#2c3e50
    classDef optional fill:#ffffff,stroke:#666666,stroke-dasharray: 5 5

    %% Infrastructure Layer
    subgraph InfrastructureLayer["Infrastructure Layer"]
        Provider["LibVirt/KVM Provider"]:::infrastructure
        Storage["Storage Volumes"]:::infrastructure
        VNet["Virtual Network<br/>(172.16.16.0/24)"]:::infrastructure
    end

    %% Cluster Layer
    subgraph ClusterLayer["Cluster Layer"]
        subgraph ControlPlane["Control Plane"]
            CP1["CP1<br/>172.16.16.10"]:::cluster
            CP2["CP2<br/>172.16.16.11"]:::cluster
            CP3["CP3<br/>172.16.16.12"]:::cluster
        end
        
        subgraph Workers["Worker Nodes"]
            WK1["WK1<br/>172.16.16.20"]:::cluster
            WK2["WK2<br/>172.16.16.21"]:::cluster
        end

        VIP["Virtual IP<br/>192.168.1.79"]:::network
        Cilium["Cilium CNI"]:::optional
    end

    %% Configuration Layer
    subgraph ConfigLayer["Configuration Layer"]
        TalosConfig["Talos Configuration"]:::config
        K8sConfig["Kubernetes Configuration"]:::config
        MachineSecrets["Machine Secrets"]:::config
        ConfigScripts["Configuration Scripts"]:::config
    end

    %% Relationships
    Provider --> Storage
    Provider --> VNet
    VNet --> CP1
    VNet --> CP2
    VNet --> CP3
    VNet --> WK1
    VNet --> WK2
    CP1 & CP2 & CP3 --> VIP
    Cilium -.-> CP1
    Cilium -.-> CP2
    Cilium -.-> CP3
    Cilium -.-> WK1
    Cilium -.-> WK2
    TalosConfig --> CP1
    TalosConfig --> CP2
    TalosConfig --> CP3
    TalosConfig --> WK1
    TalosConfig --> WK2
    K8sConfig --> VIP
    MachineSecrets --> TalosConfig
    ConfigScripts --> TalosConfig

    %% Click Events
    click VNet "https://github.com/bashfulrobot/libvirt-talos/blob/main/network.tf"
    click Provider "https://github.com/bashfulrobot/libvirt-talos/blob/main/providers.tf"
    click Cilium "https://github.com/bashfulrobot/libvirt-talos/blob/main/modules/cilium/main.tf"
    click CP1 "https://github.com/bashfulrobot/libvirt-talos/blob/main/patches/cp-scheduling.yaml"
    click TalosConfig "https://github.com/bashfulrobot/libvirt-talos/blob/main/talos.tf"
    click ConfigScripts "https://github.com/bashfulrobot/libvirt-talos/blob/main/helpers/get.config.files.sh"
    click ClusterLayer "https://github.com/bashfulrobot/libvirt-talos/blob/main/main.tf"
    click K8sConfig "https://github.com/bashfulrobot/libvirt-talos/blob/main/outputs.tf"
    click VIP "https://github.com/bashfulrobot/libvirt-talos/blob/main/variables.tf"
    click MachineSecrets "https://github.com/bashfulrobot/libvirt-talos/blob/main/locals.tf"
    click Storage "https://github.com/bashfulrobot/libvirt-talos/blob/main/sample/main.tf.sample"

    %% Legend
    subgraph Legend["Legend"]
        L1["Infrastructure Component"]:::infrastructure
        L2["Cluster Component"]:::cluster
        L3["Configuration Component"]:::config
        L4["Network Component"]:::network
        L5["Optional Component"]:::optional
    end
```
