Skip to content

GPU resources

List nodes with GPU resources

List the resources on nodes with access to Graphics Processing Units (GPUs)

kubectl get nodes -o=go-template='{{range .items}}{{$c := .status.capacity}}{{$gpus := index $c "nvidia.com/gpu"}}{{if $gpus}}{{if gt $gpus "0"}}{"{{.metadata.name}}":{"cpu":{{$c.cpu}},"gpu":{{$gpus}},"mem":"{{$c.memory}}","hdd":"{{index $c "ephemeral-storage"}}","accelerator":"{{.metadata.labels.accelerator}}"{{"}}\n"}}{{end}}{{end}}{{end}}'
{"p02r01srv02":{"cpu":64,"gpu":8,"mem":"257602Mi","hdd":"960302804Ki","accelerator":"nvidia-gtx-2080ti"}}
{"p02r01srv03":{"cpu":64,"gpu":8,"mem":"263774984Ki","hdd":"960302804Ki","accelerator":"nvidia-gtx-2080ti"}}
{"p02r01srv04":{"cpu":64,"gpu":8,"mem":"263774996Ki","hdd":"960302804Ki","accelerator":"nvidia-gtx-2080ti"}}
{"p02r01srv05":{"cpu":64,"gpu":8,"mem":"263774988Ki","hdd":"960302804Ki","accelerator":"nvidia-gtx-2080ti"}}
{"p02r01srv06":{"cpu":64,"gpu":8,"mem":"263774984Ki","hdd":"960302804Ki","accelerator":"nvidia-gtx-2080ti"}}
{"p02r01srv07":{"cpu":64,"gpu":8,"mem":"263774996Ki","hdd":"960302804Ki","accelerator":"nvidia-gtx-2080ti"}}
{"p02r02srv01":{"cpu":64,"gpu":8,"mem":"263774988Ki","hdd":"1844812632Ki","accelerator":"nvidia-gtx-2080ti"}}
{"p02r02srv02":{"cpu":64,"gpu":8,"mem":"263774988Ki","hdd":"1844812632Ki","accelerator":"nvidia-gtx-2080ti"}}
{"p02r02srv03":{"cpu":64,"gpu":8,"mem":"263783116Ki","hdd":"1844812632Ki","accelerator":"nvidia-gtx-2080ti"}}
{"p02r02srv05":{"cpu":64,"gpu":8,"mem":"263783144Ki","hdd":"1844812632Ki","accelerator":"nvidia-gtx-1080ti"}}
{"p02r09srv01":{"cpu":64,"gpu":8,"mem":"263783128Ki","hdd":"1844812632Ki","accelerator":"nvidia-gtx-2080ti"}}
{"p02r09srv02":{"cpu":64,"gpu":8,"mem":"263783116Ki","hdd":"1844812632Ki","accelerator":"nvidia-gtx-2080ti"}}
{"p02r09srv03":{"cpu":64,"gpu":8,"mem":"263773292Ki","hdd":"1844812632Ki","accelerator":"nvidia-gtx-1080ti"}}
{"p02r09srv04":{"cpu":64,"gpu":8,"mem":"263781432Ki","hdd":"1844812632Ki","accelerator":"nvidia-gtx-1080ti"}}
{"p02r09srv06":{"cpu":64,"gpu":8,"mem":"263773324Ki","hdd":"1844812632Ki","accelerator":"nvidia-gtx-1080ti"}}
{"p02r09srv07":{"cpu":64,"gpu":8,"mem":"263773292Ki","hdd":"1844812632Ki","accelerator":"nvidia-gtx-2080ti"}}
{"p02r10srv02":{"cpu":64,"gpu":8,"mem":"263775000Ki","hdd":"960302804Ki","accelerator":"nvidia-gtx-2080ti"}}
{"p02r10srv03":{"cpu":64,"gpu":8,"mem":"263774988Ki","hdd":"960302804Ki","accelerator":"nvidia-gtx-2080ti"}}
{"p02r10srv04":{"cpu":64,"gpu":8,"mem":"263774988Ki","hdd":"960302804Ki","accelerator":"nvidia-gtx-2080ti"}}
{"p02r10srv05":{"cpu":64,"gpu":8,"mem":"263765136Ki","hdd":"960167960Ki","accelerator":"nvidia-gtx-2080ti"}}

Request GPU resources

The following YAML file demonstrates how to request GPU resources:

gpu-pod.yaml
apiVersion: v1
kind: Pod
metadata:
  name: testpod
spec:
  containers:
  - name: cuda
    image: nvidia/cuda:12.2.0-base-ubuntu22.04
    command:
      - sleep
      - infinity
    resources:
      requests:
        cpu: "500m"
        memory: "2Gi"
        nvidia.com/gpu: "1"
      limits:
        memory: "2Gi"
        nvidia.com/gpu: "1"
  nodeSelector:
    accelerator: nvidia-gtx-2080ti

Create the pod and the GPU will be directly accessible

kubectl create -f gpu-pod.yaml
kubectl exec testpod -- sh -c 'nvidia-smi -L'
GPU 0: GeForce RTX 2080 Ti (UUID: GPU-cd469f06-a7da-e73c-70fe-161dc35b587b)

Last update: 2023-07-12
Created: 2023-01-05