Configure and manage the ack-nvidia-device-plugin add-on

Updated at:

The GPU device plugin (NVIDIA Device Plugin) manages the GPUs of each node in a Kubernetes cluster, so Kubernetes uses GPU resources efficiently. On ACK nodes in exclusive GPU scheduling scenarios, upgrade and restart the add-on, view and update its version, and isolate GPU devices to keep workloads running.

Usage notes

The following points apply to the NVIDIA Device Plugin deployed as a DaemonSet:

  • The add-on is automatically installed when the cluster is created.

  • If you uninstall the add-on, GPU nodes added by scale-out cannot report GPU resources properly.

  • When a cluster is upgraded from an earlier version to 1.32, the NVIDIA Device Plugin deployed as a Static Pod is also upgraded to the ACK add-on form.

  • This DaemonSet has a NodeSelector (ack.node.gpu.schedule=default). When a GPU node is added to the cluster, the ACK script for adding nodes automatically applies this label. The DaemonSet can then deploy the corresponding Pod on the GPU node.

Important
  • If the node operating system is Ubuntu 22.04 or Red Hat Enterprise Linux (RHEL) 9.3 64-bit, the ack-nvidia-device-plugin add-on configures the environment variable NVIDIA_VISIBLE_DEVICES=all for Pods by default. The node may be unable to access GPU devices after it runs the systemctl daemon-reload and systemctl daemon-reexec commands, which causes the NVIDIA Device Plugin to fail. For more information, see What do I do if the "Failed to initialize NVML: Unknown Error" error occurs when I run a GPU container?.

  • If you upgrade a cluster to 1.32 before May 1, 2025, the NVIDIA Device Plugin may be deployed as both a Static Pod and a DaemonSet. To view the nodes that run the Static Pod, run the following script:

    Script content and expected output

    #!/bin/bash
    for i in $(kubectl get po -n kube-system -l component=nvidia-device-plugin | grep -v NAME | awk '{print $1}');do
        if kubectl get po $i -o yaml -n kube-system | grep 'kubernetes.io/config.source: file' &> /dev/null;then
        kubectl get pod $i -n kube-system -o jsonpath='{.spec.nodeName}{"\n"}'
        fi
    done

    Expected output:

    cn-beijing.10.12.XXX.XX
    cn-beijing.10.13.XXX.XX

    The expected output shows that the NVIDIA Device Plugin deployed as a Static Pod still exists on some nodes. Use the following method to migrate the NVIDIA Device Plugin deployed as a Static Pod to a DaemonSet.

    kubectl label nodes <NODE_NAME> ack.node.gpu.schedule=default
  • For clusters of version 1.31 or earlier, the NVIDIA Device Plugin is also upgraded during the node pool upgrade, and non-standard configurations of the NVIDIA Device Plugin are reset.

Version differences

The implementation and management policy of the ack-nvidia-device-plugin add-on vary with the cluster version, as described in the following table:

Feature

Cluster version 1.32 or later

Cluster versions 1.20 to 1.31

Deployment method

DaemonSet

Static Pod

Management method

Add-on management in the console

Manual maintenance

Node label requirements

ack.node.gpu.schedule=default

No special requirements

Upgrade policy that follows the node pool upgrade

Manual upgrade

Automatic upgrade

If the cluster version is earlier than 1.20, see Manually upgrade a cluster.

Preparations

Connect to an ACK cluster using kubectl.

View the NVIDIA Device Plugin version

Cluster version 1.32 or later

For the add-on deployed as a DaemonSet, go to the Add-ons page in the console, locate the ack-nvidia-device-plugin add-on, and view the current version on the add-on card.

Cluster versions 1.20 to 1.31

For the add-on deployed as a Static Pod, view the add-on version:

kubectl get pods -n kube-system -l component=nvidia-device-plugin \
  -o jsonpath='{range .items[*]}{.spec.containers[0].image}{"\t"}{.spec.nodeName}{"\n"}{end}' \
  | awk -F'[:/]' '{split($NF, a, "-"); print a[1] "\t" $0}' \
  | sort -k1,1V \
  | cut -f2- \
  | awk -F'\t' '{split($1, img, ":"); print img[NF] "\t" $2}'

