|
| 1 | +--- |
| 2 | +title: 卷属性类 |
| 3 | +content_type: concept |
| 4 | +weight: 40 |
| 5 | +--- |
| 6 | +<!-- |
| 7 | +reviewers: |
| 8 | +- msau42 |
| 9 | +- xing-yang |
| 10 | +title: Volume Attributes Classes |
| 11 | +content_type: concept |
| 12 | +weight: 40 |
| 13 | +--> |
| 14 | + |
| 15 | +<!-- overview --> |
| 16 | + |
| 17 | +{{< feature-state for_k8s_version="v1.29" state="alpha" >}} |
| 18 | + |
| 19 | +<!-- |
| 20 | +This page assumes that you are familiar with [StorageClasses](/docs/concepts/storage/storage-classes/), |
| 21 | +[volumes](/docs/concepts/storage/volumes/) and [PersistentVolumes](/docs/concepts/storage/persistent-volumes/) |
| 22 | +in Kubernetes. |
| 23 | +--> |
| 24 | +本页假设你已经熟悉 Kubernetes 中的 [StorageClass](/zh-cn/docs/concepts/storage/storage-classes/)、 |
| 25 | +[Volume](/zh-cn/docs/concepts/storage/volumes/) 和 |
| 26 | +[PersistentVolume](/zh-cn/docs/concepts/storage/persistent-volumes/)。 |
| 27 | + |
| 28 | +<!-- body --> |
| 29 | + |
| 30 | +<!-- |
| 31 | +A VolumeAttributesClass provides a way for administrators to describe the mutable |
| 32 | +"classes" of storage they offer. Different classes might map to different quality-of-service levels. |
| 33 | +Kubernetes itself is unopinionated about what these classes represent. |
| 34 | +
|
| 35 | +This is an alpha feature and disabled by default. |
| 36 | +
|
| 37 | +If you want to test the feature whilst it's alpha, you need to enable the `VolumeAttributesClass` |
| 38 | +[feature gate](/docs/reference/command-line-tools-reference/feature-gates/) for the kube-controller-manager and the kube-apiserver. You use the `--feature-gates` command line argument: |
| 39 | +--> |
| 40 | +卷属性类(VolumeAttributesClass)为管理员提供了一种描述可变更的存储“类”的方法。 |
| 41 | +不同的类可以映射到不同的服务质量级别。Kubernetes 本身不关注这些类代表什么。 |
| 42 | + |
| 43 | +这是一个 Alpha 特性,默认被禁用。 |
| 44 | + |
| 45 | +如果你想测试这一处于 Alpha 阶段的特性,你需要为 kube-controller-manager 和 kube-apiserver 启用 |
| 46 | +`VolumeAttributesClass` [特性门控](/zh-cn/docs/reference/command-line-tools-reference/feature-gates/)。 |
| 47 | +你可以使用 `--feature-gates` 命令行参数: |
| 48 | + |
| 49 | +``` |
| 50 | +--feature-gates="...,VolumeAttributesClass=true" |
| 51 | +``` |
| 52 | + |
| 53 | +<!-- |
| 54 | +You can also only use VolumeAttributesClasses with storage backed by |
| 55 | +{{< glossary_tooltip text="Container Storage Interface" term_id="csi" >}}, and only where the |
| 56 | +relevant CSI driver implements the `ModifyVolume` API. |
| 57 | +--> |
| 58 | +另外你只有在使用{{< glossary_tooltip text="容器存储接口(CSI)" term_id="csi" >}}支持的存储时才能使用 |
| 59 | +VolumeAttributesClass,并且要求相关的 CSI 驱动实现了 `ModifyVolume` API。 |
| 60 | + |
| 61 | +<!-- |
| 62 | +## The VolumeAttributesClass API |
| 63 | +
|
| 64 | +Each VolumeAttributesClass contains the `driverName` and `parameters`, which are |
| 65 | +used when a PersistentVolume (PV) belonging to the class needs to be dynamically provisioned |
| 66 | +or modified. |
| 67 | +
|
| 68 | +The name of a VolumeAttributesClass object is significant and is how users can request a particular class. |
| 69 | +Administrators set the name and other parameters of a class when first creating VolumeAttributesClass objects. |
| 70 | +While the name of a VolumeAttributesClass object in a `PersistentVolumeClaim` is mutable, the parameters in an existing class are immutable. |
| 71 | +--> |
| 72 | +## VolumeAttributesClass API {#the-volumeattributesclass-api} |
| 73 | + |
| 74 | +每个 VolumeAttributesClass 都包含 `driverName` 和 `parameters` 字段, |
| 75 | +当属于此类的持久卷(PV)需要被动态制备或修改时系统会使用这两个字段。 |
| 76 | + |
| 77 | +VolumeAttributesClass 对象的名称比较重要,用户用对象名称来请求特定的类。 |
| 78 | +管理员在首次创建 VolumeAttributesClass 对象时会设置某个类的名称和其他参数。 |
| 79 | +虽然在 `PersistentVolumeClaim` 中 VolumeAttributesClass 对象的名称是可变的, |
| 80 | +但现有类中的参数是不可变的。 |
| 81 | + |
| 82 | +```yaml |
| 83 | +apiVersion: storage.k8s.io/v1alpha1 |
| 84 | +kind: VolumeAttributesClass |
| 85 | +metadata: |
| 86 | + name: silver |
| 87 | +driverName: pd.csi.storage.gke.io |
| 88 | +parameters: |
| 89 | + provisioned-iops: "3000" |
| 90 | + provisioned-throughput: "50" |
| 91 | +``` |
| 92 | +
|
| 93 | +
|
| 94 | +<!-- |
| 95 | +### Provisioner |
| 96 | +
|
| 97 | +Each VolumeAttributesClass has a provisioner that determines what volume plugin is used for provisioning PVs. The field `driverName` must be specified. |
| 98 | + |
| 99 | +The feature support for VolumeAttributesClass is implemented in [kubernetes-csi/external-provisioner](https://github.com/kubernetes-csi/external-provisioner). |
| 100 | +--> |
| 101 | +### 存储制备器 {#provisioner} |
| 102 | + |
| 103 | +每个 VolumeAttributesClass 都有一个制备器(Provisioner),用来决定使用哪个卷插件制备 PV。 |
| 104 | +`driverName` 字段是必填项。 |
| 105 | + |
| 106 | +针对 VolumeAttributesClass 的特性支持在 |
| 107 | +[kubernetes-csi/external-provisioner](https://github.com/kubernetes-csi/external-provisioner) 中实现。 |
| 108 | + |
| 109 | +<!-- |
| 110 | +You are not restricted to specifying the [kubernetes-csi/external-provisioner](https://github.com/kubernetes-csi/external-provisioner). You can also run and specify external provisioners, |
| 111 | +which are independent programs that follow a specification defined by Kubernetes. |
| 112 | +Authors of external provisioners have full discretion over where their code lives, how |
| 113 | +the provisioner is shipped, how it needs to be run, what volume plugin it uses, etc. |
| 114 | +--> |
| 115 | +你并非必须指定 [kubernetes-csi/external-provisioner](https://github.com/kubernetes-csi/external-provisioner)。 |
| 116 | +你也可以运行并指定外部制备器,它们是遵循 Kubernetes 所定义的规范的独立程序。 |
| 117 | +外部制备器的作者可以完全自行决定他们的代码放在哪儿、如何交付制备器、以何种方式运行、使用什么卷插件等。 |
| 118 | + |
| 119 | +<!-- |
| 120 | +### Resizer |
| 121 | + |
| 122 | +Each VolumeAttributesClass has a resizer that determines what volume plugin is used for modifying PVs. The field `driverName` must be specified. |
| 123 | + |
| 124 | +The modifying volume feature support for VolumeAttributesClass is implemented in [kubernetes-csi/external-resizer](https://github.com/kubernetes-csi/external-resizer). |
| 125 | + |
| 126 | +For example, a existing PersistentVolumeClaim is using a VolumeAttributesClass named silver: |
| 127 | +--> |
| 128 | +### 调整器 {#resizer} |
| 129 | + |
| 130 | +每个 VolumeAttributesClass 都有一个调整器(Resizer),用于确定修改 PV 所用的卷插件。 |
| 131 | +`driverName` 字段是必填项。 |
| 132 | + |
| 133 | +针对 VolumeAttributesClass 的修改卷特性支持在 |
| 134 | +[kubernetes-csi/external-resizer](https://github.com/kubernetes-csi/external-resizer) 中实现。 |
| 135 | + |
| 136 | +如以下 YAML 所示,有一个 PersistentVolumeClaim 使用名为 silver 的 VolumeAttributesClass: |
| 137 | + |
| 138 | +```yaml |
| 139 | +apiVersion: v1 |
| 140 | +kind: PersistentVolumeClaim |
| 141 | +metadata: |
| 142 | + name: test-pv-claim |
| 143 | +spec: |
| 144 | + … |
| 145 | + volumeAttributesClassName: silver |
| 146 | + … |
| 147 | +``` |
| 148 | + |
| 149 | +<!-- |
| 150 | +A new VolumeAttributesClass gold is available in the cluster: |
| 151 | +--> |
| 152 | +集群中有一个新的名为 gold 的 VolumeAttributesClass: |
| 153 | + |
| 154 | +```yaml |
| 155 | +apiVersion: storage.k8s.io/v1alpha1 |
| 156 | +kind: VolumeAttributesClass |
| 157 | +metadata: |
| 158 | + name: gold |
| 159 | +driverName: pd.csi.storage.gke.io |
| 160 | +parameters: |
| 161 | + iops: "4000" |
| 162 | + throughput: "60" |
| 163 | +``` |
| 164 | + |
| 165 | +<!-- |
| 166 | +The end user can update the PVC with the new VolumeAttributesClass gold and apply: |
| 167 | +--> |
| 168 | +最终用户可以更新 PVC,使之使用新的名为 gold 的 VolumeAttributesClass,并应用此更新: |
| 169 | + |
| 170 | +```yaml |
| 171 | +apiVersion: v1 |
| 172 | +kind: PersistentVolumeClaim |
| 173 | +metadata: |
| 174 | + name: test-pv-claim |
| 175 | +spec: |
| 176 | + … |
| 177 | + volumeAttributesClassName: gold |
| 178 | + … |
| 179 | +``` |
| 180 | + |
| 181 | +<!-- |
| 182 | +## Parameters |
| 183 | + |
| 184 | +VolumeAttributeClasses have parameters that describe volumes belonging to them. Different parameters may be accepted |
| 185 | +depending on the provisioner or the resizer. For example, the value `4000`, for the parameter `iops`, |
| 186 | +and the parameter `throughput` are specific to GCE PD. |
| 187 | +When a parameter is omitted, the default is used at volume provisioning. |
| 188 | +If a user apply the PVC with a different VolumeAttributesClass with omitted parameters, the default value of |
| 189 | +the parameters may be used depends on the CSI driver implementation. |
| 190 | +Please refer to the related CSI driver documentation for more details. |
| 191 | +--> |
| 192 | +## 参数 {#parameters} |
| 193 | + |
| 194 | +VolumeAttributeClass 具有参数,用来描述隶属于该类的存储卷。可接受的参数可能因制备器或调整器而异。 |
| 195 | +例如,参数 `iops` 的取值 `4000` 和参数 `throughput` 是特定于 GCE PD 的。 |
| 196 | +如果某个参数被省略,则在卷制备时使用默认值。 |
| 197 | +如果用户使用带有省略参数的不同 VolumeAttributesClass 来应用 PVC,参数的默认取值可能会因 CSI 驱动实现而异。 |
| 198 | +有关细节参阅相关的 CSI 驱动文档。 |
| 199 | + |
| 200 | +<!-- |
| 201 | +There can be at most 512 parameters defined for a VolumeAttributesClass. |
| 202 | +The total length of the parameters object including its keys and values cannot exceed 256 KiB. |
| 203 | +--> |
| 204 | +VolumeAttributesClass 最多可以定义 512 个参数。 |
| 205 | +这些参数对象的总长度(包括其键和值)不能超过 256 KiB。 |
0 commit comments