Gestor de GPUs de centro de datos de NVIDIA (DCGM)

En este documento se describe cómo configurar tu implementación de Google Kubernetes Engine para que puedas usar Google Cloud Managed Service para Prometheus y recoger métricas de NVIDIA Data Center GPU Manager. En este documento se explica cómo hacer lo siguiente:

  • Configura el exportador de DCGM para que genere informes de métricas.

Estas instrucciones solo se aplican si usas la recogida gestionada con Managed Service para Prometheus. Si utilizas la recogida autodesplegada, consulta el repositorio de origen de DCGM Exporter para obtener información sobre la instalación.

Estas instrucciones se proporcionan como ejemplo y deberían funcionar en la mayoría de los entornos de Kubernetes. Para obtener información sobre una oferta de DCGM gestionada, consulta Recoger y ver métricas de DCGM.

Si tienes problemas para instalar una aplicación o un exportador debido a políticas de seguridad o de la organización restrictivas, te recomendamos que consultes la documentación de código abierto para obtener ayuda.

Para obtener información sobre NVIDIA Data Center GPU Manager, consulta NVIDIA DCGM.

Requisitos previos

Para recoger métricas de DCGM con Managed Service para Prometheus y la recogida gestionada, tu despliegue debe cumplir los siguientes requisitos:

  • Tu clúster debe ejecutar la versión 1.28.15-gke.2475000 de Google Kubernetes Engine o una posterior.
  • Debes ejecutar Managed Service para Prometheus con la recogida gestionada habilitada. Para obtener más información, consulta el artículo Empezar a utilizar la recogida gestionada.

  • Comprueba que tengas suficiente cuota para las GPUs NVIDIA.

  • Para enumerar los nodos de GPU de tu clúster de GKE y sus tipos de GPU en el clúster correspondiente, ejecuta el siguiente comando:

    kubectl get nodes -l cloud.google.com/gke-gpu -o jsonpath='{range .items[*]}{@.metadata.name}{" "}{@.metadata.labels.cloud\.google\.com/gke-accelerator}{"\n"}{end}'
    
  • Ten en cuenta que es posible que tengas que instalar un controlador de GPU NVIDIA compatible en los nodos si la instalación automática se ha inhabilitado o no es compatible con tu versión de GKE. Para verificar que el complemento de dispositivo de GPU de NVIDIA se está ejecutando, ejecuta el siguiente comando:

    kubectl get pods -n kube-system | grep nvidia-gpu-device-plugin
    

Instalar el exportador de DCGM

Te recomendamos que instales el exportador de DCGM, DCGM-Exporter, con la siguiente configuración:

# Copyright 2023 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: nvidia-dcgm
  namespace: gmp-public
  labels:
    app: nvidia-dcgm
spec:
  selector:
    matchLabels:
      app: nvidia-dcgm
  updateStrategy:
    type: RollingUpdate
  template:
    metadata:
      labels:
        name: nvidia-dcgm
        app: nvidia-dcgm
    spec:
      affinity:
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
            - matchExpressions:
              - key: cloud.google.com/gke-accelerator
                operator: Exists
      tolerations:
      - operator: "Exists"
      volumes:
      - name: nvidia-install-dir-host
        hostPath:
          path: /home/kubernetes/bin/nvidia
          type: Directory
      containers:
      - image: "nvcr.io/nvidia/cloud-native/dcgm:3.3.0-1-ubuntu22.04"
        command: ["nv-hostengine", "-n", "-b", "ALL"]
        ports:
        - containerPort: 5555
          hostPort: 5555
        name: nvidia-dcgm
        securityContext:
          privileged: true
        volumeMounts:
        - name: nvidia-install-dir-host
          mountPath: /usr/local/nvidia
---
apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: nvidia-dcgm-exporter
  namespace: gmp-public
  labels:
    app.kubernetes.io/name: nvidia-dcgm-exporter
spec:
  selector:
    matchLabels:
      app.kubernetes.io/name: nvidia-dcgm-exporter
  updateStrategy:
    type: RollingUpdate
  template:
    metadata:
      labels:
        app.kubernetes.io/name: nvidia-dcgm-exporter
    spec:
      affinity:
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
            - matchExpressions:
              - key: cloud.google.com/gke-accelerator
                operator: Exists
      tolerations:
      - operator: "Exists"
      volumes:
      - name: nvidia-dcgm-exporter-metrics
        configMap:
          name: nvidia-dcgm-exporter-metrics
      - name: nvidia-install-dir-host
        hostPath:
          path: /home/kubernetes/bin/nvidia
          type: Directory
      - name: pod-resources
        hostPath:
          path: /var/lib/kubelet/pod-resources
      containers:
      - name: nvidia-dcgm-exporter
        image: nvcr.io/nvidia/k8s/dcgm-exporter:3.3.0-3.2.0-ubuntu22.04
        command: ["/bin/bash", "-c"]
        args:
        - hostname $NODE_NAME; dcgm-exporter --remote-hostengine-info $(NODE_IP) --collectors /etc/dcgm-exporter/counters.csv
        ports:
        - name: metrics
          containerPort: 9400
        securityContext:
          privileged: true
        env:
        - name: NODE_NAME
          valueFrom:
            fieldRef:
              fieldPath: spec.nodeName
        - name: "DCGM_EXPORTER_KUBERNETES_GPU_ID_TYPE"
          value: "device-name"
        - name: LD_LIBRARY_PATH
          value: /usr/local/nvidia/lib64
        - name: NODE_IP
          valueFrom:
            fieldRef:
              fieldPath: status.hostIP
        - name: DCGM_EXPORTER_KUBERNETES
          value: 'true'
        - name: DCGM_EXPORTER_LISTEN
          value: ':9400'
        volumeMounts:
        - name: nvidia-dcgm-exporter-metrics
          mountPath: "/etc/dcgm-exporter"
          readOnly: true
        - name: nvidia-install-dir-host
          mountPath: /usr/local/nvidia
        - name: pod-resources
          mountPath: /var/lib/kubelet/pod-resources
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: nvidia-dcgm-exporter-metrics
  namespace: gmp-public
