# DRA API 对象

LLMS index: [llms.txt](/llms.txt)

---

<!--
reviewers:
- klueska
- pohly
title: DRA API Objects
content_type: concept
weight: 10
api_metadata:
- apiVersion: "resource.k8s.io/v1"
  kind: "ResourceClaim"
- apiVersion: "resource.k8s.io/v1"
  kind: "ResourceClaimTemplate"
- apiVersion: "resource.k8s.io/v1"
  kind: "DeviceClass"
- apiVersion: "resource.k8s.io/v1"
  kind: "ResourceSlice"
-->

<!-- overview -->

<!--
This page describes the Kubernetes API kinds that dynamic resource allocation
(DRA) uses to categorize, request, and allocate devices.
-->
本页介绍 Kubernetes API 种类，这些种类由动态资源分配（DRA）用于对设备进行分类、请求和分配。

<!-- body -->

<!--
## DRA terminology {#terminology}
-->
## DRA 术语 {#terminology}

<!--
DRA uses the following Kubernetes API kinds to provide the core allocation
functionality. All of these API kinds are included in the `resource.k8s.io/v1`
<a class='glossary-tooltip' title='Kubernetes API 中的一组相关路径。' data-bs-toggle='tooltip' data-bs-placement='top' href='/zh-cn/docs/concepts/overview/kubernetes-api/#api-groups-and-versioning' target='_blank' aria-label='API group'>API group</a>.
-->
DRA 使用以下 Kubernetes API 种类来提供核心分配功能。
所有这些 API 种类都包含在 `resource.k8s.io/v1`
<a class='glossary-tooltip' title='Kubernetes API 中的一组相关路径。' data-bs-toggle='tooltip' data-bs-placement='top' href='/zh-cn/docs/concepts/overview/kubernetes-api/#api-groups-and-versioning' target='_blank' aria-label='API 组'>API 组</a>中。

<!--
DeviceClass
: Defines a category of devices that can be claimed and how to select specific
  device attributes in claims. The DeviceClass parameters can match zero or
  more devices in ResourceSlices. To claim devices from a DeviceClass,
  ResourceClaims select specific device attributes.
-->
DeviceClass
: 定义了可以被申领的设备类别，以及如何在申领中选择特定设备属性。
  DeviceClass 参数可以匹配 ResourceSlice 中的零个或多个设备。
  若要从 DeviceClass 中申领设备，ResourceClaim 需要选择特定的设备属性。

<!--
ResourceClaim
: Describes a request for access to attached resources, such as
  devices, in the cluster. ResourceClaims provide Pods with access to
  a specific resource. ResourceClaims can be created by workload operators
  or generated by Kubernetes based on a ResourceClaimTemplate.
-->
ResourceClaim
: 描述了访问集群中已挂接资源（例如设备）的请求。
  ResourceClaim 为 Pod 提供对特定资源的访问。
  ResourceClaim 可以由工作负载运维人员创建，
  也可以由 Kubernetes 基于 ResourceClaimTemplate 生成。

<!--
ResourceClaimTemplate
: Defines a template that Kubernetes uses to create per-Pod
  ResourceClaims for a workload. ResourceClaimTemplates provide Pods with
  access to separate, similar resources. Each ResourceClaim that Kubernetes
  generates from the template is bound to a specific Pod. When the Pod
  terminates, Kubernetes deletes the corresponding ResourceClaim.
-->
ResourceClaimTemplate
: 定义一个模板，Kubernetes 使用该模板为工作负载创建每个 Pod 的 ResourceClaim。
  ResourceClaimTemplate 为 Pod 提供对独立的、配置相似的资源的访问。
  Kubernetes 从此模板生成的每个 ResourceClaim 都会绑定到一个特定的 Pod。
  当 Pod 终止时，Kubernetes 删除对应的 ResourceClaim。

<!--
ResourceSlice
: Represents one or more resources that are attached to nodes, such as devices.
  Drivers create and manage ResourceSlices in the cluster. When a ResourceClaim
  is created and used in a Pod, Kubernetes uses ResourceSlices to find nodes
  that have access to the claimed resources. Kubernetes allocates resources to
  the ResourceClaim and schedules the Pod onto a node that can access the
  resources.
-->
ResourceSlice
: 代表挂接到节点上的一个或多个资源，例如设备。
  驱动在集群中创建和管理 ResourceSlice。当 ResourceClaim 被创建并在 Pod 中使用时，
  Kubernetes 使用 ResourceSlice 查找能够访问已申领资源的节点。
  Kubernetes 将资源分配给 ResourceClaim，并将 Pod 调度到可以访问这些资源的节点上。

### DeviceClass {#deviceclass}

