# kubeop/k8s architecture

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

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

## Overview

##### Main Components
- Ansible Control Node: The host where the playbooks and roles are executed.
- Inventory and Variable Configurations: The “inventory” file and the “group_vars/all.yml” which provide runtime parameters for nodes.
- Roles: Various modular components, each representing tasks for deploying Kubernetes elements:
- Core Roles: “master”, “worker”, “etcd”, “containerd” for setting up key cluster components.
- Network and Addons Roles: “network-plugins” (including subdirectories for calico, cilium, flannel, kube-router, etc.), “addons” (e.g., coredns, nodelocaldns, metrics-server, nvidia device plugin, helm).
- Utility Roles: “init” (for node initialization), “download” (for obtaining installation packages), “reset” (for cleaning up nodes), and additional roles such as “keepalived”, “haproxy”, “cert” (for certificate management) which handle special configurations.
- External Dependencies:
- Operating systems and supported platforms (AlmaLinux, RockyLinux, Ubuntu, Debian, etc.).
- External URLs and repositories (GitHub repositories for Kubernetes, etcd, containerd, and various network/application components).

##### Relationships and Interactions
- The Ansible Control Node communicates with various target nodes via SSH using the provided inventory.
- Each role in the file tree maps to a specific functionality (e.g., “roles/master” deploys and configures Kubernetes control-plane components; “roles/worker” installs and configures node-level services).
- The playbooks orchestrate tasks in a sequential pipeline: from pre-deployment disk partitioning (using the “fdisk.yml” play) to downloading packages (via “download.yml”) to actual cluster provisioning (via “cluster.yml”).
- Certain roles interact indirectly; for example, during certificate regeneration the “cert” role updates configurations across multiple nodes and services.

##### Architectural Patterns and Design Principles
- Modularity: The project is split into discrete roles for each cluster component, making it extensible and maintainable.
- Parameterization and Environment Abstraction: Configuration files (inventory, group_vars) abstract environment-specific details.
- Idempotence: Ansible playbooks are structured to ensure repeatable actions, illustrated by tasks like formatting disks, generating certificates, and redeploying services.
- Separation of Concerns: Separation between cluster initialization, core components installation, network plugin setup, and cluster expansion or upgrade processes.
- Automation Pipelines: The integration of GitHub workflows and release management indicates a CI/CD approach for deploying updates.

