Volcano vgpu device plugin for Kubernetes
Note:
Volcano vgpu device-plugin can provide device-sharing mechanism for NVIDIA devices managed by volcano.
This is based on Nvidia Device Plugin, it uses HAMi-core to support hard isolation of GPU card.
And collaborate with volcano, it is possible to enable GPU sharing.
Table of Contents
- Preparing your GPU Nodes - Enabling vGPU Support in Kubernetes - Testing without real GPUs (nvml-mock) - Running vGPU JobsVersion Compatibility Matrix
The following table shows the compatibility matrix between Volcano-vgpu and Volcano versions. Please ensure you are using compatible versions.
| Volcano-vgpu | Volcano | |--------------|---------| | v1.12.0 and below | v1.15.0 and below | | master | master |
About
The Volcano device plugin for Kubernetes is a Daemonset that allows you to automatically:
- Expose the number of GPUs on each node of your cluster
- Keep track of the health of your GPUs
- Run GPU enabled containers in your Kubernetes cluster.
- Provide device-sharing mechanism for GPU tasks as the figure below.
- Enforce hard resource limit in container.
- Support dynamic-mig, for more details, see config
Prerequisites
The list of prerequisites for running the Volcano device plugin is described below:
- NVIDIA drivers > 440
- nvidia-docker version > 2.0 (see how to install and it's prerequisites#prerequisites))
- docker configured with nvidia as the default runtime.
- Kubernetes version >= 1.16
- Volcano verison >= 1.9
Quick Start
Preparing your GPU Nodes
The following steps need to be executed on all your GPU nodes. This README assumes that the NVIDIA drivers and nvidia-docker have been installed.
Note that you need to install the nvidia-docker2 package and not the nvidia-container-toolkit.
This is because the new --gpus options hasn't reached kubernetes yet. Example:
# Add the package repositories
$ distribution=$(. /etc/os-release;echo $ID$VERSION_ID)
$ curl -fsSL https://nvidia.github.io/nvidia-docker/gpgkey | sudo gpg --dearmor -o /usr/share/keyrings/nvidia-docker-keyring.gpg
$ curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.list | \
sed 's#deb https://#deb [signed-by=/usr/share/keyrings/nvidia-docker-keyring.gpg] https://#g' | \
sudo tee /etc/apt/sources.list.d/nvidia-docker.list
$ sudo apt-get update && sudo apt-get install -y nvidia-docker2
$ sudo systemctl restart docker
You will need to enable the nvidia runtime as your default runtime on your node.
We will be editing the docker daemon config file which is usually present at /etc/docker/daemon.json:
{
"default-runtime": "nvidia",
"runtimes": {
"nvidia": {
"path": "/usr/bin/nvidia-container-runtime",
"runtimeArgs": []
}
}
}
if runtimes is not already present, head to the install page of nvidia-docker
Configuration
You need to enable vgpu in volcano-scheduler configMap:
``shell script
kubectl edit cm -n volcano-system volcano-scheduler-configmap
yaml
kind: ConfigMap
apiVersion: v1
metadata:
name: volcano-scheduler-configmap
namespace: volcano-system
data:
volcano-scheduler.conf: |
actions: "enqueue, allocate, backfill"
tiers:
- plugins:
- name: priority
- name: gang
- name: conformance
- plugins:
- name: drf
- name: deviceshare
arguments:
deviceshare.VGPUEnable: true # enable vgpu
deviceshare.SchedulePolicy: binpack # scheduling policy. binpack / spread
- name: predicates
- name: proportion
- name: nodeorder
- name: binpack
For volcano v1.9+,, use the following configMap### Sharing Mode
Volcano-vgpu supports two types of device-sharing: HAMi-core and dynamia-mig, A node can either using HAMi-core, or Dynamic-mig. Heterogeneous is supported(a part of node using HAMi-core, the other using Dynamic-mig)
A brief introduction about these two modes:
HAMi-core is a user-layer resource isolator provided by HAMi community, works on all types of GPU.
Dynamic-mig is a hardware resource isolator, works on Ampere arch or later GPU.
The table below shows the summary: | Mode | Isolation | MIG GPU Required | Annotation | Core/Memory Control | Recommended For | | ----------- | ---------------- | ---------------- | ---------- | ------------------- | -------------------------- | | HAMI-core | Software (VCUDA) | No | No | Yes | General workloads | | Dynamic MIG | Hardware | Yes | Yes | MIG-controlled | Performance-sensitive jobs |
You can set the sharing mode and customize your installation by adjusting the configs
Enabling GPU Support in Kubernetes
Once you have enabled this option on all the GPU nodes you wish to use, you can then enable GPU support in your cluster by deploying the following Daemonset:
Configure and install with Helm
Add the volcano-vgpu-device-plugin Helm repository: helm repo add volcano-vgpu-device-plugin https://project-hami.github.io/volcano-vgpu-device-plugin helm repo update
Install the chart:
helm install volcano-vgpu-device-plugin volcano-vgpu-device-plugin/volcano-vgpu-device-plugin
If you want to enable CDI, you can use the following command to install.
helm install volcano-vgpu-device-plugin volcano-vgpu-device-plugin/volcano-vgpu-device-plugin \
--set cdi.enabled=true
#### Install with yaml
##### Normal Mode
$ kubectl apply -f deployments/static/volcano-vgpu-device-plugin.yml
##### CDI Mode ###### Modify deployments/static/volcano-vgpu-device-plugin.ymlenv
- Add the following environment variables to the
section of thevolcano-device-plugincontainer.
- name: DEVICE_LIST_STRATEGY
- name: NVIDIA_DRIVER_ROOT
- name: NVIDIA_CDI_HOOK_PATH
- name: GDRCOPY_ENABLED
- name: GDS_ENABLED
- name: MOFED_ENABLED
2. Add the following configuration to thevolumeMountssection of thevolcano-device-plugincontainer.
- name: cdi-root
- name: driver-root
- name: usrbin
3. Add the following configuration to thevolumessection.
- name: driver-root
- name: cdi-root
- name: usrbin
###### Deploy
$ kubectl apply -f deployments/static/volcano-vgpu-device-plugin.yml
bash helm install nvml-mock oci://ghcr.io/nvidia/k8s-test-infra/chart/nvml-mock### Testing without real GPUs (nvml-mock)libnvidia-ml.soFor local development or CI without physical GPUs, the device-plugin can run against nvml-mock, which provides a fake
that simulates GPU devices on a kind cluster. The same approach is used by the HAMi nvml-mock lab.SetNvmlLibraryPath> Note: nvml-mock only simulates the device discovery path. Use it to verify > scheduling and registration behavior — the monitor container is automatically > disabled because it cannot resolve the mock NVML library (
> is only called by the device-plugin binary, and the monitor container does > not mount the mock driver root), so it would fail NVML initialization. > > Note:nvmlMock.enabledandcdi.enabledare mutually exclusive. The > nvml-mock driver root would override the CDI driver root, so the Helm chart > fails at render time if both are set totrue.libnvidia-ml.so1. Deploy nvml-mock
Deploy nvml-mock first so the fake driver and
are installed on the node (default host path:/var/lib/nvml-mock/driver):
bash helm install volcano-vgpu-device-plugin volcano-vgpu-device-plugin/volcano-vgpu-device-plugin \ --set nvmlMock.enabled=true#### 2. Deploy the device-plugin with nvml-mock (Helm)KLOG_LEVELnvml-mock support is provided through the Helm chart only, so that
,DEVICE_CONFIG_NAMESPACE, and other plugin settings stay in sync with the rest of the deployment:
Adjust the driver root if your nvml-mock install uses a non-default path:bash
helm install volcano-vgpu-device-plugin volcano-vgpu-device-plugin/volcano-vgpu-device-plugin \
--set nvmlMock.enabled=true \
--set nvmlMock.driverRoot=/var/lib/nvml-mock/driver
shell script $ kubectl get node {node name} -oyaml ... capacity: volcano.sh/vgpu-number: "40" # simulated vGPU resourceWhennvmlMock.enabled=true, the chart injects theNVIDIA_DRIVER_ROOT,CONTAINER_DRIVER_ROOT,NVIDIA_DEV_ROOT,DEVICE_DISCOVERY_STRATEGY=nvml, andDP_DISABLE_HEALTHCHECKS=allenvironment variables, mounts the mock driver root, and disables the monitor container.volcano.sh/vgpu-number3. Verify
Once the device-plugin pod is running, check the node capacity — a fake
resource should appear, same as with real GPUs:
shell script $ kubectl get node {node name} -oyaml ... capacity: volcano.sh/vgpu-memory: "89424" volcano.sh/vgpu-number: "10" # vGPU resourceThe exact number equals (fake GPUs from the nvml-mock profile) ×deviceConfig.nvidia.deviceSplitCount. The nvml-mock chart's defaultgb300profile exposes 4 fake GPUs, so with the defaultdeviceSplitCount: 10the node reports40; a profile with 8 GPUs (e.g.a100) reports80.volcano.sh/vgpu-numberVerify environment is ready
Check the node status, it is ok if
is included in the allocatable resources.
### Running VGPU Jobs
VGPU can be requested by both set "volcano.sh/vgpu-number" , "volcano.sh/vgpu-cores" and "volcano.sh/vgpu-memory" in resource.limit
shell script
$ cat <You can validate device memory using nvidia-smi inside container:
!img
> WARNING: *if you don't request GPUs when using the device plugin with NVIDIA images all
> the GPUs on the machine will be exposed inside your container.
> The number of vgpu used by a container can not exceed the number of gpus on that node.*
> You can specify the mode of this task by assigning
volcano.sh/vgpu-mode annotations, If not, both modes are possible.
Monitor
volcano-scheduler-metrics records every GPU usage and limitation, visit the following address to get these metrics.
curl {volcano scheduler cluster ip}:8080/metrics
You can also collect the GPU utilization, GPU memory usage, pods' GPU memory limitations and pods' GPU memory usage metrics on nodes by visiting the following addresses:
curl {volcano device plugin pod ip}:9394/metrics
Example:
HELP Device_last_kernel_of_container Container device last kernel description
TYPE Device_last_kernel_of_container gauge
Device_last_kernel_of_container{ctrname="cuda-container",deviceuuid="GPU-xxxx",podname="hami-device",podnamespace="default",vdeviceid="0",zone="vGPU"} 0HELP Device_memory_desc_of_container Container device meory description
TYPE Device_memory_desc_of_container counter
Device_memory_desc_of_container{context="331350016",ctrname="cuda-container",data="1778516992",deviceuuid="GPU-xxxx",module="0",offset="0",podname="hami-device",podnamespace="default",vdeviceid="0",zone="vGPU"} 2.109867008e+09HELP Device_utilization_desc_of_container Container device utilization description
TYPE Device_utilization_desc_of_container gauge
Device_utilization_desc_of_container{ctrname="cuda-container",deviceuuid="GPU-xxxx",podname="hami-device",podnamespace="default",vdeviceid="0",zone="vGPU"} 99HELP HostCoreUtilization GPU core utilization
TYPE HostCoreUtilization gauge
HostCoreUtilization{deviceidx="0",deviceuuid="GPU-xxxx",zone="vGPU"} 0 HostCoreUtilization{deviceidx="1",deviceuuid="GPU-xxxx",zone="vGPU"} 100HELP HostGPUMemoryUsage GPU device memory usage
TYPE HostGPUMemoryUsage gauge
HostGPUMemoryUsage{deviceidx="0",deviceuuid="GPU-xxxx",zone="vGPU"} 5.6366661632e+10 HostGPUMemoryUsage{deviceidx="1",deviceuuid="GPU-xxxx",zone="vGPU"} 5.8484457472e+10HELP vGPU_device_memory_limit_in_bytes vGPU device limit
TYPE vGPU_device_memory_limit_in_bytes gauge
vGPU_device_memory_limit_in_bytes{ctrname="cuda-container",deviceuuid="GPU-xxxx",podname="hami-device",podnamespace="default",vdeviceid="0",zone="vGPU"} 3.145728e+09HELP vGPU_device_memory_usage_in_bytes vGPU device usage
TYPE vGPU_device_memory_usage_in_bytes gauge
vGPU_device_memory_usage_in_bytes{ctrname="cuda-container",deviceuuid="GPU-xxxx",podname="hami-device",podnamespace="default",vdeviceid="0",zone="vGPU"} 2.109867008e+09 ``Issues and Contributing
Checkout the Contributing document!- You can report a bug by filing a new issue
- You can contribute by opening a pull request
Support
- Usage questions and bug reports: GitHub issues
- User guide: HAMi documentation
- Community channels: HAMi community
- Security issues: see SECURITY.md, do not open a public issue
Upgrading Kubernetes with the device plugin
Upgrading Kubernetes when you have a device plugin deployed doesn't require you to do any, particular changes to your workflow. The API is versioned and is pretty stable (though it is not guaranteed to be non breaking), upgrading kubernetes won't require you to deploy a different version of the device plugin and you will see GPUs re-registering themselves after you node comes back online.
Upgrading the device plugin is a more complex task. It is recommended to drain GPU tasks as we cannot guarantee that GPU tasks will survive a rolling upgrade. However we make best efforts to preserve GPU tasks during an upgrade.