diff --git a/content/zh-cn/docs/concepts/scheduling-eviction/dynamic-resource-allocation.md b/content/zh-cn/docs/concepts/scheduling-eviction/dynamic-resource-allocation.md index a8cd3af38e63c..01596304fcbc6 100644 --- a/content/zh-cn/docs/concepts/scheduling-eviction/dynamic-resource-allocation.md +++ b/content/zh-cn/docs/concepts/scheduling-eviction/dynamic-resource-allocation.md @@ -14,34 +14,52 @@ weight: 65 + +使用结构化参数进行核心动态资源分配: + {{< feature-state feature_gate_name="DynamicResourceAllocation" >}} + +使用控制平面控制器进行动态资源分配: + +{{< feature-state feature_gate_name="DRAControlPlaneController" >}} + 动态资源分配是一个用于在 Pod 之间和 Pod 内部容器之间请求和共享资源的 API。 -它是持久卷 API 的通用资源化。第三方资源驱动程序负责跟踪和分配资源, -Kubernetes 通过**结构化参数**(在 Kubernetes 1.30 中引入)提供了额外的支持。 -当驱动程序使用结构化参数时,Kubernetes 可以处理调度和资源分配,而无需与驱动程序通信。 -而不同类型的资源,可支持用于“定义需求”和“初始化”的任意参数。 +它是持久卷 API 针对一般资源的泛化。通常这些资源是 GPU 这类设备。 + +第三方资源驱动程序负责跟踪和准备资源, +Kubernetes 通过**结构化参数**(在 Kubernetes 1.30 中引入)处理资源的分配。 +不同类别的资源支持任意参数来定义要求和初始化。 + +当驱动程序提供**控制平面控制器**时,驱动程序本身与 Kubernetes 调度器合作一起处理资源分配。 ## {{% heading "prerequisites" %}} Kubernetes v{{< skew currentVersion >}} 包含用于动态资源分配的集群级 API 支持, 但它需要被[显式启用](#enabling-dynamic-resource-allocation)。 @@ -54,113 +72,88 @@ Kubernetes v{{< skew currentVersion >}} 包含用于动态资源分配的集群 ## API -`resource.k8s.io/v1alpha2` +`resource.k8s.io/v1alpha3` {{< glossary_tooltip text="API 组" term_id="api-group" >}} 提供了以下类型: - ResourceClaim -: Defines a particular resource instance that is required by a - workload. Created by a user (lifecycle managed manually, can be shared - between different Pods) or for individual Pods by the control plane based on - a ResourceClaimTemplate (automatic lifecycle, typically used by just one - Pod). +: 描述对集群中资源的访问请求,工作负载需要使用这些资源。 + 例如,如果工作负载需要具有特定属性的加速器设备,就可以通过这种方式表达该请求。 + 状态部分跟踪此请求是否已被满足以及具体已分配了哪些资源。 + -ResourceClass -: 定义由哪个资源驱动程序处理某种资源,并为其提供通用参数。 - 集群管理员在安装资源驱动程序时创建 ResourceClass。 - -ResourceClaim -: 定义工作负载所需的特定资源实例。 - 由用户创建(手动管理生命周期,可以在不同的 Pod 之间共享), - 或者由控制平面基于 ResourceClaimTemplate 为特定 Pod 创建 - (自动管理生命周期,通常仅由一个 Pod 使用)。 - ResourceClaimTemplate -: 定义用于创建 ResourceClaim 的 spec 和一些元数据。 +: 定义用于创建 ResourceClaim 的规约和一些元数据。 部署工作负载时由用户创建。 + 每个 Pod 的 ResourceClaim 随后会被 Kubernetes 自动创建和移除。 -PodSchedulingContext -: 供控制平面和资源驱动程序内部使用, - 在需要为 Pod 分配 ResourceClaim 时协调 Pod 调度。 +DeviceClass +: 包含某些设备的预定义选择标准和配置。 + DeviceClass 由集群管理员在安装资源驱动程序时创建。 + 对 ResourceClaim 中某个设备的每个分配请求都必须准确引用一个 DeviceClass。 + + -ResourceSlice -: 与结构化参数一起使用,发布集群中可用资源的信息。 - -ResourceClaimParameters -: 包含影响调度的 ResourceClaim 参数, - 以 Kubernetes 理解的格式(“结构化参数模型”)呈现。 - 提供了供应商驱动程序,在设置底层资源时,使用的不透明扩展中可能嵌入其他参数。 - -ResourceClassParameters -: 类似于 ResourceClaimParameters,ResourceClassParameters 为 Kubernetes 理解的 ResourceClass 参数提供了一种类型。 - +PodSchedulingContext +: 供控制平面和资源驱动程序内部使用, + 在需要为 Pod 分配 ResourceClaim 且这些 ResourceClaim 使用控制平面控制器时协调 Pod 调度。 - -ResourceClass 和 ResourceClaim 的参数存储在单独的对象中,通常使用安装资源驱动程序时创建的 -{{< glossary_tooltip term_id="CustomResourceDefinition" text="CRD" >}} 所定义的类型。 +ResourceSlice +: 与结构化参数一起使用,以发布有关集群中可用资源的信息。 -资源驱动程序的开发者决定他们是要在自己的外部控制器中处理这些参数, -还是依赖 Kubernetes 通过使用结构化参数来处理它们。 -自定义控制器提供更多的灵活性,但对于节点本地资源,集群自动缩放可能无法可靠工作。 -结构化参数使集群自动缩放成为可能,但可能无法满足所有用例。 +资源驱动程序的开发者决定他们是要使用控制平面控制器自己处理资源分配, +还是依赖 Kubernetes 使用结构化参数来处理资源分配。 +自定义控制器提供更多的灵活性,但对于节点本地资源,集群自动扩缩可能无法可靠工作。 +结构化参数使集群自动扩缩成为可能,但可能无法满足所有使用场景。 -当驱动程序使用结构化参数时,仍然可以让最终用户使用供应商特定的 CRD 指定参数。 -在这种情况下,驱动程序需要将这些自定义参数转换为内部类型。 -或者,驱动程序也可以直接使用内部类型的文档。 +当驱动程序使用结构化参数时,所有选择设备的参数都在 +ResourceClaim 和 DeviceClass 中以树内类型被定义。 +配置参数可以作为任意 JSON 对象嵌入其中。 -### 不使用结构化参数 {#without-structured-parameters} +### 使用控制平面控制器 {#with-control-plane-controller} -ResourceClaim 可以在创建时就进行分配(“立即分配”),不用考虑哪些 Pod 将使用它。 -默认情况下采用延迟分配,直到需要 ResourceClaim 的 Pod 被调度时 -(即“等待第一个消费者”)再进行分配。 - - -在这种模式下,调度器检查 Pod 所需的所有 ResourceClaim,并创建一个 PodScheduling 对象, +当 Pod 被调度时,调度器检查 Pod 所需的所有 ResourceClaim,并创建一个 PodScheduling 对象, 通知负责这些 ResourceClaim 的资源驱动程序,告知它们调度器认为适合该 Pod 的节点。 资源驱动程序通过排除没有足够剩余资源的节点来响应调度器。 一旦调度器有了这些信息,它就会选择一个节点,并将该选择存储在 PodScheduling 对象中。 @@ -341,22 +322,31 @@ responsibility of allocating resources to a ResourceClaim whenever a pod needs them. It does so by retrieving the full list of available resources from ResourceSlice objects, tracking which of those resources have already been allocated to existing ResourceClaims, and then selecting from those resources -that remain. The exact resources selected are subject to the constraints -provided in any ResourceClaimParameters or ResourceClassParameters associated -with the ResourceClaim. +that remain. --> 当驱动程序使用结构化参数时,调度器负责在 Pod 需要资源时为 ResourceClaim 分配资源。 通过从 ResourceSlice 对象中检索可用资源的完整列表, 跟踪已分配给现有 ResourceClaim 的资源,然后从剩余的资源中进行选择。 -所选资源受与 ResourceClaim 关联的 ResourceClaimParameters 或 ResourceClassParameters 提供的约束的影响。 + + +目前唯一支持的资源类别是设备。 +设备实例具有名称以及多个属性和容量信息。 +设备通过 CEL 表达式被选择,这些表达式检查设备的属性和容量。 +此外,所选择的设备集合还可以限制为满足特定约束的集合。 -所选资源与供应商特定参数一起被记录在 ResourceClaim 状态中, +所选资源与所有供应商特定配置一起被记录在 ResourceClaim 状态中, 因此当 Pod 即将在节点上启动时,节点上的资源驱动程序具有准备资源所需的所有信息。 通过使用结构化参数,调度器能够在不与 DRA 资源驱动程序通信的情况下做出决策。 -它还能够通过将 ResourceClaim 分配信息保存在内存中,并在同时将 Pod 绑定到节点的同时将此信息写入 ResourceClaim 对象中, -快速调度多个 Pod。 +它还能够通过将 ResourceClaim 分配信息保存在内存中,并在同时将 Pod 绑定到节点的同时将此信息写入 +ResourceClaim 对象中,快速调度多个 Pod。 动态资源分配是一个 **Alpha 特性**,只有在启用 `DynamicResourceAllocation` [特性门控](/zh-cn/docs/reference/command-line-tools-reference/feature-gates/) -和 `resource.k8s.io/v1alpha2` +和 `resource.k8s.io/v1alpha3` {{< glossary_tooltip text="API 组" term_id="api-group" >}} 时才启用。 有关详细信息,参阅 `--feature-gates` 和 `--runtime-config` [kube-apiserver 参数](/zh-cn/docs/reference/command-line-tools-reference/kube-apiserver/)。 kube-scheduler、kube-controller-manager 和 kubelet 也需要设置该特性门控。 + +当资源驱动程序使用控制平面控制器时,除了需要启用 `DynamicResourceAllocation` 外, +还必须启用 `DRAControlPlaneController` 特性门控。 + -快速检查 Kubernetes 集群是否支持该功能的方法是列出 ResourceClass 对象: +快速检查 Kubernetes 集群是否支持该特性的方法是列举 DeviceClass 对象: ```shell -kubectl get resourceclasses +kubectl get deviceclasses ``` -如果你的集群支持动态资源分配,则响应是 ResourceClass 对象列表或: +如果你的集群支持动态资源分配,则响应是 DeviceClass 对象列表或: ``` No resources found @@ -492,9 +488,18 @@ If not supported, this error is printed instead: 如果不支持,则会输出如下错误: ``` -error: the server doesn't have a resource type "resourceclasses" +error: the server doesn't have a resource type "deviceclasses" ``` + +当可以创建设置了 `spec.controller` 字段的 ResourceClaim 时,控制平面控制器是受支持的。 +当 `DRAControlPlaneController` 特性被禁用时,存储 ResourceClaim 时该字段会自动被清除。 + - 了解更多该设计的信息, - 参阅[动态资源分配 KEP](https://github.com/kubernetes/enhancements/blob/master/keps/sig-node/3063-dynamic-resource-allocation/README.md) - 和[结构化参数 KEP](https://github.com/kubernetes/enhancements/tree/master/keps/sig-node/4381-dra-structured-parameters)。 + 参阅[使用结构化参数的动态资源分配 KEP](https://github.com/kubernetes/enhancements/tree/master/keps/sig-node/4381-dra-structured-parameters) + 和[使用控制平面控制器的动态资源分配 KEP](https://github.com/kubernetes/enhancements/blob/master/keps/sig-node/3063-dynamic-resource-allocation/README.md)。