Kubernetes quản lý và sử dụng resources GPU tương tự như sử dụng resources CPU. Tùy vào cấu hình GPU lựa chọn cho Worker Group để khai báo resources GPU cho ứng dụng trên Kubernetes.
Chú ý:
– Kiểm tra cấu hình GPU bằng lệnh sau:
kubectl get node -o json | jq ‘.items[].metadata.labels‘
Ví dụ: hình trên cho thấy worker sủ dụng card Nvidia A30, cấu hình strategy: all-balanced, trạng thái: success.
– Kiểm tra cấu hình GPU Instance trên worker chưa bằng lệnh sau: (ssh vào worker, gõ lệnh)
Ví dụ triển khai ứng dụng sử dụng GPU:
nvidia.com/gpu: [số-lượng-gpu]
nvidia.com/gpu: 1
(Với strategy single, card GPU chia được chia nhỏ thành các instance bằng nhau)
apiVersion: apps/v1
kind: Deployment
metadata:
name: example-gpu-app
spec:
replicas: 1
selector:
matchLabels:
component: gpu-app
template:
metadata:
labels:
component: gpu-app
spec:
containers:
– name: gpu-container
securityContext:
capabilities:
add:
– SYS\_ADMIN
resources:
limits:
nvidia.com/gpu: 1
image: nvidia/samples:dcgmproftester-2.0.10-cuda11.0-ubuntu18.04
command: [“/bin/sh”, “-c”]
args:
– while true; do /usr/bin/dcgmproftester11 –no-dcgm-validation -t 1004 -d 300; sleep 30; done
nvidia.com/[mig-profile]: [số-lượng-gpu]
nvidia.com/mig-1g.6gb: 2
(Với strategy mixed, card GPU chia được chia nhỏ thành 2 loại instance nên khi khai báo resources cần chỉ rõ loại instance sử dụng)
apiVersion: apps/v1
kind: Deployment
metadata:
name: example-gpu-app
spec:
replicas: 1
selector:
matchLabels:
component: gpu-app
template:
metadata:
labels:
component: gpu-app
spec:
containers:
– name: gpu-container
securityContext:
capabilities:
add:
– SYS\_ADMIN
resources:
limits:
nvidia.com/mig-1g.6gb: 1
image: nvidia/samples:dcgmproftester-2.0.10-cuda11.0-ubuntu18.04
command: [“/bin/sh”, “-c”]
args:
– while true; do /usr/bin/dcgmproftester11 –no-dcgm-validation -t 1004 -d 300; sleep 30; done
nvidia.com/gpu: 1
(Với none strategy, pod sẽ dùng toàn bộ tài nguyên của một card GPU)
apiVersion: apps/v1
kind: Deployment
metadata:
name: example-gpu-app
spec:
replicas: 1
selector:
matchLabels:
component: gpu-app
template:
metadata:
labels:
component: gpu-app
spec:
containers:
– name: gpu-container
securityContext:
capabilities:
add:
– SYS\_ADMIN
resources:
limits:
nvidia.com/gpu: 1
image: nvidia/samples:dcgmproftester-2.0.10-cuda11.0-ubuntu18.04
command: [“/bin/sh”, “-c”]
args:
– while true; do /usr/bin/dcgmproftester11 –no-dcgm-validation -t 1004 -d 300; sleep 30; done