|
| 1 | +--- |
| 2 | +layout: blog |
| 3 | +title: "Kubernetes 1.31:通过 VolumeAttributesClass 修改卷进阶至 Beta" |
| 4 | +date: 2024-08-15 |
| 5 | +slug: kubernetes-1-31-volume-attributes-class |
| 6 | +author: > |
| 7 | + Sunny Song (Google) |
| 8 | + Matthew Cary (Google) |
| 9 | +translator: > |
| 10 | + [windsonsea](https://github.com/windsonsea) (DaoCloud) |
| 11 | +--- |
| 12 | +<!-- |
| 13 | +layout: blog |
| 14 | +title: "Kubernetes 1.31: VolumeAttributesClass for Volume Modification Beta" |
| 15 | +date: 2024-08-15 |
| 16 | +slug: kubernetes-1-31-volume-attributes-class |
| 17 | +author: > |
| 18 | + Sunny Song (Google) |
| 19 | + Matthew Cary (Google) |
| 20 | +--> |
| 21 | + |
| 22 | +<!-- |
| 23 | +Volumes in Kubernetes have been described by two attributes: their storage class, and |
| 24 | +their capacity. The storage class is an immutable property of the volume, while the |
| 25 | +capacity can be changed dynamically with [volume |
| 26 | +resize](https://kubernetes.io/docs/concepts/storage/persistent-volumes/#expanding-persistent-volumes-claims). |
| 27 | +
|
| 28 | +This complicates vertical scaling of workloads with volumes. While cloud providers and |
| 29 | +storage vendors often offer volumes which allow specifying IO quality of service |
| 30 | +(Performance) parameters like IOPS or throughput and tuning them as workloads operate, |
| 31 | +Kubernetes has no API which allows changing them. |
| 32 | +--> |
| 33 | +在 Kubernetes 中,卷由两个属性描述:存储类和容量。存储类是卷的不可变属性, |
| 34 | +而容量可以通过[卷调整大小](/zh-cn/docs/concepts/storage/persistent-volumes/#expanding-persistent-volumes-claims)进行动态变更。 |
| 35 | + |
| 36 | +这使得使用卷的工作负载的垂直扩缩容变得复杂。 |
| 37 | +虽然云厂商和存储供应商通常提供了一些允许指定注入 IOPS 或吞吐量等 IO |
| 38 | +服务质量(性能)参数的卷,并允许在工作负载运行期间调整这些参数,但 Kubernetes |
| 39 | +没有提供用来更改这些参数的 API。 |
| 40 | + |
| 41 | +<!-- |
| 42 | +We are pleased to announce that the [VolumeAttributesClass |
| 43 | +KEP](https://github.com/kubernetes/enhancements/blob/master/keps/sig-storage/3751-volume-attributes-class/README.md), |
| 44 | +alpha since Kubernetes 1.29, will be beta in 1.31. This provides a generic, |
| 45 | +Kubernetes-native API for modifying volume parameters like provisioned IO. |
| 46 | +--> |
| 47 | +我们很高兴地宣布,自 Kubernetes 1.29 起以 Alpha 引入的 |
| 48 | +[VolumeAttributesClass KEP](https://github.com/kubernetes/enhancements/blob/master/keps/sig-storage/3751-volume-attributes-class/README.md) |
| 49 | +将在 1.31 中进入 Beta 阶段。这一机制提供了一个通用的、Kubernetes 原生的 API, |
| 50 | +可用来修改诸如所提供的 IO 能力这类卷参数。 |
| 51 | + |
| 52 | +<!-- |
| 53 | +Like all new volume features in Kubernetes, this API is implemented via the [container |
| 54 | +storage interface (CSI)](https://kubernetes-csi.github.io/docs/). In addition to the |
| 55 | +VolumeAttributesClass feature gate, your provisioner-specific CSI driver must support the |
| 56 | +new ModifyVolume API which is the CSI side of this feature. |
| 57 | +
|
| 58 | +See the [full |
| 59 | +documentation](https://kubernetes.io/docs/concepts/storage/volume-attributes-classes/) |
| 60 | +for all details. Here we show the common workflow. |
| 61 | +--> |
| 62 | +类似于 Kubernetes 中所有新的卷特性,此 API 是通过[容器存储接口(CSI)](https://kubernetes-csi.github.io/docs/)实现的。 |
| 63 | +除了 VolumeAttributesClass 特性门控外,特定于制备器的 CSI 驱动还必须支持此特性在 |
| 64 | +CSI 一侧的全新的 ModifyVolume API。 |
| 65 | + |
| 66 | +有关细节请参阅[完整文档](/zh-cn/docs/concepts/storage/volume-attributes-classes/)。 |
| 67 | +在这里,我们展示了常见的工作流程。 |
| 68 | + |
| 69 | +<!-- |
| 70 | +### Dynamically modifying volume attributes. |
| 71 | +
|
| 72 | +A `VolumeAttributesClass` is a cluster-scoped resource that specifies provisioner-specific |
| 73 | +attributes. These are created by the cluster administrator in the same way as storage |
| 74 | +classes. For example, a series of gold, silver and bronze volume attribute classes can be |
| 75 | +created for volumes with greater or lessor amounts of provisioned IO. |
| 76 | +--> |
| 77 | +### 动态修改卷属性 {#dynamically-modifying-volume-attributes} |
| 78 | + |
| 79 | +`VolumeAttributesClass` 是一个集群范围的资源,用来指定特定于制备器的属性。 |
| 80 | +这些属性由集群管理员创建,方式上与存储类相同。 |
| 81 | +例如,你可以为卷创建一系列金、银和铜级别的卷属性类,以区隔不同级别的 IO 能力。 |
| 82 | + |
| 83 | +```yaml |
| 84 | +apiVersion: storage.k8s.io/v1alpha1 |
| 85 | +kind: VolumeAttributesClass |
| 86 | +metadata: |
| 87 | + name: silver |
| 88 | +driverName: your-csi-driver |
| 89 | +parameters: |
| 90 | + provisioned-iops: "500" |
| 91 | + provisioned-throughput: "50MiB/s" |
| 92 | +--- |
| 93 | +apiVersion: storage.k8s.io/v1alpha1 |
| 94 | +kind: VolumeAttributesClass |
| 95 | +metadata: |
| 96 | + name: gold |
| 97 | +driverName: your-csi-driver |
| 98 | +parameters: |
| 99 | + provisioned-iops: "10000" |
| 100 | + provisioned-throughput: "500MiB/s" |
| 101 | +``` |
| 102 | + |
| 103 | +<!-- |
| 104 | +An attribute class is added to a PVC in much the same way as a storage class. |
| 105 | +--> |
| 106 | +属性类的添加方式与存储类类似。 |
| 107 | +
|
| 108 | +```yaml |
| 109 | +apiVersion: v1 |
| 110 | +kind: PersistentVolumeClaim |
| 111 | +metadata: |
| 112 | + name: test-pv-claim |
| 113 | +spec: |
| 114 | + storageClassName: any-storage-class |
| 115 | + volumeAttributesClassName: silver |
| 116 | + accessModes: |
| 117 | + - ReadWriteOnce |
| 118 | + resources: |
| 119 | + requests: |
| 120 | + storage: 64Gi |
| 121 | +``` |
| 122 | +
|
| 123 | +<!-- |
| 124 | +Unlike a storage class, the volume attributes class can be changed: |
| 125 | +--> |
| 126 | +与存储类不同,卷属性类可以被更改: |
| 127 | +
|
| 128 | +```shell |
| 129 | +kubectl patch pvc test-pv-claim -p '{"spec": "volumeAttributesClassName": "gold"}' |
| 130 | +``` |
| 131 | +
|
| 132 | +<!-- |
| 133 | +Kubernetes will work with the CSI driver to update the attributes of the |
| 134 | +volume. The status of the PVC will track the current and desired attributes |
| 135 | +class. The PV resource will also be updated with the new volume attributes class |
| 136 | +which will be set to the currently active attributes of the PV. |
| 137 | +--> |
| 138 | +Kubernetes 将与 CSI 驱动协作来更新卷的属性。 |
| 139 | +PVC 的状态将跟踪当前和所需的属性类。 |
| 140 | +PV 资源也将依据新的卷属性类完成更新,卷属性类也会被依据 PV 当前活跃的属性完成设置。 |
| 141 | +
|
| 142 | +<!-- |
| 143 | +### Limitations with the beta |
| 144 | +
|
| 145 | +As a beta feature, there are still some features which are planned for GA but not yet |
| 146 | +present. The largest is quota support, see the |
| 147 | +[KEP](https://github.com/kubernetes/enhancements/blob/master/keps/sig-storage/3751-volume-attributes-class/README.md) |
| 148 | +and discussion in |
| 149 | +[sig-storage](https://github.com/kubernetes/community/tree/master/sig-storage) for details. |
| 150 | +
|
| 151 | +See the [Kubernetes CSI driver |
| 152 | +list](https://kubernetes-csi.github.io/docs/drivers.html) for up-to-date |
| 153 | +information of support for this feature in CSI drivers. |
| 154 | +--> |
| 155 | +### Beta 阶段的限制 {#limitations-with-the-beta} |
| 156 | +
|
| 157 | +作为一个 Beta 特性,仍有一些特性计划在 GA 阶段推出,但尚未实现。最大的限制是配额支持,详见 |
| 158 | +[KEP](https://github.com/kubernetes/enhancements/blob/master/keps/sig-storage/3751-volume-attributes-class/README.md) |
| 159 | +和 [sig-storage](https://github.com/kubernetes/community/tree/master/sig-storage) 中的讨论。 |
| 160 | +
|
| 161 | +有关此特性在 CSI 驱动中的最新支持信息,请参阅 [Kubernetes CSI 驱动列表](https://kubernetes-csi.github.io/docs/drivers.html)。 |
0 commit comments