# nvidia/k8s-device-plugin architecture

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

- Interactive diagram: https://gitdiagram.com/nvidia/k8s-device-plugin
- Repository: https://github.com/nvidia/k8s-device-plugin

## Overview

##### Main Components
- Kubernetes Cluster: Show the cluster environment where nodes run the DaemonSet.
- Device Plugin DaemonSet: Represent the NVIDIA device plugin deployed via DaemonSet. This includes different executable command binaries found in the “cmd” directory such as:
- nvidia-device-plugin (the main executable)
- gpu-feature-discovery (for automatic GPU labeling)
- mps-control-daemon (for MPS support)
- config-manager (to manage configurations)
- API and Configuration: Include the “api/config” packages that define the configuration version and flags that support both command-line and file-based configuration (supporting dynamic configuration via ConfigMap).
- Internal Libraries: Represent key internal packages that handle critical tasks:
- internal/cuda – dealing with CUDA operations and interfacing with drivers
- internal/mig – managing Multi-Instance GPU (MIG) functions
- internal/resource – managing GPU resource discovery and allocation details
- internal/plugin – orchestrating plugin-specific logic (including aspects of passing device specs, managing options, etc.)
- internal/rm – resource management with allocation, health checking, and configuration updates.
- Deployment Mechanisms: Show the integration with Helm for deployment and how the plugin leverages ConfigMaps for dynamic reconfiguration (which can be tailored per-node via node labels as described in the README).
- Underlying NVIDIA Components: Outside the containerized world, illustrate that the plugin interacts with the NVIDIA drivers, nvidia-container-runtime, and lower-level GPU device files (using concepts like “PASS_DEVICE_SPECS”, “DEVICE_LIST_STRATEGY”, etc.)

##### Relationships and Interactions
- Inside each node, show how the plugin (via its different executables) communicates with:
- The underlying container runtime (e.g., injecting environment variables or volume mounts to specify NVIDIA devices).
- The GPU drivers installed on the host (using configuration such as NVIDIA_DRIVER_ROOT).
- Use annotations or labels to indicate that various configuration options (MIG strategy, device ID strategy, etc.) come via command-line flags, environment variables, or external ConfigMaps (as shown via the “api/config”, “cmd/config-manager”, and “helm/deployments” directories).
- Integration with gpu-feature-discovery, which enriches nodes with GPU labels for scheduling.
- For the MPS and time-slicing mechanisms, highlight that there are distinct processes (e.g., mps-control-daemon and associated libraries) that modify how device allocations are handled.

##### Architectural Patterns or Design Principles
- Separation of concerns:
- The configuration layer (configuration files, flags, and ConfigMap logic).
- The resource discovery and management layer (inside internal/resource, internal/rm, internal/mig).
- The daemon/application layer (all binaries under the cmd directory).
- Present the deployment architecture (Helm chart driven, Kubernetes DaemonSet) demonstrating extensibility and multi-node support.
- Use of standard Kubernetes design (via device plugins) and integration with container runtimes (showing strategies like “envvar”, “volume-mounts”, “cdi-annotations”).

##### Relevant Technologies, Frameworks, and Libraries
- Golang for implementation (build scripts like Makefile and go.mod files show this).
- Docker (and container images) as evident from the Dockerfile in the “deployments/container” directory.
- Helm for deployment configuration.
- Kubernetes (device plugin API, DaemonSet, node labels, ConfigMap configuration).
- NVIDIA SDK components such as CUDA libraries and nvidia-container-runtime.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Kubernetes Cluster
    subgraph "Kubernetes Cluster"
        A["Kubernetes API Server"]:::external
        D["NVIDIA Device Plugin DaemonSet"]:::k8s
    end

    %% Deployment Layer
    subgraph "Deployment Layer"
        H["Helm Deployment"]:::helm
        CM["ConfigMap/Config Files"]:::config
    end

    %% Node Components
    subgraph "Node"
        direction TB
        CR["Container Runtime"]:::external
        ND["GPU Drivers & Device Files"]:::external
        dp1["nvidia-device-plugin"]:::plugin
        dp2["gpu-feature-discovery"]:::plugin
        dp3["mps-control-daemon"]:::plugin
        dp4["config-manager"]:::plugin
        configApi["Configuration API"]:::config
        libCuda["CUDA Operations (internal/cuda)"]:::lib
        libMig["MIG Management (internal/mig)"]:::lib
        libRes["GPU Discovery (internal/resource)"]:::lib
        libPlugin["Plugin Orchestration (internal/plugin)"]:::lib
        libRM["Resource Management (internal/rm)"]:::lib
    end

    %% Connections from external cluster and deployment
    A -->|"schedules"| D
    H -.->|"deploys"| D
    CM -.->|"configures"| D

    %% DaemonSet spawning executables on each node
    D --> dp1
    D --> dp2
    D --> dp3
    D --> dp4

    %% Interactions within each node
    dp1 -->|"interacts"| CR
    dp1 -->|"uses"| ND
    dp1 -->|"calls"| libRes
    dp1 -->|"orchestrates"| libPlugin
    dp1 -->|"invokes_CUDA"| libCuda
    dp1 -->|"health_check"| libRM

    dp2 -->|"labels_nodes"| H
    dp2 -->|"config_access"| configApi

    dp3 -->|"manages_MPS"| libMig
    dp3 -->|"uses_driver"| ND

    dp4 -->|"manages_config"| configApi

    configApi --> dp1
    configApi --> dp3
    configApi --> dp4

    %% Click Events
    click D "https://github.com/nvidia/k8s-device-plugin/tree/main/deployments/helm/nvidia-device-plugin"
    click dp1 "https://github.com/nvidia/k8s-device-plugin/tree/main/cmd/nvidia-device-plugin"
    click dp2 "https://github.com/nvidia/k8s-device-plugin/tree/main/cmd/gpu-feature-discovery"
    click dp3 "https://github.com/nvidia/k8s-device-plugin/tree/main/cmd/mps-control-daemon"
    click dp4 "https://github.com/nvidia/k8s-device-plugin/tree/main/cmd/config-manager"
    click configApi "https://github.com/nvidia/k8s-device-plugin/tree/main/api/config"
    click libCuda "https://github.com/nvidia/k8s-device-plugin/tree/main/internal/cuda"
    click libMig "https://github.com/nvidia/k8s-device-plugin/tree/main/internal/mig"
    click libRes "https://github.com/nvidia/k8s-device-plugin/tree/main/internal/resource"
    click libPlugin "https://github.com/nvidia/k8s-device-plugin/tree/main/internal/plugin"
    click libRM "https://github.com/nvidia/k8s-device-plugin/tree/main/internal/rm"
    click H "https://github.com/nvidia/k8s-device-plugin/tree/main/deployments/helm/nvidia-device-plugin"

    %% Style Definitions
    classDef k8s fill:#ffcccc,stroke:#cc0000,stroke-width:2px;
    classDef plugin fill:#ccffcc,stroke:#006600,stroke-width:2px;
    classDef config fill:#ccccff,stroke:#0000cc,stroke-width:2px;
    classDef lib fill:#ffffcc,stroke:#999900,stroke-width:2px;
    classDef external fill:#e6e6e6,stroke:#666666,stroke-width:2px;
    classDef helm fill:#ffebcc,stroke:#e69500,stroke-width:2px;
```
