AliyunContainerService / gpushare-device-plugin

GPU Sharing Device Plugin for Kubernetes Cluster
Apache License 2.0
468 stars 144 forks source link

[问题] Device Plugin allocate 选出的 pod 是否会跟 Kubelet 绑定的不一致 #16

Open orainxiong opened 5 years ago

orainxiong commented 5 years ago

看 Kubelet 调用 allocate 的实现

        resp, err := eI.e.allocate(devs)
                 ....
        m.podDevices.insert(podUID, contName, resource, allocDevices, resp.ContainerResponses[0])

deviceplug.allocate

但是在 Kubelet 调用deviceplug.allocate时已经确定了podUID. 两者是否会不同?

cheyang commented 5 years ago

这里依赖是Pod在调度器是按顺序bind的,而且在bind过程中已经加了锁。是能够保证顺序性的。

payall4u commented 3 years ago

这里依赖是Pod在调度器是按顺序bind的,而且在bind过程中已经加了锁。是能够保证顺序性的。

@cheyang bind是有顺序的,但kubelet不一定会按照bind的顺序创建pod。

xiaoxubeii commented 3 years ago

看 Kubelet 调用 allocate 的实现

      resp, err := eI.e.allocate(devs)
                 ....
      m.podDevices.insert(podUID, contName, resource, allocDevices, resp.ContainerResponses[0])

deviceplug.allocate

  • 会列出该节点中所有状态为 Pending 并且ALIYUN_COM_GPU_MEM_ASSIGNED为false的 GPU Share Pod
  • 选择出其中 Pod Annotation 的ALIYUN_COM_GPU_MEM_POD的数量与 Allocate 申请数量一致的 Pod。如果有多个符合这种条件的 Pod,就会选择其中ALIYUN_COM_GPU_MEM_ASSUME_TIME最早的 Pod。
  • 将该 Pod 的 annotation ALIYUN_COM_GPU_MEM_ASSIGNED设置为true,并且将 Pod annotation 中的 GPU 信息转化为环境变量返回给 Kubelet 用以真正的创建 Pod。

但是在 Kubelet 调用deviceplug.allocate时已经确定了podUID. 两者是否会不同?

是的,这里实现可能会造成不一致。kubelet device plugin allocate 是按照 container 调用,但在 gpushare-device-plugin 是按照自有逻辑找到 candidate pod,不一定是 kubelet 调用的那个 pod。并且如果单 pod 下有多个 container 申请了 gpu 资源,这里肯定匹配不到。

https://github.com/AliyunContainerService/gpushare-device-plugin/blob/5b68fe2035878864faab7b8f7a57d1f5030b7c09/pkg/gpu/nvidia/allocate.go#L54-L88

gaoyangcaiji commented 2 years ago

请问大佬有啥好的解决办法吗?这个不一致的问题