Upgrade NVIDIA Device Plugin

  1. Upgrade the ack-nvidia-device-plugin add-on.

    Cluster version 1.32 or later

    1. Log on to the ACK console. In the left navigation pane, click Clusters.

    2. On the Clusters page, click the name of your cluster. In the left navigation pane, click Add-ons .

    3. On the add-on management page, search for the ack-nvidia-device-plugin add-on and, on its card, click Upgrade.

    4. In the dialog box that appears, click OK.

    Cluster versions 1.20 to 1.31

    1. On the Clusters page, click the name of your cluster. In the left navigation pane, click Nodes > Nodes.

    2. Select the GPU nodes that require batch maintenance and click Batch Operations below the node list. Then, in the Batch Operations dialog box, select Run Shell Scripts and click OK.

      Important

      (Recommended) Upgrade a small number of GPU nodes first. After the operation is complete, verify that the Device Plugin works properly on the nodes, and then perform the operation on a large scale.

    3. On the Operation Orchestration Service (OOS) page that opens automatically, set Execution Mode to Paused Upon Failure, and then click Next: Set Parameters.

    4. On the Set Parameters page, select Run Shell Scripts and paste the following sample script:

      Note
      • In the script, change the RUN_PKG_VERSION parameter to the major version number of the cluster (for example, 1.30). Do not enter a minor version number (for example, 1.30.1); otherwise, the script reports an error.

      • In the script, change the REGION_ID parameter to the region ID of the current cluster, for example, cn-beijing.

      #!/bin/bash
      set -xe
      
      RUN_PKG_VERSION=1.30
      REGION_ID=cn-beijing
      
      function update_device_plugin() {
      	base_dir=/tmp/update_device_plugin
      	rm -rf $base_dir
      	mkdir -p $base_dir
      	cd $base_dir
      	region_id=$REGION_ID
      	PKG_URL=https://aliacs-k8s-${region_id}.oss-${region_id}-internal.aliyuncs.com/public/pkg/run/run-${RUN_PKG_VERSION}.tar.gz
      	curl -sSL --retry 3 --retry-delay 2 -o run.tar.gz $PKG_URL
      	tar -xf run.tar.gz
      
      	local dir=pkg/run/$RUN_PKG_VERSION/module
      	sed -i "s@registry.cn-hangzhou.aliyuncs.com/acs@registry-${region_id}-vpc.ack.aliyuncs.com/acs@g" $dir/nvidia-device-plugin.yml
      	mkdir -p /etc/kubernetes/device-plugin-backup
      	mkdir -p /etc/kubernetes/manifests
      	mv  /etc/kubernetes/manifests/nvidia-device-plugin.yml /etc/kubernetes/device-plugin-backup/nvidia-device-plugin.yml.$(date +%s)
      	sleep 5
      	cp -a $dir/nvidia-device-plugin.yml /etc/kubernetes/manifests
      	echo "succeeded to update device plugin"
      }
      
      if [ -f /etc/kubernetes/manifests/nvidia-device-plugin.yml ]; then
      	update_device_plugin
      else
      	echo "skip to update device plugin"
      fi
    5. Click Next: Confirm. After you verify that the information is correct, click Create.

      After creation, you are redirected to the Task Execution Management page, where you can view the running status of the task. If Output is succeeded to update device plugin, the update is successful.

  2. Check whether the add-on is running properly.

    Check whether the Device Plugin works properly on the GPU nodes.

    1. Use kubectl to connect to the cluster in Workbench or CloudShell.

    2. Run the following command to check whether the NVIDIA Device Plugin has restarted:

      kubectl get po -n kube-system -l component=nvidia-device-plugin 

      Sample output. Use the AGE value to determine whether the Pod has restarted.

      NAME                             READY   STATUS    RESTARTS      AGE
      nvidia-device-plugin-xxxx        1/1     Running   1             1m
    3. After you confirm that all Pods have restarted, run the following script to check whether the nodes report GPU resources:

      #!/bin/bash
      
      # Get all NVIDIA Device Plugin Pods that meet the conditions, along with the nodes on which they run
      PODS=$(kubectl get po -n kube-system -l component=nvidia-device-plugin -o jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.spec.nodeName}{"\n"}{end}')
      
      # Iterate over the node of each Pod
      echo "$PODS" | while IFS=$'\t' read -r pod_name node_name; do
          # Get the nvidia.com/gpu resource allocation value of the node
          gpu_allocatable=$(kubectl get node "$node_name" -o jsonpath='{.status.allocatable.nvidia\.com/gpu}' 2>/dev/null)
      
          # Check whether the resource value is 0
          if [ "$gpu_allocatable" == "0" ]; then
              echo "Error: node=$node_name, pod=$pod_name, resource(nvidia.com/gpu) is 0"
          fi
      done

      If a node reports a resource value of 0, see Restart NVIDIA Device Plugin.

