# alibaba/kubeskoop architecture

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

- Interactive diagram: https://gitdiagram.com/alibaba/kubeskoop
- Repository: https://github.com/alibaba/kubeskoop

## Overview

##### Main Components
- BPF Programs & Kernel Probes: Represent the low‐level eBPF programs (located in the “bpf” directory) that are built to monitor and capture kernel networking events. These include various C programs (flow.c, kprobe.c, etc.) and supporting header files.
- Controller/Orchestrator: Components under “cmd/controller” and related packages in “pkg/controller” handle core orchestration tasks such as configuration, database access (with options for MySQL or SQLite), telemetry collection, and interaction with Kubernetes (as seen in the “k8s” packages).
- Collector and Exporter Modules: The “cmd/collector”, “cmd/exporter”, and related packages under “pkg/exporter” implement data collection, event streaming, metric export (including Prometheus metric API and Loki log export), and utilize various probes from the “pkg/exporter/probe” sub-folders.
- BTF Hack Utility: A specialized component (cmd/btfhack and related packages) for handling BTF (BPF Type Format) integration, used to ensure CO-RE scripts work across different kernel versions.
- Web Console/UI: The “webui” directory provides a modern, interactive web-based interface that includes a backend (Go server code under webui/internal) and a frontend (React/TypeScript in webui/src) for user-friendly diagnosis, visualization (network graphs, dashboards), and interaction.
- RPC Communication and Messaging: The presence of “rpc” directories and protobuf definitions indicates internal communication between components (e.g., controller and exporter) via gRPC or similar RPC frameworks.
- Deployment/Configuration: The “deploy” directory with Helm charts, Kubernetes YAML manifests, and Vagrant scripts shows how the system is packaged and deployed in a real Kubernetes cluster.

##### Relationships and Interactions
- The Web Console (UI) interacts with backend services (controller and exporter) through defined API endpoints and possibly gRPC. Users initiate diagnostic or monitoring requests via the web interface.
- The Controller communicates with the Kubernetes APIs (using “pkg/controller/k8s”) to fetch cluster state and to trigger network diagnosis/pings or even reconfigure network probes.
- The Exporter modules deploy and manage eBPF programs (from the “bpf” directory via “pkg/exporter”) to capture real-time kernel events and network metrics. These are then forwarded to external systems like Prometheus and Loki.
- The BPF-based network probes send network events and metrics to the controller and exporters, which process the data and store it (in local databases, as seen with MySQL/sqlite DDLs).
- There is also an inter-component communication layer (using RPC, as defined in “pkg/controller/rpc” and the “rpc” folder) for sharing information like IP cache and alert events.

##### Architectural Patterns and Design Principles
- Separation of Concerns: The project separates responsibilities into discrete components (controller, exporter, collector, probe modules, web UI) that interact via defined interfaces.
- Microservices or Modular Design: Although deployed together in Kubernetes, the distinct “cmd” components suggest a modular approach that can be updated or scaled independently.
- Use of gRPC/RPC: Encapsulates communication between backend modules.
- Integration with Cloud and Kubernetes Services: The design includes k8s informers, IaaS integrations (e.g., in “pkg/skoop/infra/aliyun”), and deployment automation with Helm.

##### Relevant Technologies, Frameworks, and Libraries
- Language: Go is used extensively (go.mod and go.sum files).
- eBPF & BTF: Core components in the “bpf” folder and BTF hack utilities.
- Web Stack: Modern TypeScript/React frontend (in webui/src) and standard backend server in Go.
- Kubernetes: Native integrations via Kubernetes client libraries and deployment charts.
- Monitoring & Logging: Prometheus (for metrics), Grafana/Loki for logs and dashboards.
- RPC Framework: gRPC defined via protobuf files (inside pkg/controller/rpc and rpc directories).

