排程 GPU
Kubernetes v1.26 [stable]
Kubernetes 透過裝置外掛,在叢集的不同節點上支援管理 AMD 和 NVIDIA GPU(圖形處理單元)的穩定功能。
本頁面描述了使用者如何使用 GPU,並概述了實現中的一些限制。
使用裝置外掛
Kubernetes 實現裝置外掛,以允許 Pod 訪問 GPU 等專用硬體功能。
作為管理員,你必須在節點上安裝相應硬體供應商的 GPU 驅動程式,並執行 GPU 供應商的相應裝置外掛。以下是一些供應商說明的連結
安裝外掛後,你的叢集將公開一個自定義可排程資源,例如 amd.com/gpu
或 nvidia.com/gpu
。
你可以透過請求自定義 GPU 資源來在容器中使用這些 GPU,這與你請求 cpu
或 memory
的方式相同。但是,在指定自定義裝置的資源需求時存在一些限制。
GPU 僅應在 limits
部分中指定,這意味著
- 你可以指定 GPU
limits
而不指定requests
,因為 Kubernetes 預設會將 limit 作為請求值使用。 - 你可以在
limits
和requests
中都指定 GPU,但這兩個值必須相等。 - 你不能在不指定
limits
的情況下指定 GPUrequests
。
以下是請求 GPU 的 Pod 的示例清單
apiVersion: v1
kind: Pod
metadata:
name: example-vector-add
spec:
restartPolicy: OnFailure
containers:
- name: example-vector-add
image: "registry.example/example-vector-add:v42"
resources:
limits:
gpu-vendor.example/example-gpu: 1 # requesting 1 GPU
管理具有不同型別 GPU 的叢集
如果叢集中的不同節點具有不同型別的 GPU,那麼你可以使用節點標籤和節點選擇器來將 Pod 排程到適當的節點。
例如
# Label your nodes with the accelerator type they have.
kubectl label nodes node1 accelerator=example-gpu-x100
kubectl label nodes node2 accelerator=other-gpu-k915
標籤鍵 accelerator
只是一個示例;如果你願意,可以使用不同的標籤鍵。
自動節點標籤
作為管理員,你可以透過部署 Kubernetes 節點特徵發現 (NFD) 自動發現並標記所有支援 GPU 的節點。NFD 會檢測 Kubernetes 叢集中每個節點上可用的硬體特徵。通常,NFD 被配置為將這些特徵作為節點標籤公佈,但 NFD 也可以新增擴充套件資源、註解和節點汙點。NFD 與所有受支援的 Kubernetes 版本相容。預設情況下,NFD 會為檢測到的特徵建立特徵標籤。管理員可以利用 NFD 對具有特定特徵的節點新增汙點,以便只有請求這些特徵的 Pod 才能排程到這些節點上。
你還需要一個 NFD 外掛,用於為節點新增適當的標籤;這些標籤可以是通用標籤,也可以是供應商特定的標籤。你的 GPU 供應商可能會提供 NFD 的第三方外掛;請查閱其文件以獲取更多詳細資訊。
apiVersion: v1
kind: Pod
metadata:
name: example-vector-add
spec:
restartPolicy: OnFailure
# You can use Kubernetes node affinity to schedule this Pod onto a node
# that provides the kind of GPU that its container needs in order to work
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: "gpu.gpu-vendor.example/installed-memory"
operator: Gt # (greater than)
values: ["40535"]
- key: "feature.node.kubernetes.io/pci-10.present" # NFD Feature label
values: ["true"] # (optional) only schedule on nodes with PCI device 10
containers:
- name: example-vector-add
image: "registry.example/example-vector-add:v42"
resources:
limits:
gpu-vendor.example/example-gpu: 1 # requesting 1 GPU
GPU 供應商實現
本頁面上的專案涉及提供 Kubernetes 所需功能的第三方產品或專案。Kubernetes 專案作者不對這些第三方產品或專案負責。有關更多詳細資訊,請參閱 CNCF 網站指南。
在提議新增額外第三方連結的更改之前,你應該閱讀內容指南。