Restart NVIDIA Device Plugin

In the ACK exclusive GPU scheduling scenario, the Device Plugin that reports the GPU devices on a node is deployed as a single Pod by default. The restart must therefore be performed on the target node.

Cluster version 1.32 or later

  1. Find the Device Plugin Pod on the target node:

    kubectl get pod -n kube-system -l component=nvidia-device-plugin -o wide | grep <NODE>
  2. Restart the Device Plugin Pod.

    kubectl delete po <DEVICE_PLUGIN_POD> -n kube-system 

Cluster versions 1.20 to 1.31

  1. On the Clusters page, click the name of your cluster. In the left navigation pane, click Nodes > Node Pools.

  2. On the Node Pools page, click the name of the node pool to go to node management, and then log on to the target GPU node.

    If the operating system is ContainerOS, to reduce potential security risks, ContainerOS in principle does not allow any user to log on directly and perform potentially untraceable operations. ContainerOS also does not provide the Secure Shell (SSH) logon feature. If you still need to log on to the instance to perform O&M operations, see Maintain ContainerOS nodes.
  3. Select the GPU nodes that require batch maintenance and click Batch Operations below the node list. Then, in the Batch Operations dialog box, select Run Shell Scripts and click OK.

    Important

    (Recommended) Restart a small number of GPU nodes first. After the operation is complete, verify that the Device Plugin works properly on the nodes, and then perform the operation on a large scale.

  4. On the OOS page that opens automatically, set Execution Mode to Paused Upon Failure, and then click Next: Set Parameters.

  5. On the Set Parameters page, select Run Shell Scripts and paste the following sample script:

    #!/bin/bash
    set -e
    
    if [ -f /etc/kubernetes/manifests/nvidia-device-plugin.yml ]; then
    	cp -a /etc/kubernetes/manifests/nvidia-device-plugin.yml /etc/kubernetes
    	rm -rf /etc/kubernetes/manifests/nvidia-device-plugin.yml
    	sleep 5
    	mv /etc/kubernetes/nvidia-device-plugin.yml /etc/kubernetes/manifests
    	echo "the nvidia device is restarted"
    else
    	echo "no need to restart nvidia device plugin"
    fi
  6. Click Next: Confirm. After you verify that the information is correct, click Create. After creation, you are redirected to the Task Execution Management page, where you can view the running status of the task.

  7. Check whether the Device Plugin works properly on the GPU nodes:

    kubectl get nodes <NODE_NAME> -o jsonpath='{.metadata.name} ==> nvidia.com/gpu: {.status.allocatable.nvidia\.com/gpu}'

    Expected output:

    cn-hangzhou.172.16.XXX.XX ==> nvidia.com/gpu: 1

    If the nvidia.com/gpu extended resource reported by the GPU node is not 0, the Device Plugin is working properly.

Modify the NVIDIA Device Plugin device identifier

When the NVIDIA Device Plugin allocates devices to a Pod, it creates a Checkpoint file on the node that records which devices are already allocated and the information about their Pods. In the NVIDIA Device Plugin, the Checkpoint file uses the UUID of the GPU as the unique identifier (Key) of each GPU device by default. Follow the instructions below to change this Key to the Index of the device, which resolves issues such as the UUID loss caused by cold migration of a virtual machine (VM).

Cluster version 1.32 or later

  1. Modify the NVIDIA Device Plugin DaemonSet:

    kubectl edit ds -n kube-system ack-nvidia-device-plugin
  2. Add the following environment variable CHECKPOINT_DEVICE_ID_STRATEGY:

        env:
          - name: CHECKPOINT_DEVICE_ID_STRATEGY
            value: index
  3. Restart NVIDIA Device Plugin to make the changes take effect.

