|
| 1 | +--- |
| 2 | +layout: blog |
| 3 | +title: "Kubernetes 1.24:卷扩充现在成为稳定功能" |
| 4 | +date: 2022-05-05 |
| 5 | +slug: volume-expansion-ga |
| 6 | +--- |
| 7 | + |
| 8 | +<!-- |
| 9 | +--- |
| 10 | +layout: blog |
| 11 | +title: "Kubernetes 1.24: Volume Expansion Now A Stable Feature" |
| 12 | +date: 2022-05-05 |
| 13 | +slug: volume-expansion-ga |
| 14 | +--- |
| 15 | +--> |
| 16 | + |
| 17 | +<!-- |
| 18 | +**Author:** Hemant Kumar (Red Hat) |
| 19 | +
|
| 20 | +Volume expansion was introduced as a alpha feature in Kubernetes 1.8 and it went beta in 1.11 and with Kubernetes 1.24 we are excited to announce general availability(GA) |
| 21 | +of volume expansion. |
| 22 | +
|
| 23 | +This feature allows Kubernetes users to simply edit their `PersistentVolumeClaim` objects and specify new size in PVC Spec and Kubernetes will automatically expand the volume |
| 24 | +using storage backend and also expand the underlying file system in-use by the Pod without requiring any downtime at all if possible. |
| 25 | +--> |
| 26 | +**作者:** Hemant Kumar (Red Hat) |
| 27 | + |
| 28 | +卷扩充在 Kubernetes 1.8 作为 Alpha 功能引入, |
| 29 | +在 Kubernetes 1.11 进入了 Beta 阶段。 |
| 30 | +在 Kubernetes 1.24 中,我们很高兴地宣布卷扩充正式发布(GA)。 |
| 31 | + |
| 32 | +此功能允许 Kubernetes 用户简单地编辑其 `PersistentVolumeClaim` 对象, |
| 33 | +并在 PVC Spec 中指定新的大小,Kubernetes 将使用存储后端自动扩充卷, |
| 34 | +同时也会扩充 Pod 使用的底层文件系统,使得无需任何停机时间成为可能。 |
| 35 | +<!-- |
| 36 | +### How to use volume expansion |
| 37 | +
|
| 38 | +You can trigger expansion for a PersistentVolume by editing the `spec` field of a PVC, specifying a different |
| 39 | +(and larger) storage request. For example, given following PVC: |
| 40 | +
|
| 41 | +```yaml |
| 42 | +kind: PersistentVolumeClaim |
| 43 | +apiVersion: v1 |
| 44 | +metadata: |
| 45 | + name: myclaim |
| 46 | +spec: |
| 47 | + accessModes: |
| 48 | + - ReadWriteOnce |
| 49 | + resources: |
| 50 | + requests: |
| 51 | + storage: 1Gi # specify new size here |
| 52 | +``` |
| 53 | +--> |
| 54 | +### 如何使用卷扩充 |
| 55 | + |
| 56 | +通过编辑 PVC 的 `spec` 字段,指定不同的(和更大的)存储请求, |
| 57 | +可以触发 PersistentVolume 的扩充。 |
| 58 | +例如,给定以下 PVC: |
| 59 | + |
| 60 | +```yaml |
| 61 | +kind: PersistentVolumeClaim |
| 62 | +apiVersion: v1 |
| 63 | +metadata: |
| 64 | + name: myclaim |
| 65 | +spec: |
| 66 | + accessModes: |
| 67 | + - ReadWriteOnce |
| 68 | + resources: |
| 69 | + requests: |
| 70 | + storage: 1Gi # 在此处指定新的大小 |
| 71 | +``` |
| 72 | +<!-- |
| 73 | +You can request expansion of the underlying PersistentVolume by specifying a new value instead of old `1Gi` size. |
| 74 | +Once you've changed the requested size, watch the `status.conditions` field of the PVC to see if the |
| 75 | +resize has completed. |
| 76 | + |
| 77 | +When Kubernetes starts expanding the volume - it will add `Resizing` condition to the PVC, which will be removed once expansion completes. More information about progress of |
| 78 | +expansion operation can also be obtained by monitoring events associated with the PVC: |
| 79 | + |
| 80 | +```bash |
| 81 | +kubectl describe pvc <pvc> |
| 82 | +``` |
| 83 | +--> |
| 84 | +你可以指定新的值来替代旧的 `1Gi` 大小来请求扩充下层 PersistentVolume。 |
| 85 | +一旦你更改了请求的大小,可以查看 PVC 的 `status.conditions` 字段, |
| 86 | +确认卷大小的调整是否已完成。 |
| 87 | + |
| 88 | +当 Kubernetes 开始扩充卷时,它会给 PVC 添加 `Resizing` 状况。 |
| 89 | +一旦扩充结束,这个状况会被移除。通过监控与 PVC 关联的事件, |
| 90 | +还可以获得更多关于扩充操作进度的信息: |
| 91 | + |
| 92 | +```bash |
| 93 | +kubectl describe pvc <pvc> |
| 94 | +``` |
| 95 | +<!-- |
| 96 | +### Storage driver support |
| 97 | + |
| 98 | +Not every volume type however is expandable by default. Some volume types such as - intree hostpath volumes are not expandable at all. For CSI volumes - the CSI driver |
| 99 | +must have capability `EXPAND_VOLUME` in controller or node service (or both if appropriate). Please refer to documentation of your CSI driver, to find out |
| 100 | +if it supports volume expansion. |
| 101 | + |
| 102 | +Please refer to volume expansion documentation for intree volume types which support volume expansion - [Expanding Persistent Volumes](/docs/concepts/storage/persistent-volumes/#expanding-persistent-volumes-claims). |
| 103 | +--> |
| 104 | +### 存储驱动支持 |
| 105 | + |
| 106 | +然而,并不是每种卷类型都默认支持扩充。 |
| 107 | +某些卷类型(如树内 hostpath 卷)不支持扩充。 |
| 108 | +对于 CSI 卷, |
| 109 | +CSI 驱动必须在控制器或节点服务(如果合适,二者兼备) |
| 110 | +中具有 `EXPAND_VOLUME` 能力。 |
| 111 | +请参阅 CSI 驱动的文档,了解其是否支持卷扩充。 |
| 112 | + |
| 113 | +有关支持卷扩充的树内(intree)卷类型, |
| 114 | +请参阅卷扩充文档:[扩充 PVC 申领](/zh/docs/concepts/storage/persistent-volumes/#expanding-persistent-volumes-claims)。 |
| 115 | + |
| 116 | +<!-- |
| 117 | +In general to provide some degree of control over volumes that can be expanded, only dynamically provisioned PVCs whose storage class has `allowVolumeExpansion` parameter set to `true` are expandable. |
| 118 | + |
| 119 | +A Kubernetes cluster administrator must edit the appropriate StorageClass object and set |
| 120 | +the `allowVolumeExpansion` field to `true`. For example: |
| 121 | +--> |
| 122 | +通常,为了对可扩充的卷提供某种程度的控制, |
| 123 | +只有在存储类将 `allowVolumeExpansion` 参数设置为 `true` 时, |
| 124 | +动态供应的 PVC 才是可扩充的。 |
| 125 | + |
| 126 | +Kubernetes 集群管理员必须编辑相应的 StorageClass 对象, |
| 127 | +并将 `allowVolumeExpansion` 字段设置为 `true`。例如: |
| 128 | + |
| 129 | +```yaml |
| 130 | +apiVersion: storage.k8s.io/v1 |
| 131 | +kind: StorageClass |
| 132 | +metadata: |
| 133 | + name: gp2-default |
| 134 | +provisioner: kubernetes.io/aws-ebs |
| 135 | +parameters: |
| 136 | + secretNamespace: "" |
| 137 | + secretName: "" |
| 138 | +allowVolumeExpansion: true |
| 139 | +``` |
| 140 | +<!-- |
| 141 | +### Online expansion compared to offline expansion |
| 142 | + |
| 143 | +By default, Kubernetes attempts to expand volumes immediately after user requests a resize. |
| 144 | +If one or more Pods are using the volume, Kubernetes tries to expands the volume using an online resize; |
| 145 | +as a result volume expansion usually requires no application downtime. |
| 146 | +Filesystem expansion on the node is also performed online and hence does not require shutting |
| 147 | +down any Pod that was using the PVC. |
| 148 | + |
| 149 | +If you expand a PersistentVolume that is not in use, Kubernetes does an offline resize (and, |
| 150 | +because the volume isn't in use, there is again no workload disruption). |
| 151 | +--> |
| 152 | +### 在线扩充与离线扩充比较 |
| 153 | + |
| 154 | +默认情况下,Kubernetes 会在用户请求调整大小后立即尝试扩充卷。 |
| 155 | +如果一个或多个 Pod 正在使用该卷, |
| 156 | +Kubernetes 会尝试通过在线调整大小来扩充该卷; |
| 157 | +因此,卷扩充通常不需要应用停机。 |
| 158 | +节点上的文件系统也可以在线扩充,因此不需要关闭任何正在使用 PVC 的 Pod。 |
| 159 | + |
| 160 | +如果要扩充的 PersistentVolume 未被使用,Kubernetes 会用离线方式调整卷大小 |
| 161 | +(而且,由于该卷未使用,所以也不会造成工作负载中断)。 |
| 162 | +<!-- |
| 163 | +In some cases though - if underlying Storage Driver can only support offline expansion, users of the PVC must take down their Pod before expansion can succeed. Please refer to documentation of your storage |
| 164 | +provider to find out - what mode of volume expansion it supports. |
| 165 | + |
| 166 | +When volume expansion was introduced as an alpha feature, Kubernetes only supported offline filesystem |
| 167 | +expansion on the node and hence required users to restart their pods for file system resizing to finish. |
| 168 | +His behaviour has been changed and Kubernetes tries its best to fulfil any resize request regardless |
| 169 | +of whether the underlying PersistentVolume volume is online or offline. If your storage provider supports |
| 170 | +online expansion then no Pod restart should be necessary for volume expansion to finish. |
| 171 | +--> |
| 172 | +但在某些情况下,如果底层存储驱动只能支持离线扩充, |
| 173 | +则 PVC 用户必须先停止 Pod,才能让扩充成功。 |
| 174 | +请参阅存储提供商的文档,了解其支持哪种模式的卷扩充。 |
| 175 | + |
| 176 | +当卷扩充作为 Alpha 功能引入时, |
| 177 | +Kubernetes 仅支持在节点上进行离线的文件系统扩充, |
| 178 | +因此需要用户重新启动 Pod,才能完成文件系统的大小调整。 |
| 179 | +今天,用户的行为已经被改变,无论底层 PersistentVolume 是在线还是离线, |
| 180 | +Kubernetes 都会尽最大努力满足任何调整大小的请求。 |
| 181 | +如果你的存储提供商支持在线扩充,则无需重启 Pod 即可完成卷扩充。 |
| 182 | +<!-- |
| 183 | +## Next steps |
| 184 | + |
| 185 | +Although volume expansion is now stable as part of the recent v1.24 release, |
| 186 | +SIG Storage are working to make it even simpler for users of Kubernetes to expand their persistent storage. |
| 187 | +Kubernetes 1.23 introduced features for triggering recovery from failed volume expansion, allowing users |
| 188 | +to attempt self-service healing after a failed resize. |
| 189 | +See [Recovering from volume expansion failure](/docs/concepts/storage/persistent-volumes/#recovering-from-failure-when-expanding-volumes) for more details. |
| 190 | +--> |
| 191 | +## 下一步 |
| 192 | + |
| 193 | +尽管卷扩充在最近的 v1.24 发行版中成为了稳定版本, |
| 194 | +但 SIG Storage 团队仍然在努力让 Kubernetes 用户扩充其持久性存储变得更简单。 |
| 195 | +Kubernetes 1.23 引入了卷扩充失败后触发恢复机制的功能特性, |
| 196 | +允许用户在大小调整失败后尝试自助修复。 |
| 197 | +更多详细信息,请参阅[处理扩充卷过程中的失败](/zh/docs/concepts/storage/persistent-volumes/#recovering-from-failure-when-expanding-volumes)。 |
| 198 | +<!-- |
| 199 | +The Kubernetes contributor community is also discussing the potential for StatefulSet-driven storage expansion. This proposed |
| 200 | +feature would let you trigger expansion for all underlying PVs that are providing storage to a StatefulSet, |
| 201 | +by directly editing the StatefulSet object. |
| 202 | +See the [Support Volume Expansion Through StatefulSets](https://github.com/kubernetes/enhancements/issues/661) enhancement proposal for more details. |
| 203 | +--> |
| 204 | +Kubernetes 贡献者社区也在讨论有状态(StatefulSet)驱动的存储扩充的潜力。 |
| 205 | +这个提议的功能特性将允许用户通过直接编辑 StatefulSet 对象, |
| 206 | +触发为 StatefulSet 提供存储的所有底层 PV 的扩充。 |
| 207 | +更多详细信息,请参阅[通过 StatefulSet 支持卷扩充](https://github.com/kubernetes/enhancements/issues/661)的改善提议。 |
0 commit comments