Schedule GPUs

    FEATURE STATE:

    Kubernetes includes experimental support for managing AMD and NVIDIA GPUs (graphical processing units) across several nodes.

    This page describes how users can consume GPUs across different Kubernetes versions and the current limitations.

    Kubernetes implements Device Plugins to let Pods access specialized hardware features such as GPUs.

    As an administrator, you have to install GPU drivers from the corresponding hardware vendor on the nodes and run the corresponding device plugin from the GPU vendor:

    When the above conditions are true, Kubernetes will expose amd.com/gpu or nvidia.com/gpu as a schedulable resource.

    You can consume these GPUs from your containers by requesting <vendor>.com/gpu the same way you request cpu or memory. However, there are some limitations in how you specify the resource requirements when using GPUs:

    • GPUs are only supposed to be specified in the limits section, which means:
      • You can specify GPU limits without specifying requests because Kubernetes will use the limit as the request value by default.
      • You can specify GPU in both limits and requests but these two values must be equal.
      • You cannot specify GPU requests without specifying limits.
    • Containers (and Pods) do not share GPUs. There’s no overcommitting of GPUs.
    • Each container can request one or more GPUs. It is not possible to request a fraction of a GPU.

    The has the following requirements:

    • Kubernetes nodes have to be pre-installed with AMD GPU Linux driver.

    To deploy the AMD device plugin once your cluster is running and the above requirements are satisfied:

    You can report issues with this third-party device plugin by logging an issue in RadeonOpenCompute/k8s-device-plugin.

    Deploying NVIDIA GPU device plugin

    There are currently two device plugin implementations for NVIDIA GPUs:

    Official NVIDIA GPU device plugin

    The has the following requirements:

    • Kubernetes nodes have to be pre-installed with NVIDIA drivers.
    • Kubernetes nodes have to be pre-installed with nvidia-docker 2.0
    • nvidia-container-runtime must be configured as the for Docker, instead of runc.
    • The version of the NVIDIA drivers must match the constraint ~= 384.81.

    To deploy the NVIDIA device plugin once your cluster is running and the above requirements are satisfied:

    You can report issues with this third-party device plugin by logging an issue in NVIDIA/k8s-device-plugin.

    NVIDIA GPU device plugin used by GCE

    You can use the following commands to install the NVIDIA drivers and device plugin:

    1. # Install NVIDIA drivers on Container-Optimized OS:
    2. kubectl create -f https://raw.githubusercontent.com/GoogleCloudPlatform/container-engine-accelerators/stable/daemonset.yaml
    3. # Install NVIDIA drivers on Ubuntu (experimental):
    4. kubectl create -f https://raw.githubusercontent.com/GoogleCloudPlatform/container-engine-accelerators/stable/nvidia-driver-installer/ubuntu/daemonset.yaml
    5. # Install the device plugin:
    6. kubectl create -f https://raw.githubusercontent.com/kubernetes/kubernetes/release-1.14/cluster/addons/device-plugins/nvidia-gpu/daemonset.yaml

    You can report issues with using or deploying this third-party device plugin by logging an issue in GoogleCloudPlatform/container-engine-accelerators.

    Google publishes its own for using NVIDIA GPUs on GKE .

    If different nodes in your cluster have different types of GPUs, then you can use Node Labels and Node Selectors to schedule pods to appropriate nodes.

    For example:

    If you’re using AMD GPU devices, you can deploy . Node Labeller is a controller that automatically labels your nodes with GPU device properties.

    At the moment, that controller can add labels for:

    • Device ID (-device-id)
    • VRAM Size (-vram)
    • Number of SIMD (-simd-count)
    • Number of Compute Unit (-cu-count)
    • Firmware and Feature Versions (-firmware)
    • GPU Family, in two letters acronym (-family)
      • SI - Southern Islands
      • CI - Sea Islands
      • KV - Kaveri
      • CZ - Carrizo
      • AI - Arctic Islands
      • RV - Raven
    1. kubectl describe node cluster-node-23
    1. apiVersion: v1
    2. kind: Pod
    3. name: cuda-vector-add
    4. spec:
    5. restartPolicy: OnFailure
    6. containers:
    7. - name: cuda-vector-add
    8. # https://github.com/kubernetes/kubernetes/blob/v1.7.11/test/images/nvidia-cuda/Dockerfile
    9. image: "k8s.gcr.io/cuda-vector-add:v0.1"
    10. resources:
    11. limits:
    12. nvidia.com/gpu: 1
    13. nodeSelector:
    14. accelerator: nvidia-tesla-p100 # or nvidia-tesla-k80 etc.

    This will ensure that the Pod will be scheduled to a node that has the GPU type you specified.