Skip to content

Commit 164774c

Browse files
authored
Merge pull request #23163 from tengqm/zh-fix-change-pv-policy
[zh] Fix change PV reclaim policy task
2 parents 89d6639 + 23ec620 commit 164774c

File tree

1 file changed

+106
-51
lines changed

1 file changed

+106
-51
lines changed

content/zh/docs/tasks/administer-cluster/change-pv-reclaim-policy.md

Lines changed: 106 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -2,86 +2,141 @@
22
title: 更改 PersistentVolume 的回收策略
33
content_type: task
44
---
5-
6-
75
<!-- overview -->
8-
6+
<!--
7+
This page shows how to change the reclaim policy of a Kubernetes
8+
PersistentVolume.
9+
-->
910
本文展示了如何更改 Kubernetes PersistentVolume 的回收策略。
1011

11-
1212
## {{% heading "prerequisites" %}}
1313

14-
1514
{{< include "task-tutorial-prereqs.md" >}} {{< version-check >}}
1615

17-
18-
1916
<!-- steps -->
2017

21-
18+
<!--
19+
## Why change reclaim policy of a PersistentVolume
20+
21+
PersistentVolumes can have various reclaim policies, including "Retain",
22+
"Recycle", and "Delete". For dynamically provisioned PersistentVolumes,
23+
the default reclaim policy is "Delete". This means that a dynamically provisioned
24+
volume is automatically deleted when a user deletes the corresponding
25+
PersistentVolumeClaim. This automatic behavior might be inappropriate if the volume
26+
contains precious data. In that case, it is more appropriate to use the "Retain"
27+
policy. With the "Retain" policy, if a user deletes a PersistentVolumeClaim,
28+
the corresponding PersistentVolume is not be deleted. Instead, it is moved to the
29+
Released phase, where all of its data can be manually recovered.
30+
-->
2231
## 为什么要更改 PersistentVolume 的回收策略
2332

24-
25-
PersistentVolumes 可以有多种回收策略,包括 "Retain"、"Recycle" 和 "Delete"。对于动态配置的 PersistentVolumes 来说,默认回收策略为 "Delete"。这表示当用户删除对应的 PersistentVolumeClaim 时,动态配置的 volume 将被自动删除。如果 volume 包含重要数据时,这种自动行为可能是不合适的。那种情况下,更适合使用 "Retain" 策略。使用 "Retain" 时,如果用户删除 PersistentVolumeClaim,对应的 PersistentVolume 不会被删除。相反,它将变为 Released 状态,表示所有的数据可以被手动恢复。
26-
27-
33+
PersistentVolumes 可以有多种回收策略,包括 "Retain"、"Recycle" 和 "Delete"。
34+
对于动态配置的 PersistentVolumes 来说,默认回收策略为 "Delete"。
35+
这表示当用户删除对应的 PersistentVolumeClaim 时,动态配置的 volume 将被自动删除。
36+
如果 volume 包含重要数据时,这种自动行为可能是不合适的。
37+
那种情况下,更适合使用 "Retain" 策略。
38+
使用 "Retain" 时,如果用户删除 PersistentVolumeClaim,对应的 PersistentVolume 不会被删除。
39+
相反,它将变为 Released 状态,表示所有的数据可以被手动恢复。
40+
41+
<!--
42+
## Changing the reclaim policy of a PersistentVolume
43+
-->
2844
## 更改 PersistentVolume 的回收策略
2945

30-
46+
<!--
47+
1. List the PersistentVolumes in your cluster:
48+
-->
3149
1. 列出你集群中的 PersistentVolumes
3250

33-
kubectl get pv
34-
35-
输出类似于这样:
36-
37-
NAME CAPACITY ACCESSMODES RECLAIMPOLICY STATUS CLAIM REASON AGE
38-
pvc-b6efd8da-b7b5-11e6-9d58-0ed433a7dd94 4Gi RWO Delete Bound default/claim1 10s
39-
pvc-b95650f8-b7b5-11e6-9d58-0ed433a7dd94 4Gi RWO Delete Bound default/claim2 6s
40-
pvc-bb3ca71d-b7b5-11e6-9d58-0ed433a7dd94 4Gi RWO Delete Bound default/claim3 3s
51+
```shell
52+
kubectl get pv
53+
```
4154

55+
输出类似于这样:
4256

43-
这个列表同样包含了绑定到每个 volume 的 claims 名称,以便更容易的识别动态配置的 volumes。
57+
```
58+
NAME CAPACITY ACCESSMODES RECLAIMPOLICY STATUS CLAIM REASON AGE
59+
pvc-b6efd8da-b7b5-11e6-9d58-0ed433a7dd94 4Gi RWO Delete Bound default/claim1 10s
60+
pvc-b95650f8-b7b5-11e6-9d58-0ed433a7dd94 4Gi RWO Delete Bound default/claim2 6s
61+
pvc-bb3ca71d-b7b5-11e6-9d58-0ed433a7dd94 4Gi RWO Delete Bound default/claim3 3s
62+
```
4463

64+
<!--
65+
This list also includes the name of the claims that are bound to each volume
66+
for easier identification of dynamically provisioned volumes.
67+
-->
68+
这个列表同样包含了绑定到每个卷的 claims 名称,以便更容易的识别动态配置的卷。
4569

70+
<!--
71+
1. Choose one of your PersistentVolumes and change its reclaim policy:
72+
-->
4673
2. 选择你的 PersistentVolumes 中的一个并更改它的回收策略:
4774