Cluster versions 1.20 to 1.31

  1. In the /etc/kubernetes/manifests/nvidia-device-plugin.yml file on the target node, check the image tag of the NVIDIA Device Plugin. The version number represented by the tag is the version of the NVIDIA Device Plugin. If the version number is 0.9.3 or later, you do not need to change it. Otherwise, change the version number to the latest version, v0.9.3-0dd4d5f5-aliyun.

  2. Modify the environment variables of the Static Pod in the /etc/kubernetes/manifests/nvidia-device-plugin.yml file. Add an environment variable CHECKPOINT_DEVICE_ID_STRATEGY as shown in the following code:

        env:
          - name: CHECKPOINT_DEVICE_ID_STRATEGY
            value: index
  3. Restart NVIDIA Device Plugin to make the changes take effect.

Enable or disable automatic GPU isolation

When the NPD check items that trigger automatic GPU isolation are configured, abnormal GPU cards are automatically isolated. Automatic isolation is not equivalent to automatic repair. The node instances on which GPU cards are automatically isolated continue to be billed, and you still need to repair the nodes. Configure GPU anomaly alerts so that issues can be handled promptly. If no check items are selected, automatic isolation is not performed.

Applicable scope

The ACK NVIDIA Device Plugin add-on version >= 0.7.0 and the ACK Node Problem Detector (NPD) add-on version >= 1.2.35.

How to enable

  1. Log on to the ACK console. In the left navigation pane, click Clusters.

  2. On the Clusters page, click the name of your cluster. In the left navigation pane, click Add-ons .

  3. On the add-on management page, search for the ack-nvidia-device-plugin add-on and, on its card, click Configuration.

  4. In the dialog box that appears, enable or disable automatic GPU isolation.

    • Enable: Select the Enable Automatic GPU Isolation check box and select the NPD check items that trigger automatic GPU isolation.

    • Disable: Clear the Enable Automatic GPU Isolation check box, or do not configure any check items.

Mount GDR devices and enable GPU memory copy acceleration

Applicable scope

Starting with v0.5.0, ack-nvidia-device-plugin supports mounting GPU Direct RDMA (GDR) devices into GPU containers. The following conditions must be met:

  • The cluster version is >=1.32.

  • The node is a Lingjun node.

  • The GDR software is installed on the node.

    Log on to the node and run lsmod | grep gdrdrv to check whether the GDR kernel module is loaded. Sample output:
    gdrdrv                196608  0
    nvidia              14680064  88 nvidia_uvm,nvidia_peermem,gdrdrv,nvidia_modeset
  • nvidia-container-toolkit is installed on the node and its version is >= 1.15.0.

    Log on to the node and run nvidia-container-cli --version to confirm the version. Sample output:
    cli-version: 1.17.8
    lib-version: 1.17.8

How to enable

  1. Log on to the ACK console. In the left navigation pane, click Clusters.

  2. On the Clusters page, click the name of your cluster. In the left navigation pane, click Add-ons .

  3. On the add-on management page, search for the ack-nvidia-device-plugin add-on and, on its card, click Configuration.

  4. In the dialog box that appears, select Enable GDRCopy for GPU memory copy acceleration (takes effect on Lingjun nodes with GDR software installed and nvidia-container-toolkit version >= 1.15.0).

Verify the result

  1. On the Clusters page, click the name of your cluster. In the left navigation pane, click Workloads > Deployments.

  2. On the Deployments page, click Create from YAML. Use the following sample code to create an application.

    apiVersion: v1
    kind: Pod
    metadata:
      name: tensorflow-mnist
      namespace: default
    spec:
      containers:
      - image: registry.cn-beijing.aliyuncs.com/acs/tensorflow-mnist-sample:v1.5
        name: tensorflow-mnist
        command:
        - python
        - tensorflow-sample-code/tfjob/docker/mnist/main.py
        - --max_steps=100000
        - --data_dir=tensorflow-sample-code/data
        resources:
          limits:
            nvidia.com/gpu: 1  # Requests one GPU card for this container.
        workingDir: /root
      restartPolicy: Always
  3. Enter the Pod:

    kubectl exec -ti tensorflow-mnist -- ls /dev/gdrdrv

    Expected output:

    /dev/gdrdrv

    This output indicates that the gdrdrv device is mounted.

FAQ

How do I disable the native GPU isolation capability of the NVIDIA Device Plugin?

Background

