AI基础设施变革:
节点准备要求:
# 验证节点GPU就绪状态
nvidia-smi -L
# 输出示例:
GPU 0: xxxx
容器运行时配置:
# /etc/containerd/config.toml
[plugins."io.containerd.grpc.v1.cri"]
enable_gpu = true
[plugins."io.containerd.grpc.v1.cri".device_plugin]
config_path = "/var/lib/kubelet/device-plugins"
Kubernetes 在 Pod 的 API 对象里,并没有为 GPU 专门设置一个资源类型字段,而是使用了一种叫作 Extended Resource(ER)的特殊字段来负责传递 GPU 的信息。
apiVersion: v1
kind: Pod
metadata:
name: cuda-training
spec:
containers:
- name: trainer
image: nvcr.io/nvidia/tensorflow:22.07-tf2-py3
resources:
limits:
nvidia.com/gpu: 1 # 必须为整数
volumeMounts:
- name: nvidia-driver
mountPath: /usr/local/nvidia
readOnly: true
volumes:
- name: nvidia-driver
hostPath:
path: /usr/local/nvidia
可以看到,在上述 Pod 的 limits 字段里,这个资源的名称是nvidia.com/gpu,它的值是 1。也就是说,这个 Pod 声明了自己要使用一个 NVIDIA 类型的 GPU。
而在 kube-scheduler 里面,它其实并不关心这个字段的具体含义,只会在计算的时候,一律将调度器里保存的该类型资源的可用量,直接减去 Pod 声明的数值即可。所以说,Extended Resource,其实是 Kubernetes 为用户设置的一种对自定义资源的支持。
kubectl get node <node> -o jsonpath='{.status.capacity}'
# 输出示例:{"nvidia.com/gpu":"8"}
Device Plugin --gRPC--> Kubelet
Kubelet -->|上报| API-Server
Scheduler -->|查询| API-Server
Kubelet -->|分配| CRI(Container Runtime)
通信协议:通过 Unix socket (/var/lib/kubelet/device-plugins/
) 使用 gRPC 通信
关键接口:
service DevicePlugin {
rpc ListAndWatch(Empty) returns (stream ListAndWatchResponse) {}
rpc Allocate(AllocateRequest) returns (AllocateResponse) {}
rpc GetPreferredAllocation(PreferredAllocationRequest) returns (PreferredAllocationResponse) {}
}
工作流程:
ListAndWatch
上报设备列表及状态Allocate
注入设备资源nvidia.com/gpu: 2
这样的整数资源判断# 用户无法表达如下需求:
resources:
limits:
nvidia.com/gpu.performance: "high" # 期望高性能GPU
nvidia.com/gpu.memory: "32Gi" # 需要大显存
ListAndWatch
仅返回设备 ID 和健康状态
type Device struct {
ID string
Health string
// 无厂商/型号/性能等字段
}
// 自定义调度插件示例
func (p *GPUScheduler) Filter(ctx context.Context, pod *v1.Pod, nodeInfo *framework.NodeInfo) *framework.Status {
gpuDevices := getNodeGPUs(nodeInfo)
if !matchesRequirements(pod, gpuDevices) {
return framework.NewStatus(framework.Unschedulable)
}
return nil
}
Volcano是CNCF下首个也是唯一的基于Kubernetes的容器批量计算平台,主要用于高性能计算场景。它提供了包括异构设备调度,网络拓扑感知调度,多集群调度,在离线混部调度等多种调度能力。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。