# k0sproject/k0s architecture

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

- Interactive diagram: https://gitdiagram.com/k0sproject/k0s
- Repository: https://github.com/k0sproject/k0s

## Overview

##### Main Components Identification
The system should be divided into these major components:

a. Core Components:
- Controller plane
- Worker plane
- API Server
- Embedded binaries (containerd, etcd, etc.)
- Configuration management
- Autopilot system

b. Supporting Components:
- Networking layer (CNI)
- Storage layer (CSI)
- Container runtime (CRI)
- Authentication/Authorization
- Monitoring & Metrics

**┌─ k0s Cluster ──────────────────────────────────────┐**
- ┌─ Control Plane ─────┐    ┌─ Worker Nodes ─────┐ │
- API Server        │    │ - Kubelet          │ │
- Controller Manager│    │ - Container Runtime│ │
- Scheduler        │    │ - kube-proxy       │ │
- etcd/SQLite      │    │ - CNI Plugin       │ │
- ┘    └──────────────────────┘ │
- ┘

##### Implementation Notes

- Maintain clean spacing and alignment
- Version compatibility matrix
- Notes for specific platform requirements
- Document scaling capabilities

**┌─ Infrastructure Layer ─┐**
- Host OS             │
- Hardware Resources  │
- ┘
- ↓
**┌─ k0s Core Layer ──────┐**
- Single Binary      │
- Embedded Components│
- ┘
- ↓
**┌─ Kubernetes Layer ────┐**
- Control Plane      │
- Worker Components  │
- ┘
- ↓
**┌─ Extension Layer ─────┐**
- CNI Plugins        │
- Storage Plugins    │
- ┘

Remember to emphasize k0s's unique features like:
- Single binary distribution
- Zero dependencies
- Multiple storage backend support
- Flexible deployment options
- Automatic lifecycle management

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Infrastructure
        Host[Host OS]
        Hardware[Hardware Resources]
        Host --> Hardware
    end

    subgraph Core["k0s Core Layer"]
        SingleBinary[Single Binary Distribution]:::core
        EmbeddedBins[Embedded Binaries]:::core
        Config[Configuration Management]:::core
        TokenMgmt[Token Management]:::core
        Supervisor[System Supervisor]:::core

        click EmbeddedBins "https://github.com/k0sproject/k0s/tree/main/embedded-bins/"
        click Config "https://github.com/k0sproject/k0s/tree/main/pkg/config/"
        click TokenMgmt "https://github.com/k0sproject/k0s/tree/main/pkg/token/"
        click Supervisor "https://github.com/k0sproject/k0s/tree/main/pkg/supervisor/"
    end

    subgraph K8s["Kubernetes Layer"]
        direction TB
        subgraph ControlPlane["Control Plane Components"]
            direction TB
            APIServer[API Server]:::controller
            ControllerMgr[Controller Manager]:::controller
            Scheduler[Scheduler]:::controller
            Storage[Storage Backend]:::controller
            Metrics[Monitoring & Metrics]:::controller
            Auth[Authentication]:::security
        end

        subgraph WorkerPlane["Worker Components"]
            direction TB
            Kubelet[Kubelet]:::worker
            ContainerRT[Container Runtime]:::worker
            KubeProxy[Kube Proxy]:::worker
        end

        click APIServer "https://github.com/k0sproject/k0s/blob/main/pkg/component/controller/apiserver.go"
        click Storage "https://github.com/k0sproject/k0s/tree/main/pkg/etcd/"
        click Metrics "https://github.com/k0sproject/k0s/blob/main/pkg/component/controller/metrics.go"
        click Auth "https://github.com/k0sproject/k0s/tree/main/pkg/certificate/"
        click ContainerRT "https://github.com/k0sproject/k0s/tree/main/pkg/component/worker/containerd/"
    end

    subgraph Extensions["Extension Layer"]
        CNI[Network Plugins]:::network
        CSI[Storage Plugins]:::storage
        Autopilot[Autopilot System]:::management

        click CNI "https://github.com/k0sproject/k0s/tree/main/static/manifests/calico/"
        click Autopilot "https://github.com/k0sproject/k0s/tree/main/pkg/autopilot/"
    end

    %% Connections
    Host --> SingleBinary
    SingleBinary --> EmbeddedBins
    SingleBinary --> Config
    Config --> ControlPlane
    Config --> WorkerPlane
    TokenMgmt --> Auth
    Supervisor --> ControlPlane
    Supervisor --> WorkerPlane
    ControlPlane --> WorkerPlane
    WorkerPlane --> CNI
    WorkerPlane --> CSI
    Autopilot --> ControlPlane
    Autopilot --> WorkerPlane

    %% Styles
    classDef core fill:#b8d4ff,stroke:#333,stroke-width:2px
    classDef controller fill:#aed581,stroke:#333,stroke-width:2px
    classDef worker fill:#fff176,stroke:#333,stroke-width:2px
    classDef network fill:#81d4fa,stroke:#333,stroke-width:2px
    classDef storage fill:#ffb74d,stroke:#333,stroke-width:2px
    classDef security fill:#ef9a9a,stroke:#333,stroke-width:2px
    classDef management fill:#ce93d8,stroke:#333,stroke-width:2px

    %% Legend
    subgraph Legend
        L1[Core Components]:::core
        L2[Controller Components]:::controller
        L3[Worker Components]:::worker
        L4[Network Components]:::network
        L5[Storage Components]:::storage
        L6[Security Components]:::security
        L7[Management Components]:::management
    end
```