<!--
A DeviceClass lets cluster admins or device drivers define categories of devices
in the cluster. DeviceClasses tell operators what devices they can request and
how they can request those devices. You can use
[common expression language (CEL)](https://cel.dev) to select devices based on
specific attributes. A ResourceClaim that references the DeviceClass can then
request specific configurations within the DeviceClass.
-->
DeviceClass 允许集群管理员或设备驱动在集群中定义设备的类别。
DeviceClass 告知运维人员他们可以请求哪些设备，以及如何请求这些设备。
你可以使用[公共表达式语言（CEL）](https://cel.dev)根据特定属性选择设备。
引用 DeviceClass 的 ResourceClaim 随后可以请求 DeviceClass 中的特定配置。

<!--
To create a DeviceClass, see
[Set Up DRA in a Cluster](/docs/tasks/configure-pod-container/assign-resources/set-up-dra-cluster).
-->
要创建 DeviceClass，
请参阅[在集群中设置 DRA](/zh-cn/docs/tasks/configure-pod-container/assign-resources/set-up-dra-cluster)。

<!--
### ResourceClaims and ResourceClaimTemplates {#resourceclaims-templates}
-->
### ResourceClaim 与 ResourceClaimTemplate {#resourceclaims-templates}

<!--
A ResourceClaim defines the resources that a workload needs. Every ResourceClaim
has _requests_ that reference a DeviceClass and select devices from that
DeviceClass. ResourceClaims can also use _selectors_ to filter for devices that
meet specific requirements, and can use _constraints_ to limit the devices that
can satisfy a request. ResourceClaims can be created by workload operators or
can be generated by Kubernetes based on a ResourceClaimTemplate. A
ResourceClaimTemplate defines a template that Kubernetes can use to
auto-generate ResourceClaims for Pods.
-->
ResourceClaim 定义了工作负载所需的资源。每个 ResourceClaim 都包含
**requests**，它们引用一个 DeviceClass 并从该 DeviceClass 中选择设备。
ResourceClaim 还可以使用 **selectors** 过滤符合特定需求的设备，
并可以使用 **constraints** 限制能够满足请求的设备。
ResourceClaim 可以由工作负载运维人员创建，
也可以由 Kubernetes 基于 ResourceClaimTemplate 生成。
ResourceClaimTemplate 定义了一个模板，Kubernetes 可以使用该模板为 Pod
自动生成 ResourceClaim。

<!--
#### Use cases for ResourceClaims and ResourceClaimTemplates {#when-to-use-rc-rct}
-->
#### ResourceClaim 与 ResourceClaimTemplate 的使用场景 {#when-to-use-rc-rct}

<!--
The method that you use depends on your requirements, as follows:
-->
你使用的方法取决于你的需求，如下所述：

<!--
* **ResourceClaim**: you want multiple Pods to share access to specific
  devices. You manually manage the lifecycle of ResourceClaims that you create.
-->
* **ResourceClaim：** 你希望多个 Pod 共享对特定设备的访问。
  你手动管理你创建的 ResourceClaim 的生命周期。

<!--
* **ResourceClaimTemplate**: you want Pods to have independent access to
  separate, similarly-configured devices. Kubernetes generates ResourceClaims
  from the specification in the ResourceClaimTemplate. The lifetime of each
  generated ResourceClaim is bound to the lifetime of the corresponding Pod.
-->
* **ResourceClaimTemplate：** 你希望 Pod
  能够独立访问独立的、配置相似的设备。Kubernetes 根据 ResourceClaimTemplate 中的规约生成
  ResourceClaim。每个生成的 ResourceClaim 的生存期都绑定到对应 Pod 的生存期。

<!--
* [**PodGroup ResourceClaimTemplate**](#workload-resource-claims): you want
  <a class='glossary-tooltip' title='PodGroup 表示一组具有共同调度策略和约束的 Pod。' data-bs-toggle='tooltip' data-bs-placement='top' href='/zh-cn/docs/concepts/workloads/podgroup-api/' target='_blank' aria-label='PodGroups'>PodGroups</a> to have
  independent access to separate, similarly-configured devices that can be
  shared by their Pods. Kubernetes generates one ResourceClaim for the PodGroup
  from the specification in the ResourceClaimTemplate. The lifetime of each
  generated ResourceClaim is bound to the lifetime of the corresponding
  PodGroup. This requires the
  [`DRAWorkloadResourceClaims`](/docs/reference/command-line-tools-reference/feature-gates/#DRAWorkloadResourceClaims)
  feature to be enabled.
-->
* [**PodGroup ResourceClaimTemplate**](#workload-resource-claims)：
  你希望 <a class='glossary-tooltip' title='PodGroup 表示一组具有共同调度策略和约束的 Pod。' data-bs-toggle='tooltip' data-bs-placement='top' href='/zh-cn/docs/concepts/workloads/podgroup-api/' target='_blank' aria-label='PodGroup'>PodGroup</a>
  能够独立访问独立的、配置相似的设备，且其 Pod 可以共享这些设备。
  Kubernetes 根据 ResourceClaimTemplate 中的规约为 PodGroup 生成一个
  ResourceClaim。每个生成的 ResourceClaim 的生存期都绑定到对应 PodGroup
  的生存期。这要求启用
  [`DRAWorkloadResourceClaims`](/zh-cn/docs/reference/command-line-tools-reference/feature-gates/#DRAWorkloadResourceClaims)
  特性。

<!--
When you define a workload, you can use
<a class='glossary-tooltip' title='一种为安全执行用户代码而设计的表达式语言。' data-bs-toggle='tooltip' data-bs-placement='top' href='https://cel.dev' target='_blank' aria-label='Common Expression Language (CEL)'>Common Expression Language (CEL)</a>
to filter for specific device attributes or capacity. The available parameters
for filtering depend on the device and the drivers.
-->
当你定义工作负载时，可以使用
<a class='glossary-tooltip' title='一种为安全执行用户代码而设计的表达式语言。' data-bs-toggle='tooltip' data-bs-placement='top' href='https://cel.dev' target='_blank' aria-label='公共表达式语言（CEL）'>公共表达式语言（CEL）</a>
来过滤特定的设备属性或容量。可用于过滤的可用参数取决于设备和驱动。

<!--
If you directly reference a specific ResourceClaim in a Pod, that ResourceClaim
must already exist in the same namespace as the Pod. If the ResourceClaim
doesn't exist in the namespace, the Pod won't schedule. This behavior is similar
to how a PersistentVolumeClaim must exist in the same namespace as a Pod that
references it.
-->
如果你在 Pod 中直接引用特定的 ResourceClaim，该 ResourceClaim 必须已经存在于与
Pod 相同的名字空间中。如果 ResourceClaim 不存在于该名字空间中，
Pod 将无法调度。此行为类似于 PersistentVolumeClaim 必须存在于引用它的 Pod
所在的同一名字空间中。

<!--
You can reference an auto-generated ResourceClaim in a Pod, but this isn't
recommended because auto-generated ResourceClaims are bound to the lifetime of
the Pod or PodGroup that triggered the generation.
-->
你可以在 Pod 中引用自动生成的 ResourceClaim，但这并不推荐，
因为自动生成的 ResourceClaim 的生存期绑定到触发生成的 Pod 或 PodGroup 的生存期。

<!--
To learn how to claim resources using one of these methods, see
[Allocate Devices to Workloads with DRA](/docs/tasks/configure-pod-container/assign-resources/allocate-devices-dra/).
-->
要了解如何使用这些方法之一申领资源，
请参阅[使用 DRA 为工作负载分配设备](/zh-cn/docs/tasks/configure-pod-container/assign-resources/allocate-devices-dra/)。

<!--
#### Prioritized list {#prioritized-list}
-->
#### 优先级列表 {#prioritized-list}



















<div class="feature-state-notice feature-stable" title=" 特性门控： DRAPrioritizedList">
  <span class="feature-state-name">特性状态：</span>
  <span class="feature-state-details">
    
    <span class="feature-state-stage">GA</span> since Kubernetes v1.36; （默认启用）
    </span>
</div>


<div class="feature-stable">
  
  <details>
    <summary>More information about this feature</summary>
    <p><em>This is a stable feature in Kubernetes, and has been since version 1.36. It was first available in the v1.33 release.</em>
      </p>
  </details>

  
  </div>


<!--
You can provide a prioritized list of subrequests for requests in a ResourceClaim or
ResourceClaimTemplate. The scheduler will then select the first subrequest that can be allocated.
This allows users to specify alternative devices that can be used by the workload if the primary
choice is not available.
-->
你可以为 ResourceClaim 或 ResourceClaimTemplate 中的请求提供子请求的优先级列表。
调度器会选择第一个可以被分配的子请求。
这允许用户指定在首选方案不可用时工作负载可以使用的备选设备。

<!--
In the example below, the ResourceClaimTemplate requested a device with the color black
and the size large. If a device with those attributes is not available, the pod cannot
be scheduled. With the prioritized list feature, a second alternative can be specified, which
requests two devices with the color white and size small. The large black device will be
allocated if it is available. If it is not, but two small white devices are available,
the pod will still be able to run.
-->
在以下示例中，ResourceClaimTemplate 请求了一台颜色为黑色、尺寸为大号的设备。
如果没有具有这些属性的设备可用，Pod 将无法被调度。
借助优先级列表特性，可以指定第二个备选方案，即请求两台颜色为白色、尺寸为小号的设备。
如果大号黑色设备可用，将分配它；如果不可用，但有两台小号白色设备可用，Pod 仍然可以运行。

```yaml
apiVersion: resource.k8s.io/v1
kind: ResourceClaimTemplate
metadata:
  name: prioritized-list-claim-template
spec:
  spec:
    devices:
      requests:
      - name: req-0
        firstAvailable:
        - name: large-black
          deviceClassName: resource.example.com
          selectors:
          - cel:
              expression: |-
                device.attributes["resource-driver.example.com"].color == "black" &&
                device.attributes["resource-driver.example.com"].size == "large"
        - name: small-white
          deviceClassName: resource.example.com
          selectors:
          - cel:
              expression: |-
                device.attributes["resource-driver.example.com"].color == "white" &&
                device.attributes["resource-driver.example.com"].size == "small"
          count: 2
```

<!--
If the pod is eligible for multiple nodes in the cluster, the scheduler will use the
index of chosen subrequests from any prioritized lists as one of the inputs when it
scores each node. So nodes that can allocate devices requested in a higher ranked
subrequest are more likely to be chosen than nodes that can only allocate devices for
lower ranked subrequests.
-->
如果 Pod 适合在集群中的多个节点上运行，调度器在为每个节点打分时，
会将从任何优先级列表中选中的子请求的索引作为输入之一。
因此，能够分配更高级子请求中所请求设备的节点，
比只能分配较低级子请求设备的节点更有可能被选中。

<!--
The decision is made on a per-Pod basis, so if the Pod is a member of a ReplicaSet or
similar grouping, you cannot rely on all the members of the group having the same subrequest
chosen. Your workload must be able to accommodate this.
-->
该决策是按每个 Pod 单独作出的，因此如果 Pod 是 ReplicaSet 或类似分组的成员，
你不能依赖该组的所有成员都选用相同的子请求。你的工作负载必须能适应这一点。

<!--
#### Workload ResourceClaims {#workload-resource-claims}
-->
#### 工作负载 ResourceClaim {#workload-resource-claims}



















<div class="feature-state-notice feature-beta" title=" 特性门控： DRAWorkloadResourceClaims">
  <span class="feature-state-name">特性状态：</span>
  <span class="feature-state-details">
    
    <span class="feature-state-stage">Beta</span> since Kubernetes v1.37; （默认禁用）
    </span>
</div>


<div class="feature-beta">
  
  
  <details>
    <summary>More information about this feature</summary>
    <p>To use this feature, you (or a cluster administrator) will need to enable the <a href=\"/docs/reference/command-line-tools-reference/feature-gates/#DRAWorkloadResourceClaims\"><tt>DRAWorkloadResourceClaims</tt></a> feature gate for all relevant components in your cluster.</p>
<p>See <a href=\"/docs/tasks/administer-cluster/configure-feature-gates/\">Enable Or Disable Feature Gates</a> for more information.</p>

  </details>
  </div>


<!--
When you organize Pods with the
[Workload API](/docs/concepts/workloads/workload-api/),
you can reserve ResourceClaims for entire
<a class='glossary-tooltip' title='PodGroup 表示一组具有共同调度策略和约束的 Pod。' data-bs-toggle='tooltip' data-bs-placement='top' href='/zh-cn/docs/concepts/workloads/podgroup-api/' target='_blank' aria-label='PodGroups'>PodGroups</a>
instead of individual Pods and generate ResourceClaimTemplates for a
PodGroup instead of a single Pod, allowing the Pods within a PodGroup to share
access to devices allocated to the generated ResourceClaim.
-->
当你使用
[Workload API](/zh-cn/docs/concepts/workloads/workload-api/)
来组织 Pod 时，你可以为整个
<a class='glossary-tooltip' title='PodGroup 表示一组具有共同调度策略和约束的 Pod。' data-bs-toggle='tooltip' data-bs-placement='top' href='/zh-cn/docs/concepts/workloads/podgroup-api/' target='_blank' aria-label='PodGroup'>PodGroup</a>
预留 ResourceClaim，而不是为每个 Pod 单独预留；
并为 PodGroup 而非单个 Pod 生成 ResourceClaimTemplate，
从而允许 PodGroup 内的 Pod 共享对生成的 ResourceClaim 所分配设备的访问权。

<!--
This feature targets two problems:
-->
此特性针对两个问题：

<!--
- The ResourceClaim API's `status.reservedFor` list can only contain 256 items.
  Since kube-scheduler only records individual Pods in that list, only 256 Pods
  can share a ResourceClaim. By allowing PodGroups to be recorded in
  `status.reservedFor`, many more than 256 Pods can share a ResourceClaim.
-->
- ResourceClaim API 的 `status.reservedFor` 列表只能包含 256 项。
  由于 kube-scheduler 仅在该列表中记录单个 Pod，
  因此只能有 256 个 Pod 共享一个 ResourceClaim。
  通过允许将 PodGroup 记录在 `status.reservedFor` 中，
  远多于 256 个 Pod 可以共享一个 ResourceClaim。

<!--
- Pods can only share a ResourceClaim when its exact name is known. For complex
  workloads that replicate _groups_ of Pods, ResourceClaims shared by the Pods
  in each group need to be created and deleted explicitly when the set of
  groups scales up and down. By generating ResourceClaims for each PodGroup, a
  single ResourceClaimTemplate can form the basis for ResourceClaims that are
  both replicated automatically and shareable among the Pods in a PodGroup.
-->
- 只有当 ResourceClaim 的确切名称已知时，Pod 才能共享它。
  对于复制 **Pod 组**的复杂工作负载，当组的集合扩缩容时，
  每组中 Pod 共享的 ResourceClaim 都需要显式创建和删除。
  通过为每个 PodGroup 生成 ResourceClaim，
  单个 ResourceClaimTemplate 可以作为既被自动复制、又能在
  PodGroup 内的 Pod 之间共享的 ResourceClaim 的基础。

<!--
The PodGroup API defines a `spec.resourceClaims` field with the same structure
and similar meaning as the `spec.resourceClaims` field in the Pod API:
-->
PodGroup API 定义了一个 `spec.resourceClaims` 字段，其结构与 Pod API 中的
`spec.resourceClaims` 字段相同，含义也类似：

```yaml
apiVersion: scheduling.k8s.io/v1beta1
kind: PodGroup
metadata:
  name: training-group
  namespace: some-ns
spec:
  ...
  resourceClaims:
  - name: pg-claim
    resourceClaimName: my-pg-claim
  - name: pg-claim-template
    resourceClaimTemplateName: my-pg-template
```

<!--
Like claims made by Pods, claims for PodGroups defining a `resourceClaimName`
refer to a ResourceClaim by name. Claims defining a `resourceClaimTemplateName`
refer to a ResourceClaimTemplate which replicates into one ResourceClaim for the
entire PodGroup that can be shared amongst its Pods.
-->
与 Pod 提出的申领类似，定义了 `resourceClaimName` 的 PodGroup
申领按名称引用一个 ResourceClaim。定义了 `resourceClaimTemplateName`
的申领引用一个 ResourceClaimTemplate，该模板会复制为整个 PodGroup 的一个
ResourceClaim，供其 Pod 之间共享。

<!--
When a Pod defines a claim with a `name`, `resourceClaimName`, and
`resourceClaimTemplateName` that all match one of its PodGroup's
`spec.resourceClaims`, then kube-scheduler reserves the ResourceClaim for the
PodGroup instead of the Pod. If the Pod's claim does not match one made by its
PodGroup, then kube-scheduler reserves the ResourceClaim for the Pod. In either
case, reservation is recorded in the ResourceClaim's `status.reservedFor`.
PodGroup reservations and the corresponding resource allocation persist in the
ResourceClaim until the PodGroup is deleted, even if the group no longer has any
Pods.
-->
当 Pod 定义的申领的 `name`、`resourceClaimName` 和
`resourceClaimTemplateName` 全部与其 PodGroup 的某个
`spec.resourceClaims` 匹配时，kube-scheduler 会为 PodGroup
而非 Pod 预留该 ResourceClaim。如果 Pod 的申领与 PodGroup 的申领不匹配，
kube-scheduler 则为 Pod 预留 ResourceClaim。在这两种情况下，
预留都会记录在 ResourceClaim 的 `status.reservedFor` 中。
PodGroup 预留以及对应的资源分配会在 ResourceClaim 中持久存在，
直到 PodGroup 被删除，即使该组中不再有任何 Pod。

<!--
When a Pod claim matching a PodGroup claim defines a
`resourceClaimTemplateName`, then one ResourceClaim is generated for the
PodGroup. Other Pods in the group defining the same claim will share that
generated ResourceClaim instead of prompting a new ResourceClaim to be generated
for each Pod. Whether or not a `resourceClaimTemplateName` claim matches a
PodGroup claim, the name of the generated ResourceClaim is recorded in the Pod's
`status.resourceClaimStatuses`.
-->
当匹配 PodGroup 申领的 Pod 申领定义了 `resourceClaimTemplateName` 时，
会为 PodGroup 生成一个 ResourceClaim。组中定义了相同申领的其他 Pod
将共享该生成的 ResourceClaim，而不会为每个 Pod 触发新的 ResourceClaim 生成。
无论 `resourceClaimTemplateName` 申领是否匹配 PodGroup 申领，
生成的 ResourceClaim 的名称都会记录在 Pod 的 `status.resourceClaimStatuses` 中。

<!--
A matching PodGroup claim for a ResourceClaimTemplate only prompts the creation
of a ResourceClaim when the
[`DRAWorkloadResourceClaims`](/docs/reference/command-line-tools-reference/feature-gates/#DRAWorkloadResourceClaims)
feature is enabled. Instead of creating per-Pod ResourceClaims when the feature
is disabled, no ResourceClaim is created to prevent creating spurious per-Pod
ResourceClaims during cluster upgrades or rollouts/rollbacks of the feature
between `kube-apiserver` and `kube-controller-manager`.
-->
只有当
[`DRAWorkloadResourceClaims`](/zh-cn/docs/reference/command-line-tools-reference/feature-gates/#DRAWorkloadResourceClaims)
特性启用时，匹配的 PodGroup 申领才会触发 ResourceClaimTemplate 创建 ResourceClaim。
在该特性禁用时，不会创建 ResourceClaim，以避免在集群升级或 `kube-apiserver` 与
`kube-controller-manager` 之间进行特性滚动/回滚期间产生虚假的按 Pod 分配的
ResourceClaim。

<!--
ResourceClaims generated from a ResourceClaimTemplate for a
PodGroup follow the lifecycle of the PodGroup. The ResourceClaim is first
created when both the PodGroup and its ResourceClaimTemplate exist. The
ResourceClaim is deleted after the PodGroup has been deleted and the
ResourceClaim is no longer reserved.
-->
从 ResourceClaimTemplate 为 PodGroup 生成的 ResourceClaim 遵循 PodGroup
的生命周期。当 PodGroup 及其 ResourceClaimTemplate 都存在时，才会首次创建
ResourceClaim。在 PodGroup 已被删除且 ResourceClaim 不再被预留后，
ResourceClaim 会被删除。

<!--
Consider the following example:
-->
请看以下示例：

```yaml
apiVersion: scheduling.k8s.io/v1beta1
kind: PodGroup
metadata:
  name: training-group
  namespace: some-ns
spec:
  ...
  resourceClaims:
  - name: pg-claim
    resourceClaimName: my-pg-claim
  - name: pg-claim-template
    resourceClaimTemplateName: my-pg-template
---
apiVersion: v1
kind: Pod
metadata:
  name: training-group-pod-1
  namespace: some-ns
spec:
  ...
  schedulingGroup:
    podGroupName: training-group
  resourceClaims:
  - name: pod-claim
    resourceClaimName: my-pod-claim
  - name: pod-claim-template
    resourceClaimTemplateName: my-pod-template
  - name: pg-claim
    resourceClaimName: my-pg-claim
  - name: pg-claim-template
    resourceClaimTemplateName: my-pg-template
```

<!--
In this example, the `training-group` PodGroup has one Pod named `training-group-pod-1`.
The Pod's `pod-claim` and `pod-claim-template` claims do not match
any claim made by the PodGroup, so those claims are not affected by the
PodGroup: ResourceClaim `my-pod-claim` becomes reserved for the Pod and a
ResourceClaim is generated from ResourceClaimTemplate `my-pod-template` and also
becomes reserved for the Pod. The `pg-claim` and `pg-claim-template` do match
claims made by the PodGroup. ResourceClaim `my-pg-claim` becomes reserved for
the PodGroup and a ResourceClaim is generated from ResourceClaimTemplate
`my-pg-template` and also becomes reserved for the PodGroup.
-->
在此示例中，`training-group` PodGroup 有一个名为 `training-group-pod-1` 的 Pod。
Pod 的 `pod-claim` 和 `pod-claim-template` 申领不匹配 PodGroup 的任何申领，
因此这些申领不受 PodGroup 的影响：ResourceClaim `my-pod-claim` 变为为 Pod 预留，
并且从 ResourceClaimTemplate `my-pod-template` 生成一个 ResourceClaim，
同样变为为 Pod 预留。`pg-claim` 和 `pg-claim-template` 确实匹配 PodGroup
的申领。ResourceClaim `my-pg-claim` 变为为 PodGroup 预留，
并且从 ResourceClaimTemplate `my-pg-template` 生成一个 ResourceClaim，
同样变为为 PodGroup 预留。

<!--
Associating ResourceClaims with Workload API resources is controlled by the
[`DRAWorkloadResourceClaims` feature gate](/docs/reference/command-line-tools-reference/feature-gates/#DRAWorkloadResourceClaims)
in the `kube-apiserver`, `kube-controller-manager`, `kube-scheduler`, and `kubelet`.
-->
将 ResourceClaim 与 Workload API 资源关联由
`kube-apiserver`、`kube-controller-manager`、`kube-scheduler` 和 `kubelet` 中的
[`DRAWorkloadResourceClaims` 特性门控](/zh-cn/docs/reference/command-line-tools-reference/feature-gates/#DRAWorkloadResourceClaims)控制。

### ResourceSlice {#resourceslice}

<!--
Each ResourceSlice represents one or more
<a class='glossary-tooltip' title='直接或间接挂接到集群节点上的所有资源，例如 GPU 或电路板。' data-bs-toggle='tooltip' data-bs-placement='top' href='/zh-cn/docs/reference/glossary/?all=true#term-device' target='_blank' aria-label='devices'>devices</a> in a pool. The pool is
managed by a device driver, which creates and manages ResourceSlices. The
resources in a pool might be represented by a single ResourceSlice or span
multiple ResourceSlices.
-->
每个 ResourceSlice 代表一个池中一个或多个<a class='glossary-tooltip' title='直接或间接挂接到集群节点上的所有资源，例如 GPU 或电路板。' data-bs-toggle='tooltip' data-bs-placement='top' href='/zh-cn/docs/reference/glossary/?all=true#term-device' target='_blank' aria-label='设备'>设备</a>。
该池由设备驱动管理，驱动会创建和管理 ResourceSlice。
池中的资源可能由单个 ResourceSlice 表示，也可能跨越多个 ResourceSlice。

<!--
ResourceSlices provide useful information to device users and to the scheduler,
and are crucial for dynamic resource allocation. Every ResourceSlice must include
the following information:
-->
ResourceSlice 向设备使用者和调度器提供有用的信息，
并且对于动态资源分配至关重要。每个 ResourceSlice 必须包含以下信息：

<!--
* **Resource pool**: a group of one or more resources that the driver manages.
  The pool can span more than one ResourceSlice. Changes to the resources in a
  pool must be propagated across all of the ResourceSlices in that pool. The
  device driver that manages the pool is responsible for ensuring that this
  propagation happens.
-->
* **资源池（Resource pool）：** 驱动管理的一个或多个资源的组。
  池可以跨越多个 ResourceSlice。池中资源的变更必须在该池的所有
  ResourceSlice 之间传播。管理该池的设备驱动负责确保此传播发生。

<!--
* **Devices**: devices in the managed pool. A ResourceSlice can list every
  device in a pool or a subset of the devices in a pool. The ResourceSlice
  defines device information like attributes, versions, and capacity. Device
  users can select devices for allocation by filtering for device information
  in ResourceClaims or in DeviceClasses.
-->
* **设备（Devices）：** 被管理的池中的设备。
  ResourceSlice 可以列出池中的每个设备，也可以列出池中的设备子集。
  ResourceSlice 定义设备信息，例如属性、版本和容量。
  设备使用者可以通过在 ResourceClaim 或 DeviceClass 中过滤设备信息来选择要分配的设备。

<!--
* **Nodes**: the nodes that can access the resources. Drivers can choose which
  nodes can access the resources, whether that's all of the nodes in the
  cluster, a single named node, or nodes that have specific node labels.
-->
* **节点（Nodes）：** 可以访问这些资源的节点。
  驱动可以选择哪些节点可以访问资源，
  是集群中的所有节点、单个指定名称的节点，还是具有特定节点标签的节点。

<!--
Drivers use a <a class='glossary-tooltip' title='控制器通过 API 服务器监控集群的公共状态，并致力于将当前状态转变为期望的状态。' data-bs-toggle='tooltip' data-bs-placement='top' href='/zh-cn/docs/concepts/architecture/controller/' target='_blank' aria-label='controller'>controller</a> to
reconcile ResourceSlices in the cluster with the information that the driver has
to publish. This controller overwrites any manual changes, such as cluster users
creating or modifying ResourceSlices.
-->
驱动使用<a class='glossary-tooltip' title='控制器通过 API 服务器监控集群的公共状态，并致力于将当前状态转变为期望的状态。' data-bs-toggle='tooltip' data-bs-placement='top' href='/zh-cn/docs/concepts/architecture/controller/' target='_blank' aria-label='控制器'>控制器</a>将集群中的
ResourceSlice 与驱动必须发布的信息进行协调。
此控制器会覆写任何手动更改，例如集群用户创建或修改 ResourceSlice 的操作。

<!--
Consider the following example ResourceSlice:
-->
请看以下 ResourceSlice 示例：

<!--
# The allNodes field defines whether any node in the cluster can access the device.
-->
```yaml
apiVersion: resource.k8s.io/v1
kind: ResourceSlice
metadata:
  name: cat-slice
spec:
  driver: "resource-driver.example.com"
  pool:
    generation: 1
    name: "black-cat-pool"
    resourceSliceCount: 1
  # allNodes 字段定义集群中的任何节点是否都可以访问该设备。
  allNodes: true
  devices:
  - name: "large-black-cat"
    attributes:
      color:
        string: "black"
      size:
        string: "large"
      cat:
        bool: true
```

<!--
This ResourceSlice is managed by the `resource-driver.example.com` driver in the
`black-cat-pool` pool. The `allNodes: true` field indicates that any node in the
cluster can access the devices. There's one device in the ResourceSlice, named
`large-black-cat`, with the following attributes:
-->
该 ResourceSlice 由 `resource-driver.example.com` 驱动在 `black-cat-pool` 池中管理。
`allNodes: true` 字段表示集群中的任何节点都可以访问这些设备。
ResourceSlice 中有一台设备，名为 `large-black-cat`，具有以下属性：

* `color`：`black`
* `size`：`large`
* `cat`：`true`

<!--
A DeviceClass could select this ResourceSlice by using these attributes, and a
ResourceClaim could filter for specific devices in that DeviceClass.
-->
DeviceClass 可以使用这些属性选择此 ResourceSlice，
ResourceClaim 可以在该 DeviceClass 中过滤特定设备。

<!--
#### Naming and prioritization {#resourceslice-naming-and-prioritization}
-->
#### 命名与优先级 {#resourceslice-naming-and-prioritization}

<!--
The order in which the Kubernetes scheduler evaluates devices for allocation is
determined by the lexicographical sorting of ResourceSlice and resource pool names.
The scheduler uses a first-fit strategy, meaning it selects the first available device
that satisfies the claim's requirements.
-->
Kubernetes 调度器评估设备分配顺序的依据是 ResourceSlice
和资源池名称的字典序排序。调度器使用最先适应（first-fit）策略，
即选择满足申领需求的第一台可用设备。

<!--
This allows the priority of resource allocation to be influenced by the names
assigned to pools and ResourceSlices. Note that pools without
[binding conditions](/docs/concepts/resource-management/dynamic-resource-allocation/dra-features/#device-binding-conditions)
are always evaluated before those
with binding conditions, regardless of their names.
-->
这允许通过为池和 ResourceSlice 分配的名称来影响资源分配的优先级。
请注意，没有[绑定条件](/zh-cn/docs/concepts/resource-management/dynamic-resource-allocation/dra-features/#device-binding-conditions)
的池总是比具有绑定条件的池先被评估，无论它们的名称如何。

<!--
For drivers built using the `k8s.io/dynamic-resources/kubeletplugin` Go package or
the ResourceSlice controller from that module, these components automatically handle
ResourceSlice naming to ensure they are evaluated in the order specified by the driver.
-->
对于使用 `k8s.io/dynamic-resources/kubeletplugin` Go 包构建的驱动，
或使用该模块中的 ResourceSlice 控制器构建的驱动，
这些组件会自动处理 ResourceSlice 命名，
确保按照驱动指定的顺序进行评估。

<!--
## Admin access {#admin-access}
-->
## 管理员访问 {#admin-access}



















<div class="feature-state-notice feature-stable" title=" 特性门控： DRAAdminAccess">
  <span class="feature-state-name">特性状态：</span>
  <span class="feature-state-details">
    
    <span class="feature-state-stage">GA</span> since Kubernetes v1.36; （默认启用）
    </span>
</div>


<div class="feature-stable">
  
  <details>
    <summary>More information about this feature</summary>
    <p><em>This is a stable feature in Kubernetes, and has been since version 1.36. It was first available in the v1.32 release.</em>
      </p>
  </details>

  
  </div>


<!--
You can mark a request in a ResourceClaim or ResourceClaimTemplate as having
privileged features for maintenance and troubleshooting tasks. A request with
admin access grants access to in-use devices and may enable additional
permissions when making the device available in a container:
-->
你可以将 ResourceClaim 或 ResourceClaimTemplate 中的请求标记为具有特权特性，
用于维护和故障排查任务。具有管理员访问的请求可以授予对正在使用中设备的访问权限，
并可能在使设备在容器中可用时启用额外权限：

```yaml
apiVersion: resource.k8s.io/v1
kind: ResourceClaimTemplate
metadata:
  name: large-black-cat-claim-template
spec:
  spec:
    devices:
      requests:
      - name: req-0
        exactly:
          deviceClassName: resource.example.com
          allocationMode: All
          adminAccess: true
```

<!--
Admin access is a privileged mode and should not be granted to regular users in
multi-tenant clusters. Only users authorized to
create ResourceClaim or ResourceClaimTemplate objects in namespaces labeled with
`resource.kubernetes.io/admin-access: "true"` (case-sensitive) can use the
`adminAccess` field. This ensures that non-admin users cannot misuse the
feature.
-->
管理员访问是一种特权模式，在多租户集群中不应授予普通用户。
只有被授权在带有 `resource.kubernetes.io/admin-access: "true"`
（区分大小写）标签的名字空间中创建 ResourceClaim 或
ResourceClaimTemplate 对象的用户，才能使用 `adminAccess` 字段。
这确保了非管理员用户不会滥用此特性。

<!--
Admin access is controlled by the
[`DRAAdminAccess` feature gate](/docs/reference/command-line-tools-reference/feature-gates/#DRAAdminAccess)
in the `kube-apiserver`, `kube-scheduler`, and `kubelet`.
-->
管理员访问由 `kube-apiserver`、`kube-scheduler` 和 `kubelet` 中的
[`DRAAdminAccess` 特性门控](/zh-cn/docs/reference/command-line-tools-reference/feature-gates/#DRAAdminAccess)控制。

<!--
## List type attributes {#list-type-attributes}
-->
## 列表类型属性 {#list-type-attributes}



















<div class="feature-state-notice feature-alpha" title=" 特性门控： DRAListTypeAttributes">
  <span class="feature-state-name">特性状态：</span>
  <span class="feature-state-details">
    
    <span class="feature-state-stage">Alpha</span> since Kubernetes v1.36; （默认禁用）
    </span>
</div>


<div class="feature-alpha">
  
  
  <details>
    <summary>More information about this feature</summary>
    <p>To use this feature, you (or a cluster administrator) will need to enable the <a href=\"/docs/reference/command-line-tools-reference/feature-gates/#DRAListTypeAttributes\"><tt>DRAListTypeAttributes</tt></a> feature gate for all relevant components in your cluster.</p>
<p>See <a href=\"/docs/tasks/administer-cluster/configure-feature-gates/\">Enable Or Disable Feature Gates</a> for more information.</p>

  </details>
  </div>


<!--
This feature improves the ResourceSlice API, allowing DRA drivers to specify list values for device attributes instead of only scalars.
This is useful for modeling more complex internal node topologies, for example when a CPU has adjacency to multiple PCIe roots.
-->
此特性改进了 ResourceSlice API，允许 DRA 驱动为设备属性指定列表值，
而不仅仅是标量。这对于建模更复杂的节点内部拓扑非常有用，
例如当 CPU 与多个 PCIe 根节点相邻时。

<!--
For ResourceClaim authors (end users), this means that the `matchAttribute` and `distinctAttribute` work better for these cases.
-->
对于 ResourceClaim 的编写者（最终用户），
这意味着 `matchAttribute` 和 `distinctAttribute` 在此类场景下工作得更好。

<!--
- `matchAttribute` — the two attributes must have a *non-empty list intersection*, rather than be identical (scalar values are treated as single-item lists).
  This just means that if one driver publishes a single value for, say, the PCIe root, and another driver publishes a list, the constraint is met as long as
  the single value appears somewhere in the list.
-->
- `matchAttribute` — 两个属性必须具有**非空的列表交集**，
  而非完全相同（标量值被视为单项列表）。这仅意味着如果一个驱动为例如
  PCIe 根节点发布了单个值，而另一个驱动发布了一个列表，
  只要该单个值出现在列表中的某个位置，约束就被满足。

<!--
- `distinctAttribute` — the attribute values must be *pairwise-disjoint* (no value shared between any two devices)
-->
- `distinctAttribute` — 属性值必须**两两互不相交**（任意两台设备之间不共享任何值）。

<!--
To help ResourceClaim authors use attributes that may be lists inside CEL expressions, this feature also introduces an `includes()` CEL function.
-->
为了帮助 ResourceClaim 的编写者在 CEL 表达式中使用可能为列表的属性，
此特性还引入了 `includes()` CEL 函数。

<!--
```
# Scalar attribute (backward compatible)
# assume: device.attributes["dra.example.com"].model = "model-a"
device.attributes["dra.example.com"].model.includes("model-a")  # true
device.attributes["dra.example.com"].model.includes("model-b")  # false

# List-type attribute (requires DRAListTypeAttributes)
# assume: device.attributes["dra.example.com"].supported-models= ["model-a", "model-b"]
device.attributes["dra.example.com"].supported-models.includes("model-a")  # true
device.attributes["dra.example.com"].supported-models.includes("model-c")  # false
```
-->
```
# 标量属性（向后兼容）
# 假设：device.attributes["dra.example.com"].model = "model-a"
device.attributes["dra.example.com"].model.includes("model-a")  # true
device.attributes["dra.example.com"].model.includes("model-b")  # false

# 列表类型属性（需要 DRAListTypeAttributes）
# 假设：device.attributes["dra.example.com"].supported-models = ["model-a", "model-b"]
device.attributes["dra.example.com"].supported-models.includes("model-a")  # true
device.attributes["dra.example.com"].supported-models.includes("model-c")  # false
```

<!--
### Details for DRA Driver Authors
-->
### DRA 驱动编写者的细节

<!--
By default, each `DeviceAttribute` holds exactly one scalar value: a boolean, an integer,
a string, or a semantic version string. The `DRAListTypeAttributes` feature gate extends
`DeviceAttribute` with four list-type fields, allowing a device to advertise multiple
values for a single attribute:
-->
默认情况下，每个 `DeviceAttribute` 恰好保存一个标量值：
布尔值、整数、字符串或语义版本字符串。
`DRAListTypeAttributes` 特性门控为 `DeviceAttribute` 扩展了四个列表类型字段，
允许设备为单个属性通告多个值：

<!--
- **`bools`** — a list of boolean values
- **`ints`** — a list of 64-bit integer values
- **`strings`** — a list of strings (each at most 64 characters)
- **`versions`** — a list of semantic version strings per semver.org spec 2.0.0
  (each at most 64 characters)
-->
- **`bools`** — 布尔值列表
- **`ints`** — 64 位整数值列表
- **`strings`** — 字符串列表（每项最多 64 个字符）
- **`versions`** — 符合 semver.org 规范 2.0.0 的语义版本字符串列表
  （每项最多 64 个字符）

<!--
The total number of individual attribute values per device (scalar fields plus all list
elements combined) is limited to **48**. When any device in a ResourceSlice uses this feature or other advanced features such as taints,
the ResourceSlice will be limited to at most **64** devices.
use list-type attributes or other advanced features such as taints.
-->
每台设备的单个属性值总数（标量字段加上所有列表元素的总和）上限为 **48**。
当 ResourceSlice 中的任何设备使用此特性或其他高级特性（如污点）时，
ResourceSlice 最多被限制为 **64** 台设备。

<!--
Here is an example of a device advertising multiple supported models using a list-type
string attribute:
-->
以下是一台设备使用列表类型字符串属性通告多个支持型号的示例：

```yaml
kind: ResourceSlice
apiVersion: resource.k8s.io/v1
metadata:
  name: example-resourceslice
spec:
  nodeName: worker-1
  pool:
    name: pool
    generation: 1
    resourceSliceCount: 1
  driver: dra.example.com
  devices:
  - name: gpu-0
    attributes:
      dra.example.com/supported-models:
        strings:
        - model-a
        - model-b
```

<!--
List type attributes is controlled by the
[`DRAListTypeAttributes` feature gate](/docs/reference/command-line-tools-reference/feature-gates/#DRAListTypeAttributes)
in the `kube-apiserver` and `kube-scheduler`.
-->
列表类型属性由 `kube-apiserver` 和 `kube-scheduler` 中的
[`DRAListTypeAttributes` 特性门控](/zh-cn/docs/reference/command-line-tools-reference/feature-gates/#DRAListTypeAttributes)控制。

<!--
## Derived attributes {#derived-attributes}
-->
## 派生属性 {#derived-attributes}



















<div class="feature-state-notice feature-alpha" title=" 特性门控： DRADerivedAttributes">
  <span class="feature-state-name">特性状态：</span>
  <span class="feature-state-details">
    
    <span class="feature-state-stage">Alpha</span> since Kubernetes v1.37; （默认禁用）
    </span>
</div>


<div class="feature-alpha">
  
  
  <details>
    <summary>More information about this feature</summary>
    <p>To use this feature, you (or a cluster administrator) will need to enable the <a href=\"/docs/reference/command-line-tools-reference/feature-gates/#DRADerivedAttributes\"><tt>DRADerivedAttributes</tt></a> feature gate for all relevant components in your cluster.</p>
<p>See <a href=\"/docs/tasks/administer-cluster/configure-feature-gates/\">Enable Or Disable Feature Gates</a> for more information.</p>

  </details>
  </div>


<!--
The `matchAttribute` and `distinctAttribute` constraints normally require
devices to publish attributes under the exact same name. If a GPU driver
publishes `pcie_locality` and a NIC driver publishes `pcie_root` (or embeds
the same information in a string like `numa0-pcie1`), the scheduler has no
way to recognize that these represent the same thing, so devices from the
two drivers can't be co-located without first agreeing on a shared
attribute name.
-->
通常，`matchAttribute` 和 `distinctAttribute` 约束要求设备
使用完全相同的名称来发布属性。如果 GPU 驱动发布 `pcie_locality`，
而 NIC 驱动发布 `pcie_root`（或将相同信息嵌入到诸如 `numa0-pcie1` 的字符串中），
调度器无法识别它们表示的是同一事物，
因此来自两个驱动的设备无法被共置，除非先就共享属性名称达成一致。

<!--
`derivedAttributes` lets you bridge this gap inline, without waiting for
drivers to standardize on shared attribute names. Add one or more
`derivedAttributes` entries to a request, under
`.spec.devices.requests[].exactly` or
`.spec.devices.requests[].firstAvailable[]`. Each entry defines a CEL
expression that the scheduler evaluates against every candidate device for
that request. The result becomes a virtual attribute that can be referenced
from a `matchAttribute` or `distinctAttribute` constraint exactly like a
driver-provided device attribute.
-->
`derivedAttributes` 让你可以就地弥合这一差距，
而无需等待驱动在共享属性名称上实现标准化。
在请求的 `.spec.devices.requests[].exactly` 或
`.spec.devices.requests[].firstAvailable[]` 下添加一个或多个
`derivedAttributes` 条目。每个条目定义一个 CEL 表达式，
调度器会针对该请求的每个候选设备评估该表达式。
评估结果成为一个虚拟属性，可以与驱动提供的设备属性完全一样地被
`matchAttribute` 或 `distinctAttribute` 约束引用。

```yaml
apiVersion: resource.k8s.io/v1
kind: ResourceClaim
metadata:
  name: gpu-nic-numa-alignment
spec:
  devices:
    requests:
    - name: gpu
      exactly:
        deviceClassName: gpu.example.com
        count: 1
        derivedAttributes:
        - name: derived/numa
          expression: device.attributes["gpu.example.com"].numa
    - name: nic
      exactly:
        deviceClassName: nic.example.com
        count: 1
        derivedAttributes:
        - name: derived/numa
          expression: device.attributes["nic.example.com"].numaNode
    constraints:
    - requests: ["gpu", "nic"]
      matchAttribute: derived/numa
```

<!--
In this example, the `gpu` and `nic` drivers publish topology information
under different attribute names (`numa` and `numaNode`). Each request
computes a common `derived/numa` value from its own device's attributes,
and the `matchAttribute` constraint aligns the two requests on that virtual
attribute, even though the underlying drivers never agreed on a shared
attribute name.
-->
在此示例中，`gpu` 和 `nic` 驱动使用不同的属性名称（`numa` 和 `numaNode`）来发布拓扑信息。
每个请求都从自己的设备属性中计算出一个公共的 `derived/numa` 值，
而 `matchAttribute` 约束将两个请求在该虚拟属性上对齐，
即使底层驱动从未就共享属性名称达成一致。

<!--
A few things to know about `derivedAttributes`:
-->
关于 `derivedAttributes` 需要了解以下几点：

<!--
- **Naming**: `name` must be a DNS subdomain followed by a `/` and a C
  identifier, the same format used for driver-provided attribute names (for
  example, `example.com/numaNode` or `derived/numaNode`). If the name
  matches a driver-provided attribute already published by the driver,
  the derived attribute's value shadows the driver-provided one for
  constraint matching. Use a domain prefix that no driver would use,
  such as `derived/`, if you want to avoid shadowing unintentionally.
  You can define up to 32 derived attributes per request.
-->
- **命名：** `name` 必须是一个 DNS 子域名，后跟 `/` 和一个 C 标识符，
  格式与驱动提供的属性名称相同（例如 `example.com/numaNode` 或
  `derived/numaNode`）。如果该名称与驱动已经发布的驱动提供属性相匹配，
  则派生属性的值会在约束匹配时遮蔽驱动提供的属性。
  如果你希望避免无意中发生遮蔽，请使用不会被任何驱动使用的域名前缀，
  例如 `derived/`。每个请求最多可以定义 32 个派生属性。

<!--
- **Must be used by a constraint**: every derived attribute must be
  referenced by at least one `matchAttribute` or `distinctAttribute`
  constraint that applies to the request (or subrequest) that defines it.
  Otherwise the ResourceClaim fails validation.
-->
- **必须被约束使用：** 每个派生属性必须被至少一个应用于定义它的请求（或子请求）的
  `matchAttribute` 或 `distinctAttribute` 约束引用。
  否则 ResourceClaim 验证会失败。

<!--
- **Evaluation scope and order**: `expression` is evaluated once per
  candidate device, after the request's own CEL selectors
  (`.selectors[].cel`) have already filtered that device. As a result,
  derived attributes can't be referenced from selector expressions, and
  aren't exposed through `device.attributes` in the CEL environment.
-->
- **评估范围和顺序：** `expression` 对每个候选设备评估一次，
  评估发生在请求自己的 CEL 选择算符（`.selectors[].cel`）
  已经过滤完该设备之后。因此，派生属性不能被选择算符表达式引用，
  也不会通过 CEL 环境中的 `device.attributes` 暴露。

<!--
- **Return type**: `expression` must evaluate to a scalar (`string`, `int`,
  `bool`, or a semantic version) or, when the `DRAListTypeAttributes`
  feature gate is also enabled, a list of one of those scalar types.
-->
- **返回类型：** `expression` 必须评估为一个标量（`string`、`int`、`bool`
  或语义版本），或者当同时启用了 `DRAListTypeAttributes` 特性门控时，
  评估为上述标量类型之一的列表。

<!--
- **Cost limits**: each expression has a maximum length and a limit on its
  estimated CEL evaluation cost. On top of that, the combined estimated cost
  of all `derivedAttributes` expressions in a ResourceClaim is also capped,
  to bound the total overhead added to a single scheduling attempt. The
  ResourceClaim is rejected if any of these limits are exceeded.
-->
- **开销限制：** 每个表达式都有最大长度和 CEL 评估开销估算上限。
  除此之外，ResourceClaim 中所有 `derivedAttributes`
  表达式的组合估算开销也有上限，以限制单次调度尝试的总附加开销。
  如果超出上述任何限制，ResourceClaim 将被拒绝。

<!--
- **Runtime errors abort scheduling**: if evaluating an expression fails for
  a candidate device, for example because it references an attribute that
  device doesn't have, the scheduler aborts allocation and the Pod fails to
  schedule, rather than silently skipping that device. Write expressions
  defensively, for example by checking that an attribute exists before
  reading it.
-->
- **运行时错误会中止调度：** 如果对某个候选设备的表达式评估失败（例如因为它引用了该设备没有的属性），
  调度器会中止分配，且该 Pod 会调度失败，而不是静默跳过该设备。
  请以防御方式编写表达式，例如在读取属性之前先检查它是否存在。

<!--
Derived attributes is controlled by the
[`DRADerivedAttributes` feature gate](/docs/reference/command-line-tools-reference/feature-gates/#DRADerivedAttributes)
in the `kube-apiserver` and `kube-scheduler`.
-->
派生属性由 `kube-apiserver` 和 `kube-scheduler` 中的
[`DRADerivedAttributes` 特性门控](/zh-cn/docs/reference/command-line-tools-reference/feature-gates/#DRADerivedAttributes)
控制。

<!--
For a list of standard device attributes that DRA drivers can publish, see the
[Standard Device Attributes](/docs/reference/node/dra-standard-device-attributes/)
reference.
-->
有关 DRA 驱动可以发布的标准设备属性列表，
请参阅[标准设备属性](/zh-cn/docs/reference/node/dra-standard-device-attributes/)参考。

<!--
## Extended resource allocation by DRA {#extended-resource}
-->
## 通过 DRA 的扩展资源分配 {#extended-resource}



















<div class="feature-state-notice feature-stable" title=" 特性门控： DRAExtendedResource">
  <span class="feature-state-name">特性状态：</span>
  <span class="feature-state-details">
    
    <span class="feature-state-stage">GA</span> since Kubernetes v1.37; （默认启用）
    </span>
</div>


<div class="feature-stable stable-in-latest-release">
  
  <details>
    <summary>More information about this feature</summary>
    <p><em>This is a stable feature in Kubernetes, and has been since version 1.37. It was first available in the v1.34 release.</em>
      </p>
  </details>

  
  </div>


<!--
You can provide an extended resource name for a DeviceClass. The scheduler will then
select the devices matching the class for the extended resource requests.
This allows users to continue using extended resource requests in a pod to request
either extended resources provided by device plugin, or DRA devices.
The same extended resource can be provided either by device plugin, or DRA on one single cluster node.
The same extended resource can be provided by device plugin on some nodes, and DRA on other nodes in the same cluster.
-->
你可以为 DeviceClass 提供一个扩展资源名称。调度器随后会为扩展资源请求选择匹配该类的设备。
这允许用户继续在 Pod 中使用扩展资源请求，
来请求由设备插件提供的扩展资源，或 DRA 设备。
在单个集群节点上，同一扩展资源可以由设备插件提供，也可以由 DRA 提供。
在同一集群中，某些节点上的同一扩展资源可以由设备插件提供，
而其他节点上可以由 DRA 提供。

<!--
In the example below, the DeviceClass is given an extendedResourceName `example.com/gpu`.
If a pod requested for the extended resource `example.com/gpu: 2`, it can be scheduled to
a node with two or more devices matching the DeviceClass.
-->
在以下示例中，DeviceClass 被赋予了一个 `example.com/gpu` 的 extendedResourceName。
如果 Pod 请求扩展资源 `example.com/gpu: 2`，
它可以被调度到具有两台或更多匹配该 DeviceClass 设备的节点上。

```yaml
apiVersion: resource.k8s.io/v1
kind: DeviceClass
metadata:
  name: gpu.example.com
spec:
  selectors:
  - cel:
      expression: device.driver == 'gpu.example.com' && device.attributes['gpu.example.com'].type
        == 'gpu'
  extendedResourceName: example.com/gpu
```

<!--
In addition, users can use a special extended resource to allocate devices without
having to explicitly create a ResourceClaim. Using the extended resource name
prefix `deviceclass.resource.kubernetes.io/` and the DeviceClass name.
This works for any DeviceClass, even if it does not specify an extended resource name.
The resulting ResourceClaim will contain a request for an `ExactCount` of the
specified number of devices of that DeviceClass.
-->
此外，用户可以使用一种特殊的扩展资源来分配设备，而无需显式创建 ResourceClaim。
使用扩展资源名称前缀 `deviceclass.resource.kubernetes.io/` 加上 DeviceClass 名称即可。
这对任何 DeviceClass 都有效，即使它没有指定扩展资源名称。
生成的 ResourceClaim 将包含一个请求，要求分配该 DeviceClass 的指定数量设备的
`ExactCount`。

<!--
Extended resource allocation by DRA is controlled by the
[`DRAExtendedResource` feature gate](/docs/reference/command-line-tools-reference/feature-gates/#DRAExtendedResource)
in the `kube-apiserver`, `kube-scheduler`, `kube-controller-manager`, and `kubelet`.
-->
通过 DRA 的扩展资源分配由
`kube-apiserver`、`kube-scheduler`、`kube-controller-manager` 和 `kubelet` 中的
[`DRAExtendedResource` 特性门控](/zh-cn/docs/reference/command-line-tools-reference/feature-gates/#DRAExtendedResource)控制。

<!--
For a hands-on walkthrough of requesting extended resources, see
[Assign Extended Resources to a Container](/docs/tasks/configure-pod-container/extended-resource/).
-->
有关请求扩展资源的实际演练，
请参阅[将扩展资源分配给容器](/zh-cn/docs/tasks/configure-pod-container/extended-resource/)。