##### Elements
- Components with Clear Labels:
- “eBPF Kernel Probes” (bpf programs)
- “Controller & Orchestrator”
- “Collector/Exporter Module”
- “RPC Communication Layer”
- “Web Console/UI”
- “External Integrations” (Kubernetes API, Prometheus, Grafana/Loki)
- Data flow from eBPF probes to Exporter, from Exporter to Controller, and from Controller to the Web UI.
- Bidirectional communication between the Controller and Kubernetes API.
- Flow of diagnostic requests initiated from the Web Console to the backend.
- With Technologies:
- Next to each component, note key technologies (e.g., “Go”, “eBPF”, “gRPC”, “React/TypeScript”, “Helm/Kubernetes”).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Kernel-Level Monitoring
    subgraph "Kernel-Level Monitoring"
        A["eBPF Kernel Probes"]:::kernel
    end

    %% Data Collection & Export
    subgraph "Data Collection & Export"
        B["Collector & Exporter Modules"]:::backend
        C["BTF Hack Utility"]:::utility
    end

    %% Control & Communication
    subgraph "Control & Communication"
        D["Controller & Orchestrator"]:::backend
        E["RPC Communication Layer"]:::rpc
    end

    %% User Interface
    subgraph "User Interface"
        F["Web Console/UI"]:::frontend
    end

    %% External Systems
    subgraph "External Systems"
        G["Kubernetes API"]:::external
        H["Prometheus"]:::external
        I["Grafana/Loki"]:::external
    end

    %% Deployment/Configuration (placed aside)
    J["Deployment/Configuration"]:::deploy

    %% Relationships
    A -->|"captures"| B
    A -->|"reports"| D
    B -->|"forwards"| D
    B -->|"utilizes"| C
    C -->|"integrates"| B

    D -->|"viaRPC"| E
    E -->|"viaRPC"| D
    E -->|"viaRPC"| B
    B -->|"viaRPC"| E

    D -->|"serves"| F
    F -->|"diagnostic"| D

    D <==>|"K8sAPI"| G

    B -->|"metrics"| H
    B -->|"logs"| I

    J -->|"deploys"| D
    J -->|"deploys"| B
    J -->|"deploys"| F

    %% Styles
    classDef kernel fill:#F9D3A4,stroke:#D2691E,stroke-width:2px;
    classDef backend fill:#B3D4FC,stroke:#1E90FF,stroke-width:2px;
    classDef utility fill:#C7F9CC,stroke:#228B22,stroke-width:2px;
    classDef rpc fill:#F9C6D3,stroke:#FF1493,stroke-width:2px;
    classDef frontend fill:#CDEBFF,stroke:#4682B4,stroke-width:2px;
    classDef external fill:#FDE2E2,stroke:#CD5C5C,stroke-width:2px;
    classDef deploy fill:#E2E2E2,stroke:#696969,stroke-width:2px;

    %% Click Events
    click A "https://github.com/alibaba/kubeskoop/tree/main/bpf/"
    click B "https://github.com/alibaba/kubeskoop/tree/main/cmd/collector"
    click B "https://github.com/alibaba/kubeskoop/tree/main/cmd/exporter"
    click B "https://github.com/alibaba/kubeskoop/tree/main/pkg/exporter/"
    click C "https://github.com/alibaba/kubeskoop/tree/main/cmd/btfhack"
    click C "https://github.com/alibaba/kubeskoop/tree/main/pkg/exporter/btfhack/"
    click D "https://github.com/alibaba/kubeskoop/tree/main/cmd/controller"
    click D "https://github.com/alibaba/kubeskoop/tree/main/pkg/controller/"
    click E "https://github.com/alibaba/kubeskoop/tree/main/pkg/controller/rpc"
    click E "https://github.com/alibaba/kubeskoop/tree/main/rpc/"
    click F "https://github.com/alibaba/kubeskoop/tree/main/webui/"
    click F "https://github.com/alibaba/kubeskoop/tree/main/webui/internal"
    click F "https://github.com/alibaba/kubeskoop/tree/main/webui/src"
    click J "https://github.com/alibaba/kubeskoop/tree/main/deploy/"
```