When a GPU on a node becomes abnormal, ACK automatically isolates the abnormal GPU through the NVIDIA Device Plugin to prevent jobs from being scheduled onto the abnormal GPU. However, automatic isolation does not perform automatic repair. You still need to restart or repair the node manually. Configure GPU anomaly alerts so that issues can be handled promptly. For more information about the native GPU isolation capability of the NVIDIA Device Plugin, see k8s-device-plugin.

  • After isolation, if the remaining GPUs on the node cannot meet the requirements of a job, the job cannot be scheduled. For example, an 8-GPU job cannot be scheduled when only 7 GPUs are available, which may leave GPU resources idle.

  • After the GPU status returns to normal, the isolation of the GPU device is automatically deactivated.

  • To disable automatic isolation (abnormal GPUs still report resources and are not isolated), see the following solution.

Solution

  1. Check whether the add-on has enabled the native GPU isolation capability.

    If it is not enabled, you do not need to perform the subsequent steps to disable it.

    Cluster version 1.32 or later

    Log on to the Container Service console, and check the version of ack-nvidia-device-plugin in the Add-ons of the target cluster. If the version is v0.1.0, the GPU isolation capability is enabled.

    Cluster versions 1.20 to 1.31

    1. Use kubectl to connect to the cluster in Workbench or CloudShell.

    2. Check whether the GPU isolation capability is enabled in the NVIDIA Device Plugin.

      check_gpu_isolation_enabled() {
          echo "Checking nodes with NVIDIA Device Plugin deployed as static pods that have GPU isolation enabled (i.e., DP_DISABLE_HEALTHCHECKS is not set to 'all')..."
      
          # Get pod names with the expected label
          pods=$(kubectl get pods -n kube-system -l component=nvidia-device-plugin --no-headers -o custom-columns=":metadata.name" 2>/dev/null)
      
          if [ -z "$pods" ]; then
              echo "No pods found with label 'component=nvidia-device-plugin'."
              return 0
          fi
      
          found=0
          while IFS= read -r pod; do
              [ -z "$pod" ] && continue
      
              # Check if it's a static pod: annotation kubernetes.io/config.source must be "file"
              config_source=$(kubectl get pod "$pod" -n kube-system -o jsonpath='{.metadata.annotations.kubernetes\.io/config\.source}' 2>/dev/null)
      
              if [ "$config_source" != "file" ]; then
                  # Not a static pod (e.g., managed by DaemonSet), skip
                  continue
              fi
      
              # Get node name
              node=$(kubectl get pod "$pod" -n kube-system -o jsonpath='{.spec.nodeName}' 2>/dev/null)
              [ -z "$node" ] && continue
      
              # Check if DP_DISABLE_HEALTHCHECKS is set to "all"
              disabled_value=$(kubectl get pod "$pod" -n kube-system -o jsonpath='{range .spec.containers[*]}{range .env[?(@.name=="DP_DISABLE_HEALTHCHECKS")]}{.value}{"\n"}{end}{end}' 2>/dev/null | head -n1)
      
              # If not set or not equal to "all", health checks are active → isolation is enabled
              if [ -z "$disabled_value" ] || [ "$disabled_value" != "all" ]; then
                  echo "Node: $node, Static Pod: $pod"
                  found=1
              fi
          done <<< "$pods"
      
          if [ "$found" -eq 0 ]; then
              echo "No static pods found with GPU isolation enabled."
          else
              echo "Note: The above nodes will automatically isolate faulty GPUs via NVIDIA Device Plugin."
          fi
      }
      
      check_gpu_isolation_enabled

      Expected output:

      Checking nodes with NVIDIA Device Plugin deployed as static pods that have GPU isolation enabled (i.e., DP_DISABLE_HEALTHCHECKS is not set to 'all')...
      Node: cn-beijing.192.168.XXX.XXX, Static Pod: nvidia-device-plugin-cn-beijing.192.168.XXX.XXX
      Note: The above nodes will automatically isolate faulty GPUs via NVIDIA Device Plugin.

      If the output contains Note: The above nodes will automatically isolate faulty GPUs via NVIDIA Device Plugin., the GPU isolation capability is enabled.

  2. Disable the GPU isolation capability by upgrading the add-on.

    The latest version of the NVIDIA Device Plugin add-on disables the native GPU isolation capability by default. To update the add-on to the latest version, see Upgrade NVIDIA Device Plugin.

References