diff --git a/content/zh-cn/docs/tasks/configure-pod-container/assign-resources/set-up-dra-cluster.md b/content/zh-cn/docs/tasks/configure-pod-container/assign-resources/set-up-dra-cluster.md new file mode 100644 index 0000000000..13e94deed0 --- /dev/null +++ b/content/zh-cn/docs/tasks/configure-pod-container/assign-resources/set-up-dra-cluster.md @@ -0,0 +1,307 @@ +--- +title: "在集群中设置 DRA" +content_type: task +min-kubernetes-server-version: v1.32 +weight: 10 +--- + + +{{< feature-state feature_gate_name="DynamicResourceAllocation" >}} + + + + +本文介绍如何在 Kubernetes 集群中通过启用 API 组并配置设备类别来设置**动态资源分配(DRA)**。 +这些指示说明适用于集群管理员。 + + + + +## 关于 DRA {#about-dra} + +{{< glossary_definition term_id="dra" length="all" >}} + + +确保你已了解 DRA 的工作机制及其术语,例如 +{{< glossary_tooltip text="DeviceClasses" term_id="deviceclass" >}}、 +{{< glossary_tooltip text="ResourceClaims" term_id="resourceclaim" >}}以及 +{{< glossary_tooltip text="ResourceClaimTemplates" term_id="resourceclaimtemplate" >}}。 +更多信息请参见[动态资源分配(DRA)](/zh-cn/docs/concepts/scheduling-eviction/dynamic-resource-allocation/)。 + + + +## {{% heading "prerequisites" %}} + +{{< include "task-tutorial-prereqs.md" >}} {{< version-check >}} + + +* 将设备直接或间接挂接到你的集群中。为避免驱动相关的问题,请在安装驱动之前先完成 DRA 特性的配置。 + + + + +## 启用 DRA API 组 {#enable-dra} + +若要让 Kubernetes 能够使用 DRA 为你的 Pod 分配资源,需完成以下配置步骤: + +1. 在所有以下组件中启用 `DynamicResourceAllocation` + [特性门控](/zh-cn/docs/reference/command-line-tools-reference/feature-gates/): + + * `kube-apiserver` + * `kube-controller-manager` + * `kube-scheduler` + * `kubelet` + + +2. 启用以下 {{< glossary_tooltip text="API 组" term_id="api-group" >}}: + + * `resource.k8s.io/v1beta1`:DRA 所必需。 + * `resource.k8s.io/v1beta2`:可选,推荐启用以提升用户体验。 + + 更多信息请参阅[启用或禁用 API 组](/zh-cn/docs/reference/using-api/#enabling-or-disabling)。 + + +## 验证是否启用了 DRA {#verify} + +若要验证集群是否配置正确,可尝试列出 DeviceClass: + +```shell +kubectl get deviceclasses +``` + + +如果组件配置正确,输出类似如下: + +``` +No resources found +``` + + +如果 DRA 未正确配置,则上述命令的输出可能如下: + +``` +error: the server doesn't have a resource type "deviceclasses" +``` + + +你可以尝试以下排查步骤: + +1. 确保 `kube-scheduler` 组件已启用 `DynamicResourceAllocation` 特性门控,并且使用的是 + [v1 配置 API](/zh-cn/docs/reference/config-api/kube-scheduler-config.v1/)。 + 如果你使用自定义配置,你可能还需额外启用 `DynamicResource` 插件。 + +2. 重启 `kube-apiserver` 和 `kube-controller-manager` 组件,以传播 API 组变更。 + + +## 安装设备驱动 {#install-drivers} + +你启用集群的 DRA 特性后,你可以安装所挂接设备的驱动。 +安装方式请参见设备所有者或驱动维护方提供的文档。你安装的驱动必须与 DRA 兼容。 + +若要验证驱动是否正常工作,可列出集群中的 ResourceSlice: + +```shell +kubectl get resourceslices +``` + + +输出示例如下: + +``` +NAME NODE DRIVER POOL AGE +cluster-1-device-pool-1-driver.example.com-lqx8x cluster-1-node-1 driver.example.com cluster-1-device-pool-1-r1gc 7s +cluster-1-device-pool-2-driver.example.com-29t7b cluster-1-node-2 driver.example.com cluster-1-device-pool-2-446z 8s +``` + + +## 创建 DeviceClass {#create-deviceclasses} + +你可以通过创建 +{{< glossary_tooltip text="DeviceClasses" term_id="deviceclass" >}} +定义设备的分类,供应用运维人员在工作负载中申领这些设备。 +某些设备驱动提供方也可能在驱动安装过程中要求你创建 DeviceClass。 + + +你的驱动所发布的 ResourceSlice 中包含了设备的相关信息,例如容量、元数据和属性。你可以使用 +{{< glossary_tooltip term_id="cel" >}} 表达式按 DeviceClass 中的属性进行筛选, +从而帮助工作负载运维人员更轻松地找到合适的设备。 + +1. 若要查看可通过 CEL 表达式在 DeviceClass 中选择的设备属性,你可以查看某个 ResourceSlice 的规约: + + ```shell + kubectl get resourceslice -o yaml + ``` + + + + 输出类似如下: + + + + ```yaml + apiVersion: resource.k8s.io/v1beta1 + kind: ResourceSlice + # 为简洁省略部分内容 + spec: + devices: + - basic: + attributes: + type: + string: gpu + capacity: + memory: + value: 64Gi + name: gpu-0 + - basic: + attributes: + type: + string: gpu + capacity: + memory: + value: 64Gi + name: gpu-1 + driver: driver.example.com + nodeName: cluster-1-node-1 + # 为简洁省略部分内容 + ``` + + + + 你也可以查阅驱动提供商的文档,了解可用的属性和对应值。 + + +2. 查看以下 DeviceClass 示例清单,它选择所有由 `driver.example.com` 设备驱动管理的设备: + + {{% code_sample file="dra/deviceclass.yaml" %}} + + +3. 在集群中创建 DeviceClass: + + ```shell + kubectl apply -f https://k8s.io/examples/dra/deviceclass.yaml + ``` + + +## 清理 {#clean-up} + +要删除本任务中创建的 DeviceClass,运行以下命令: + +```shell +kubectl delete -f https://k8s.io/examples/dra/deviceclass.yaml +``` + +## {{% heading "whatsnext" %}} + + +* [进一步了解 DRA](/zh-cn/docs/concepts/scheduling-eviction/dynamic-resource-allocation) +* [使用 DRA 为工作负载分配设备](/zh-cn/docs/tasks/configure-pod-container/assign-resources/allocate-devices-dra) diff --git a/content/zh-cn/examples/dra/deviceclass.yaml b/content/zh-cn/examples/dra/deviceclass.yaml new file mode 100644 index 0000000000..dcad8e488b --- /dev/null +++ b/content/zh-cn/examples/dra/deviceclass.yaml @@ -0,0 +1,9 @@ +apiVersion: resource.k8s.io/v1beta2 +kind: DeviceClass +metadata: + name: example-device-class +spec: + selectors: + - cel: + expression: |- + device.driver == "driver.example.com"