# canonical/k8s-snap architecture

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

- Interactive diagram: https://gitdiagram.com/canonical/k8s-snap
- Repository: https://github.com/canonical/k8s-snap

## Overview

##### Main Components

a. Core Components:
- K8s Snap Package (central component)
- K8sd Daemon (control plane management)
- Kubernetes Components (apiserver, controller-manager, scheduler, kubelet)
- Database Layer (dqlite-based storage)
- Feature Management System
- PKI Infrastructure

b. Integration Components:
- Snap Interface Layer
- Configuration Management
- Networking Stack (Cilium/Calico)
- Service Proxy Layer
- Certificate Management

##### Architectural Layers

**┌─ User Interface Layer ─────────────────────┐**
- CLI Commands (k8s bootstrap, status)     │
- kubectl Integration                      │
- ┬───────────────────────┘
- ↓
**┌─ Control Layer ──────────────────────────┐**
- K8sd Daemon                            │
- Feature Controllers                    │
- Configuration Management               │
- ┬───────────────────────┘
- ↓
**┌─ Core Services Layer ────────────────────┐**
- Kubernetes Components                  │
- Database (dqlite)                     │
- Certificate Management                 │
- ┬───────────────────────┘
- ↓
**┌─ Infrastructure Layer ───────────────────┐**
- Snap System Integration               │
- Container Runtime (containerd)        │
- Networking (CNI)                      │
- ┘

##### Key Elements to Highlight

a. Control Flow:
- CLI command processing path
- Configuration propagation
- Feature enablement flow
- Certificate management flow

b. Data Flow:
- Cluster state management
- Configuration storage
- Certificate distribution
- Container image handling

##### Specific Implementation Details

Specialized components:
- Feature Management System (showing Cilium, CoreDNS, etc.)
- Certificate Management Infrastructure
- Snap Integration Points
- High Availability Components

##### Deployment View

- Single-node deployment
- Multi-node cluster configuration
- High-availability setup

##### The security and certificate management infrastructure

Remember to include version compatibility indicators and integration points with the broader Ubuntu/Snap ecosystem.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles
    classDef ui fill:#B3E5FC,stroke:#0288D1
    classDef control fill:#C8E6C9,stroke:#388E3C
    classDef core fill:#FFE0B2,stroke:#F57C00
    classDef infra fill:#E0E0E0,stroke:#616161
    classDef security fill:#E1BEE7,stroke:#7B1FA2
    classDef network fill:#FFCDD2,stroke:#D32F2F
    classDef database fill:#BBDEFB,stroke:#1976D2

    %% User Interface Layer
    subgraph UI
        CLI["CLI Commands"]
        KUBECTL["kubectl Integration"]
    end

    %% Control Layer
    subgraph Control
        K8SD["K8sd Daemon"]
        FEATCTL["Feature Controllers"]
        CONFMGMT["Configuration Management"]
    end

    %% Core Services Layer
    subgraph CoreServices
        K8SCOMP["Kubernetes Components"]
        DB["Database (dqlite)"]
        CERTMGMT["Certificate Management"]
    end

    %% Infrastructure Layer
    subgraph Infrastructure
        SNAP["Snap System Integration"]
        CONTAIN["Container Runtime"]
        NET["Networking Stack"]
    end

    %% Connections
    CLI --> K8SD
    KUBECTL --> K8SD
    K8SD --> FEATCTL
    K8SD --> CONFMGMT
    FEATCTL --> K8SCOMP
    CONFMGMT --> K8SCOMP
    K8SD --> DB
    K8SD --> CERTMGMT
    K8SCOMP --> SNAP
    K8SCOMP --> CONTAIN
    K8SCOMP --> NET

    %% Component Styling
    class CLI,KUBECTL ui
    class K8SD,FEATCTL,CONFMGMT control
    class K8SCOMP core
    class SNAP,CONTAIN,NET infra
    class CERTMGMT security
    class DB database

    %% Click Events
    click K8SD "https://github.com/canonical/k8s-snap/tree/main/src/k8s/cmd/k8sd/"
    click DB "https://github.com/canonical/k8s-snap/tree/main/src/k8s/pkg/k8sd/database/"
    click FEATCTL "https://github.com/canonical/k8s-snap/tree/main/src/k8s/pkg/k8sd/features/"
    click CERTMGMT "https://github.com/canonical/k8s-snap/blob/main/src/k8s/pkg/k8sd/setup/certificates.go"
    click CONFMGMT "https://github.com/canonical/k8s-snap/tree/main/src/k8s/pkg/k8sd/types/"
    click NET "https://github.com/canonical/k8s-snap/tree/main/src/k8s/pkg/k8sd/features/cilium/"
    click SNAP "https://github.com/canonical/k8s-snap/tree/main/src/k8s/pkg/snap/"
    click CLI "https://github.com/canonical/k8s-snap/tree/main/src/k8s/cmd/k8s/"
    click K8SCOMP "https://github.com/canonical/k8s-snap/tree/main/src/k8s/pkg/k8sd/setup/"
    click CONTAIN "https://github.com/canonical/k8s-snap/tree/main/k8s/wrappers/services/"

    %% Legend
    subgraph Legend
        L1["UI Components"]:::ui
        L2["Control Components"]:::control
        L3["Core Services"]:::core
        L4["Infrastructure"]:::infra
        L5["Security"]:::security
        L6["Database"]:::database
    end
```