##### Relevant Technologies and Frameworks
- Ansible (as the automation engine) including the recommended version, along with Python.
- Kubernetes and its core components (API Server, Controller Manager, Scheduler, etcd, kubelet, kube-proxy).
- Container runtime (containerd) and CRI tools (crictl).
- Network plugins (Calico, Cilium, Flannel, Kube-Router).
- -ons such as coredns, metrics-server, GPU plugins, and helm.
- Supporting tools like haproxy and keepalived for load balancing and high availability.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Control Layer
    subgraph "Control Layer"
        A["Ansible Control Node"]:::control
        INV["Inventory"]:::control
        GV["Global Variables"]:::control
        PY1["cluster.yml"]:::control
        PY2["download.yml"]:::control
        PY3["fdisk.yml"]:::control
        PY4["reset.yml"]:::control
    end

    %% Utility & Initialization Layer
    subgraph "Utility & Initialization"
        INIT["Init Role"]:::utility
        DOWN["Download Role"]:::utility
        RESET["Reset Role"]:::utility
    end

    %% Core Kubernetes Cluster
    subgraph "Core Kubernetes Cluster"
        MASTER["Master Role"]:::core
        WORKER["Worker Role"]:::core
        ETCD["etcd Cluster"]:::core
        CONTAINERD["Containerd Runtime"]:::core
    end

    %% Network & Add-ons Layer
    subgraph "Network & Add-ons"
        NP{"Select Network Plugin"}:::network
        CALICO["Calico"]:::network
        CILIUM["Cilium"]:::network
        FLANNEL["Flannel"]:::network
        KUBE_ROUTER["Kube-Router"]:::network
        ADDONS["Add-ons (coredns,metrics-server,helm)"]:::network
        GPU["GPU Drivers"]:::network
    end

    %% Ancillary Services Layer
    subgraph "Ancillary Services"
        HAPROXY["HAProxy"]:::ancillary
        KEEPALIVED["Keepalived"]:::ancillary
        CERT["Certificate Management"]:::ancillary
    end

    %% Connections from Control Layer
    INV --> A
    GV --> A
    A -->|"triggers"| PY1
    A -->|"triggers"| PY2
    A -->|"triggers"| PY3
    A -->|"triggers"| PY4
    PY3 -->|"initiates"| INIT
    PY2 -->|"initiates"| DOWN
    PY4 -->|"initiates"| RESET
    A -->|"orchestrates"| INIT
    A -->|"orchestrates"| DOWN
    A -->|"orchestrates"| RESET

    %% Connections from Utility to Core Kubernetes
    INIT -->|"prepares"| MASTER
    INIT -->|"prepares"| WORKER
    DOWN --> MASTER
    DOWN --> WORKER
    RESET --> MASTER
    RESET --> WORKER

    %% Core Kubernetes internal interactions
    MASTER -->|"configures"| ETCD
    MASTER -->|"configures"| CONTAINERD
    WORKER -->|"uses"| CONTAINERD

    %% Core to Network & Add-ons
    MASTER -->|"integrates"| NP
    WORKER --> NP
    NP --> CALICO
    NP --> CILIUM
    NP --> FLANNEL
    NP --> KUBE_ROUTER
    MASTER -->|"deploys"| ADDONS
    WORKER --> ADDONS
    MASTER --> GPU
    WORKER --> GPU

    %% Core to Ancillary Services
    MASTER -->|"supports"| HAPROXY
    MASTER -->|"supports"| KEEPALIVED
    MASTER -->|"updates"| CERT
    WORKER --> CERT

    %% Styling Classes
    classDef control fill:#AED6F1,stroke:#1B4F72,stroke-width:2px;
    classDef utility fill:#E8DAEF,stroke:#8E44AD,stroke-width:2px;
    classDef core fill:#A9DFBF,stroke:#1D8348,stroke-width:2px;
    classDef network fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
    classDef ancillary fill:#F5B7B1,stroke:#922B21,stroke-width:2px;

    %% Click Events for Control Layer
    click INV "https://github.com/kubeop/k8s/tree/main/inventory"
    click GV "https://github.com/kubeop/k8s/blob/main/group_vars/all.yml"
    click PY1 "https://github.com/kubeop/k8s/blob/main/cluster.yml"
    click PY2 "https://github.com/kubeop/k8s/blob/main/download.yml"
    click PY3 "https://github.com/kubeop/k8s/blob/main/fdisk.yml"
    click PY4 "https://github.com/kubeop/k8s/blob/main/reset.yml"

    %% Click Events for Core Kubernetes Deployment
    click MASTER "https://github.com/kubeop/k8s/blob/main/roles/master/tasks/main.yml"
    click WORKER "https://github.com/kubeop/k8s/blob/main/roles/worker/tasks/main.yml"
    click ETCD "https://github.com/kubeop/k8s/blob/main/roles/etcd/tasks/main.yml"
    click CONTAINERD "https://github.com/kubeop/k8s/blob/main/roles/containerd/tasks/main.yml"

    %% Click Events for Network Plugins & Add-ons
    click CALICO "https://github.com/kubeop/k8s/blob/main/roles/network-plugins/calico/tasks/main.yml"
    click CILIUM "https://github.com/kubeop/k8s/blob/main/roles/network-plugins/cilium/tasks/main.yml"
    click FLANNEL "https://github.com/kubeop/k8s/blob/main/roles/network-plugins/flannel/tasks/main.yml"
    click KUBE_ROUTER "https://github.com/kubeop/k8s/blob/main/roles/network-plugins/kube-router/tasks/main.yml"
    click ADDONS "https://github.com/kubeop/k8s/blob/main/roles/addons/tasks/coredns.yml"
    click GPU "https://github.com/kubeop/k8s/blob/main/roles/addons/tasks/nvidia-device-plugin.yml"

    %% Click Events for Utility & Initialization
    click INIT "https://github.com/kubeop/k8s/blob/main/roles/init/tasks/main.yml"
    click DOWN "https://github.com/kubeop/k8s/blob/main/roles/download/tasks/main.yml"
    click RESET "https://github.com/kubeop/k8s/blob/main/roles/reset/tasks/main.yml"

    %% Click Events for Ancillary Services
    click HAPROXY "https://github.com/kubeop/k8s/blob/main/roles/haproxy/tasks/main.yml"
    click KEEPALIVED "https://github.com/kubeop/k8s/blob/main/roles/keepalived/tasks/main.yml"
    click CERT "https://github.com/kubeop/k8s/blob/main/roles/cert/tasks/main.yml"
```