48-
```shell
49-
kubectl patch pv <your-pv-name> -p '{"spec":{"persistentVolumeReclaimPolicy":"Retain"}}'
50-
```
51-
52-
这里的 `<your-pv-name>` 是你选择的 PersistentVolume 的名字。
53-
75+
```shell
76+
kubectl patch pv <your-pv-name> -p '{"spec":{"persistentVolumeReclaimPolicy":"Retain"}}'
77+
```
78+
79+
<!--
80+
where `<your-pv-name>` is the name of your chosen PersistentVolume.
81+
-->
82+
这里的 `<your-pv-name>` 是你选择的 PersistentVolume 的名字。
83+
84+
<!--
85+
On Windows, you must _double_ quote any JSONPath template that contains spaces
86+
(not single quote as shown above for bash). This in turn means that you must
87+
use a single quote or escaped double quote around any literals in the template. For example:
88+
-->
89+
{{< note >}}
90+
在 Windows 系统上,你必须对包含空格的 JSONPath 模板加双引号(而不是像上面
91+
一样为 Bash 环境使用的单引号)。这也意味着你必须使用单引号或者转义的双引号
92+
来处理模板中的字面值。例如:
93+
94+
```cmd
95+
kubectl patch pv <your-pv-name> -p "{\"spec\":{\"persistentVolumeReclaimPolicy\":\"Retain\"}}"
96+
```
97+
{{< /note >}}
98+
99+
<!--
100+
1. Verify that your chosen PersistentVolume has the right policy:
101+
-->
54102
3. 验证你选择的 PersistentVolume 拥有正确的策略:
55103

56-
```shell
57-
kubectl get pv
58-
```
59-
60-
输出类似于这样:
61-
62-
NAME CAPACITY ACCESSMODES RECLAIMPOLICY STATUS CLAIM REASON AGE
63-
pvc-b6efd8da-b7b5-11e6-9d58-0ed433a7dd94 4Gi RWO Delete Bound default/claim1 40s
64-
pvc-b95650f8-b7b5-11e6-9d58-0ed433a7dd94 4Gi RWO Delete Bound default/claim2 36s
65-
pvc-bb3ca71d-b7b5-11e6-9d58-0ed433a7dd94 4Gi RWO Retain Bound default/claim3 33s
66-
67-
68-
在前面的输出中,你可以看到绑定到 claim `default/claim3` 的 volume 拥有的回收策略为 `Retain`。当用户删除 claim `default/claim3` 时,它不会被自动删除。
69-
70-
104+
```shell
105+
kubectl get pv
106+
```
107+
108+
<!--
109+
The output is similar to this:
110+
-->
111+
输出类似于这样:
112+
113+
```
114+
NAME CAPACITY ACCESSMODES RECLAIMPOLICY STATUS CLAIM REASON AGE
115+
pvc-b6efd8da-b7b5-11e6-9d58-0ed433a7dd94 4Gi RWO Delete Bound default/claim1 40s
116+
pvc-b95650f8-b7b5-11e6-9d58-0ed433a7dd94 4Gi RWO Delete Bound default/claim2 36s
117+
pvc-bb3ca71d-b7b5-11e6-9d58-0ed433a7dd94 4Gi RWO Retain Bound default/claim3 33s
118+
```
119+
120+
<!--
121+
In the preceding output, you can see that the volume bound to claim
122+
`default/claim3` has reclaim policy `Retain`. It will not be automatically
123+
deleted when a user deletes claim `default/claim3`.
124+
-->
125+
在前面的输出中,你可以看到绑定到申领 `default/claim3` 的卷的回收策略为 `Retain`
126+
当用户删除申领 `default/claim3` 时,它不会被自动删除。
71127

72128
## {{% heading "whatsnext" %}}
73129

74-
75-
* 了解更多关于 [PersistentVolumes](/docs/concepts/storage/persistent-volumes/)的信息。
76-
* 了解更多关于 [PersistentVolumeClaims](/docs/user-guide/persistent-volumes/#persistentvolumeclaims) 的信息。
77-
130+
<!--
131+
* Learn more about [PersistentVolumes](/docs/concepts/storage/persistent-volumes/).
132+
* Learn more about [PersistentVolumeClaims](/docs/concepts/storage/persistent-volumes/#persistentvolumeclaims).
133+
-->
134+
* 进一步了解 [PersistentVolumes](/docs/concepts/storage/persistent-volumes/)
135+
* 进一步了解 [PersistentVolumeClaims](/docs/concepts/storage/persistent-volumes/#persistentvolumeclaims)
78136

79137
### 参考
80138

81139
* [PersistentVolume](/docs/api-reference/{{< param "version" >}}/#persistentvolume-v1-core)
82140
* [PersistentVolumeClaim](/docs/api-reference/{{< param "version" >}}/#persistentvolumeclaim-v1-core)
83-
84-
* 查阅 [PersistentVolumeSpec](/docs/api-reference/{{< param "version" >}}/#persistentvolumeclaim-v1-core) 的 `persistentVolumeReclaimPolicy` 字段。
85-
86-
141+
* 参阅 [PersistentVolumeSpec](/docs/api-reference/{{< param "version" >}}/#persistentvolumeclaim-v1-core) 的 `persistentVolumeReclaimPolicy` 字段
87142

0 commit comments

Comments
 (0)