data:
  counters.csv: |
    # Utilization (the sample period varies depending on the product),,
    DCGM_FI_DEV_GPU_UTIL, gauge, GPU utilization (in %).
    DCGM_FI_DEV_MEM_COPY_UTIL, gauge, Memory utilization (in %).

    # Temperature and power usage,,
    DCGM_FI_DEV_GPU_TEMP, gauge, Current temperature readings for the device in degrees C.
    DCGM_FI_DEV_MEMORY_TEMP, gauge, Memory temperature for the device.
    DCGM_FI_DEV_POWER_USAGE, gauge, Power usage for the device in Watts.

    # Utilization of IP blocks,,
    DCGM_FI_PROF_SM_ACTIVE, gauge, The ratio of cycles an SM has at least 1 warp assigned
    DCGM_FI_PROF_SM_OCCUPANCY, gauge, The fraction of resident warps on a multiprocessor
    DCGM_FI_PROF_PIPE_TENSOR_ACTIVE, gauge, The ratio of cycles the tensor (HMMA) pipe is active (off the peak sustained elapsed cycles)
    DCGM_FI_PROF_PIPE_FP64_ACTIVE, gauge, The fraction of cycles the FP64 (double precision) pipe was active.
    DCGM_FI_PROF_PIPE_FP32_ACTIVE, gauge, The fraction of cycles the FP32 (single precision) pipe was active.
    DCGM_FI_PROF_PIPE_FP16_ACTIVE, gauge, The fraction of cycles the FP16 (half precision) pipe was active.

    # Memory usage,,
    DCGM_FI_DEV_FB_FREE, gauge, Framebuffer memory free (in MiB).
    DCGM_FI_DEV_FB_USED, gauge, Framebuffer memory used (in MiB).
    DCGM_FI_DEV_FB_TOTAL, gauge, Total Frame Buffer of the GPU in MB.

    # PCIE,,
    DCGM_FI_PROF_PCIE_TX_BYTES, gauge, Total number of bytes transmitted through PCIe TX
    DCGM_FI_PROF_PCIE_RX_BYTES, gauge, Total number of bytes received through PCIe RX

    # NVLink,,
    DCGM_FI_PROF_NVLINK_TX_BYTES, gauge, The number of bytes of active NvLink tx (transmit) data including both header and payload.
    DCGM_FI_PROF_NVLINK_RX_BYTES, gauge, The number of bytes of active NvLink rx (read) data including both header and payload.
Para verificar que DCGM Exporter emite métricas en los endpoints esperados, haz lo siguiente:

  1. Configura el reenvío de puertos con el siguiente comando:

    kubectl -n gmp-public port-forward POD_NAME 9400
    
  2. Accede al endpoint localhost:9400/metrics mediante el navegador o la utilidad curl en otra sesión de terminal.

Puedes personalizar la sección ConfigMap para seleccionar qué métricas de GPU quieres emitir.

También puedes usar el gráfico de Helm oficial para instalar DCGM Exporter.

Para aplicar los cambios de configuración de un archivo local, ejecuta el siguiente comando:

kubectl apply -n NAMESPACE_NAME -f FILE_NAME

También puedes usar Terraform para gestionar tus configuraciones.

Definir un recurso de PodMonitoring

Para la detección de destinos, el operador de Managed Service para Prometheus requiere un recurso PodMonitoring que corresponda a DCGM Exporter en el mismo espacio de nombres.

Puedes usar la siguiente configuración de PodMonitoring:

# Copyright 2023 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

apiVersion: monitoring.googleapis.com/v1
kind: ClusterPodMonitoring
metadata:
  name: nvidia-dcgm-exporter
  labels:
    app.kubernetes.io/name: nvidia-dcgm-exporter
    app.kubernetes.io/part-of: google-cloud-managed-prometheus
spec:
  selector:
    matchLabels:
      app.kubernetes.io/name: nvidia-dcgm-exporter
  endpoints:
  - port: metrics
    interval: 30s
  targetLabels:
    metadata: []

Para aplicar los cambios de configuración de un archivo local, ejecuta el siguiente comando:

kubectl apply -n NAMESPACE_NAME -f FILE_NAME

También puedes usar Terraform para gestionar tus configuraciones.

Verificar la configuración

Puede usar Explorador de métricas para verificar que ha configurado correctamente DCGM Exporter. Cloud Monitoring puede tardar uno o dos minutos en ingerir tus métricas.

Para comprobar que las métricas se han insertado, haz lo siguiente:

  1. En la Google Cloud consola, ve a la página  Explorador de métricas:

    Ve al explorador de métricas.

    Si usas la barra de búsqueda para encontrar esta página, selecciona el resultado cuya sección sea Monitorización.

  2. En la barra de herramientas del panel de creación de consultas, selecciona el botón cuyo nombre sea  MQL o  PromQL.
  3. Verifica que PromQL esté seleccionado en el interruptor Idioma. El interruptor de idioma se encuentra en la misma barra de herramientas que te permite dar formato a tu consulta.
  4. Introduce y ejecuta la siguiente consulta:
    DCGM_FI_DEV_GPU_UTIL{cluster="CLUSTER_NAME", namespace="gmp-public"}
    

Solución de problemas

Para obtener información sobre cómo solucionar problemas de ingestión de métricas, consulta la sección Problemas con la recogida de datos de los exportadores del artículo Solucionar problemas del lado de la ingestión.