2.8. 使用设备插件通过 pod 访问外部资源

通过设备插件,您可以在 OpenShift Container Platform pod 中使用需要特定厂商初始化和设置的特定设备类型(GPU、InfiniBand 或其他类似的计算资源),而无需编写自定义代码。

2.8.1. 了解设备插件

设备插件提供一致且可移植的解决方案,用于在集群中消耗硬件设备。设备插件通过一种扩展机制提供对这些设备的支持,从而使这些设备可供容器使用,提供这些设备的健康检查,并安全地共享它们。

重要

OpenShift Container Platform 支持设备插件 API,但设备插件容器由各个供应商提供支持。

设备插件是在节点( kubelet的外部)上运行的 gRPC 服务,负责管理特定的硬件资源。任何设备插件都必须支持以下远程过程调用(RPC):

service DevicePlugin {
      // GetDevicePluginOptions returns options to be communicated with Device
      // Manager
      rpc GetDevicePluginOptions(Empty) returns (DevicePluginOptions) {}

      // ListAndWatch returns a stream of List of Devices
      // Whenever a Device state change or a Device disappears, ListAndWatch
      // returns the new list
      rpc ListAndWatch(Empty) returns (stream ListAndWatchResponse) {}

      // Allocate is called during container creation so that the Device
      // Plug-in can run device specific operations and instruct Kubelet
      // of the steps to make the Device available in the container
      rpc Allocate(AllocateRequest) returns (AllocateResponse) {}

      // PreStartcontainer is called, if indicated by Device Plug-in during
      // registration phase, before each container start. Device plug-in
      // can run device specific operations such as reseting the device
      // before making devices available to the container
      rpc PreStartcontainer(PreStartcontainerRequest) returns (PreStartcontainerResponse) {}
}
设备插件示例
注意

对于简单设备插件参考实现,设备管理器代码中有一个存根设备插件: vendor/k8s.io/kubernetes/pkg/kubelet/cm/deviceplugin/device_plugin_stub.go

2.8.1.1. 设备插件部署方法

  • 守护进程集是设备插件部署的推荐方法。
  • 在启动时,设备插件会尝试在节点上 /var/lib/kubelet/device-plugin/ 创建一个 UNIX 域套接字,以服务来自设备管理器的 RPC。
  • 由于设备插件必须管理硬件资源、主机文件系统的访问以及套接字创建,它们必须在特权安全上下文中运行。
  • 有关部署步骤的更多细节,请参阅每个设备插件实施。