|
| 1 | +--- |
| 2 | +layout: blog |
| 3 | +title: 'Kubernetes v1.33:防止无序删除时 PersistentVolume 泄漏特性进阶到 GA' |
| 4 | +date: 2025-05-05T10:30:00-08:00 |
| 5 | +slug: kubernetes-v1-33-prevent-persistentvolume-leaks-when-deleting-out-of-order-graduate-to-ga |
| 6 | +author: > |
| 7 | + Deepak Kinni (Broadcom) |
| 8 | +--- |
| 9 | +<!-- |
| 10 | +layout: blog |
| 11 | +title: 'Kubernetes v1.33: Prevent PersistentVolume Leaks When Deleting out of Order graduates to GA' |
| 12 | +date: 2025-05-05T10:30:00-08:00 |
| 13 | +slug: kubernetes-v1-33-prevent-persistentvolume-leaks-when-deleting-out-of-order-graduate-to-ga |
| 14 | +author: > |
| 15 | + Deepak Kinni (Broadcom) |
| 16 | +--> |
| 17 | + |
| 18 | +<!-- |
| 19 | +I am thrilled to announce that the feature to prevent |
| 20 | +[PersistentVolume](/docs/concepts/storage/persistent-volumes/) (or PVs for short) |
| 21 | +leaks when deleting out of order has graduated to General Availability (GA) in |
| 22 | +Kubernetes v1.33! This improvement, initially introduced as a beta |
| 23 | +feature in Kubernetes v1.31, ensures that your storage resources are properly |
| 24 | +reclaimed, preventing unwanted leaks. |
| 25 | +--> |
| 26 | +我很高兴地宣布,当无序删除时防止 |
| 27 | +[PersistentVolume](/zh-cn/docs/concepts/storage/persistent-volumes/)(简称 PV) |
| 28 | +泄漏的特性已经在 Kubernetes v1.33 中进阶为正式版(GA)!这项改进最初在 |
| 29 | +Kubernetes v1.31 中作为 Beta 特性引入, |
| 30 | +确保你的存储资源能够被正确回收,防止不必要的泄漏。 |
| 31 | + |
| 32 | +<!-- |
| 33 | +## How did reclaim work in previous Kubernetes releases? |
| 34 | +
|
| 35 | +[PersistentVolumeClaim](/docs/concepts/storage/persistent-volumes/#Introduction) (or PVC for short) is |
| 36 | +a user's request for storage. A PV and PVC are considered [Bound](/docs/concepts/storage/persistent-volumes/#Binding) |
| 37 | +if a newly created PV or a matching PV is found. The PVs themselves are |
| 38 | +backed by volumes allocated by the storage backend. |
| 39 | +--> |
| 40 | +## 以前的 Kubernetes 版本中 reclaim 是如何工作的? |
| 41 | + |
| 42 | +[PersistentVolumeClaim](/zh-cn/docs/concepts/storage/persistent-volumes/#Introduction) (简称 PVC) |
| 43 | +是用户对存储的请求。如果创建了新的 PV 或找到了匹配的 PV,则认为 PV 和 PVC |
| 44 | +是[绑定](/zh-cn/docs/concepts/storage/persistent-volumes/#Binding)的。 |
| 45 | +PV 本身由存储后端分配的卷支持。 |
| 46 | + |
| 47 | +<!-- |
| 48 | +Normally, if the volume is to be deleted, then the expectation is to delete the |
| 49 | +PVC for a bound PV-PVC pair. However, there are no restrictions on deleting a PV |
| 50 | +before deleting a PVC. |
| 51 | +--> |
| 52 | +通常,如果卷需要被删除,则预期是删除绑定的 PV-PVC 对的 PVC。但是, |
| 53 | +删除 PVC 之前并没有限制不能删除 PV。 |
| 54 | + |
| 55 | +<!-- |
| 56 | +For a `Bound` PV-PVC pair, the ordering of PV-PVC deletion determines whether |
| 57 | +the PV reclaim policy is honored. The reclaim policy is honored if the PVC is |
| 58 | +deleted first; however, if the PV is deleted prior to deleting the PVC, then the |
| 59 | +reclaim policy is not exercised. As a result of this behavior, the associated |
| 60 | +storage asset in the external infrastructure is not removed. |
| 61 | +--> |
| 62 | +对于一个“已绑定”的 PV-PVC 对,PV 和 PVC 的删除顺序决定了是否遵守 PV 回收策略。 |
| 63 | +如果先删除 PVC,则会遵守回收策略;然而,如果在删除 PVC 之前删除了 PV, |
| 64 | +则不会执行回收策略。因此,外部基础设施中相关的存储资源不会被移除。 |
| 65 | + |
| 66 | +<!-- |
| 67 | +## PV reclaim policy with Kubernetes v1.33 |
| 68 | +
|
| 69 | +With the graduation to GA in Kubernetes v1.33, this issue is now resolved. Kubernetes |
| 70 | +now reliably honors the configured `Delete` reclaim policy, even when PVs are deleted |
| 71 | +before their bound PVCs. This is achieved through the use of finalizers, |
| 72 | +ensuring that the storage backend releases the allocated storage resource as intended. |
| 73 | +--> |
| 74 | +## 在 Kubernetes v1.33 中的 PV 回收策略 |
| 75 | + |
| 76 | +随着在 Kubernetes v1.33 中升级为 GA,这个问题现在得到了解决。 |
| 77 | +Kubernetes 现在可靠地遵守配置的“删除”回收策略,即使在删除 PV |
| 78 | +时其绑定的 PVC 尚未删除。这是通过使用终结器实现的, |
| 79 | +确保存储后端如预期释放分配的存储资源。 |
| 80 | + |
| 81 | +<!-- |
| 82 | +### How does it work? |
| 83 | +
|
| 84 | +For CSI volumes, the new behavior is achieved by adding a [finalizer](/docs/concepts/overview/working-with-objects/finalizers/) `external-provisioner.volume.kubernetes.io/finalizer` |
| 85 | +on new and existing PVs. The finalizer is only removed after the storage from the backend is deleted. Addition or removal of finalizer is handled by `external-provisioner` |
| 86 | +
|
| 87 | +An example of a PV with the finalizer, notice the new finalizer in the finalizers list |
| 88 | +--> |
| 89 | +### 它是如何工作的? |
| 90 | + |
| 91 | +对于 CSI 卷,新行为通过在新的和现有的 PV |
| 92 | +上添加一个[终结器](/zh-cn/docs/concepts/overview/working-with-objects/finalizers/) |
| 93 | +`external-provisioner.volume.kubernetes.io/finalizer` 来实现。 |
| 94 | +只有当后端存储被删除后,终结器才会被移除。终结器的添加或移除由 |
| 95 | +`external-provisioner` 处理。 |
| 96 | + |
| 97 | +以下是带有终结器的 PV 示例,注意 finalizers 列表中的新终结器: |
| 98 | + |
| 99 | +``` |
| 100 | +kubectl get pv pvc-a7b7e3ba-f837-45ba-b243-dec7d8aaed53 -o yaml |
| 101 | +``` |
| 102 | + |
| 103 | +```yaml |
| 104 | +apiVersion: v1 |
| 105 | +kind: PersistentVolume |
| 106 | +metadata: |
| 107 | + annotations: |
| 108 | + pv.kubernetes.io/provisioned-by: csi.example.driver.com |
| 109 | + creationTimestamp: "2021-11-17T19:28:56Z" |
| 110 | + finalizers: |
| 111 | + - kubernetes.io/pv-protection |
| 112 | + - external-provisioner.volume.kubernetes.io/finalizer |
| 113 | + name: pvc-a7b7e3ba-f837-45ba-b243-dec7d8aaed53 |
| 114 | + resourceVersion: "194711" |
| 115 | + uid: 087f14f2-4157-4e95-8a70-8294b039d30e |
| 116 | +spec: |
| 117 | + accessModes: |
| 118 | + - ReadWriteOnce |
| 119 | + capacity: |
| 120 | + storage: 1Gi |
| 121 | + claimRef: |
| 122 | + apiVersion: v1 |
| 123 | + kind: PersistentVolumeClaim |
| 124 | + name: example-vanilla-block-pvc |
| 125 | + namespace: default |
| 126 | + resourceVersion: "194677" |
| 127 | + uid: a7b7e3ba-f837-45ba-b243-dec7d8aaed53 |
| 128 | + csi: |
| 129 | + driver: csi.example.driver.com |
| 130 | + fsType: ext4 |
| 131 | + volumeAttributes: |
| 132 | + storage.kubernetes.io/csiProvisionerIdentity: 1637110610497-8081-csi.example.driver.com |
| 133 | + type: CNS Block Volume |
| 134 | + volumeHandle: 2dacf297-803f-4ccc-afc7-3d3c3f02051e |
| 135 | + persistentVolumeReclaimPolicy: Delete |
| 136 | + storageClassName: example-vanilla-block-sc |
| 137 | + volumeMode: Filesystem |
| 138 | +status: |
| 139 | + phase: Bound |
| 140 | +``` |
| 141 | +
|
| 142 | +<!-- |
| 143 | +The [finalizer](/docs/concepts/overview/working-with-objects/finalizers/) prevents this |
| 144 | +PersistentVolume from being removed from the |
| 145 | +cluster. As stated previously, the finalizer is only removed from the PV object |
| 146 | +after it is successfully deleted from the storage backend. To learn more about |
| 147 | +finalizers, please refer to [Using Finalizers to Control Deletion](/blog/2021/05/14/using-finalizers-to-control-deletion/). |
| 148 | +
|
| 149 | +Similarly, the finalizer `kubernetes.io/pv-controller` is added to dynamically provisioned in-tree plugin volumes. |
| 150 | +--> |
| 151 | +[终结器](/zh-cn/docs/concepts/overview/working-with-objects/finalizers/)防止此 |
| 152 | +PersistentVolume 从集群中被移除。如前所述,在从存储后端成功删除之后, |
| 153 | +才会从 PV 对象中移除终结器。要了解更多关于终结器的信息, |
| 154 | +请参阅[使用终结器控制删除](/zh-cn/blog/2021/05/14/using-finalizers-to-control-deletion/)。 |
| 155 | + |
| 156 | +类似地,终结器 `kubernetes.io/pv-controller` 被添加到动态供应的内置插件卷中。 |
| 157 | + |
| 158 | +<!-- |
| 159 | +### Important note |
| 160 | + |
| 161 | +The fix does not apply to statically provisioned in-tree plugin volumes. |
| 162 | +--> |
| 163 | +### 重要提示 |
| 164 | + |
| 165 | +此修复不适用于静态供应的内置插件卷。 |
| 166 | + |
| 167 | +<!-- |
| 168 | +## How to enable new behavior? |
| 169 | + |
| 170 | +To take advantage of the new behavior, you must have upgraded your cluster to the v1.33 release of Kubernetes |
| 171 | +and run the CSI [`external-provisioner`](https://github.com/kubernetes-csi/external-provisioner) version `5.0.1` or later. |
| 172 | +The feature was released as beta in v1.31 release of Kubernetes, where it was enabled by default. |
| 173 | +--> |
| 174 | +## 如何启用新行为? |
| 175 | + |
| 176 | +要利用新行为,你必须将集群升级到 Kubernetes 的 v1.33 版本, |
| 177 | +并运行 CSI [`external-provisioner`](https://github.com/kubernetes-csi/external-provisioner) |
| 178 | +5.0.1 或更新版本。 |
| 179 | +此特性在 Kubernetes 的 v1.31 版本中作为测试版发布,并且默认启用。 |
| 180 | + |
| 181 | +<!-- |
| 182 | +## References |
| 183 | + |
| 184 | +* [KEP-2644](https://github.com/kubernetes/enhancements/tree/master/keps/sig-storage/2644-honor-pv-reclaim-policy) |
| 185 | +* [Volume leak issue](https://github.com/kubernetes-csi/external-provisioner/issues/546) |
| 186 | +* [Beta Release Blog](/blog/2024/08/16/kubernetes-1-31-prevent-persistentvolume-leaks-when-deleting-out-of-order/) |
| 187 | +--> |
| 188 | +## 参考 |
| 189 | + |
| 190 | +* [KEP-2644](https://github.com/kubernetes/enhancements/tree/master/keps/sig-storage/2644-honor-pv-reclaim-policy) |
| 191 | +* [卷泄漏问题](https://github.com/kubernetes-csi/external-provisioner/issues/546) |
| 192 | +* [测试版发布博客](/zh-cn/blog/2024/08/16/kubernetes-1-31-prevent-persistentvolume-leaks-when-deleting-out-of-order/) |
| 193 | + |
| 194 | +<!-- |
| 195 | +## How do I get involved? |
| 196 | + |
| 197 | +The Kubernetes Slack channel [SIG Storage communication channels](https://github.com/kubernetes/community/blob/master/sig-storage/README.md#contact) are great mediums to reach out to the SIG Storage and migration working group teams. |
| 198 | + |
| 199 | +Special thanks to the following people for the insightful reviews, thorough consideration and valuable contribution: |
| 200 | +--> |
| 201 | +## 如何参与? |
| 202 | + |
| 203 | +Kubernetes Slack 频道 |
| 204 | +[SIG Storage 交流渠道](https://github.com/kubernetes/community/blob/master/sig-storage/README.md#contact)是接触 |
| 205 | +SIG Storage 和迁移工作组团队的绝佳方式。 |
| 206 | + |
| 207 | +特别感谢以下人员的深入审查、细致考虑和宝贵贡献: |
| 208 | + |
| 209 | +* Fan Baofa (carlory) |
| 210 | +* Jan Šafránek (jsafrane) |
| 211 | +* Xing Yang (xing-yang) |
| 212 | +* Matthew Wong (wongma7) |
| 213 | + |
| 214 | +<!-- |
| 215 | +Join the [Kubernetes Storage Special Interest Group (SIG)](https://github.com/kubernetes/community/tree/master/sig-storage) if you're interested in getting involved with the design and development of CSI or any part of the Kubernetes Storage system. We’re rapidly growing and always welcome new contributors. |
| 216 | +--> |
| 217 | +如果你对 CSI 或 Kubernetes 存储系统的任何部分的设计和开发感兴趣, |
| 218 | +可以加入 [Kubernetes 存储特别兴趣小组 (SIG)](https://github.com/kubernetes/community/tree/master/sig-storage)。 |
| 219 | +我们正在迅速成长,并且总是欢迎新的贡献者。 |
0 commit comments