|
2 | 2 | title: 更改 PersistentVolume 的回收策略
|
3 | 3 | content_type: task
|
4 | 4 | ---
|
5 |
| - |
6 |
| - |
7 | 5 | <!-- overview -->
|
8 |
| - |
| 6 | +<!-- |
| 7 | +This page shows how to change the reclaim policy of a Kubernetes |
| 8 | +PersistentVolume. |
| 9 | +--> |
9 | 10 | 本文展示了如何更改 Kubernetes PersistentVolume 的回收策略。
|
10 | 11 |
|
11 |
| - |
12 | 12 | ## {{% heading "prerequisites" %}}
|
13 | 13 |
|
14 |
| - |
15 | 14 | {{< include "task-tutorial-prereqs.md" >}} {{< version-check >}}
|
16 | 15 |
|
17 |
| - |
18 |
| - |
19 | 16 | <!-- steps -->
|
20 | 17 |
|
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 | +--> |
22 | 31 | ## 为什么要更改 PersistentVolume 的回收策略
|
23 | 32 |
|
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 | +--> |
28 | 44 | ## 更改 PersistentVolume 的回收策略
|
29 | 45 |
|
30 |
| - |
| 46 | +<!-- |
| 47 | +1. List the PersistentVolumes in your cluster: |
| 48 | +--> |
31 | 49 | 1. 列出你集群中的 PersistentVolumes
|
32 | 50 |
|
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 | + ``` |
41 | 54 |
|
| 55 | + 输出类似于这样: |
42 | 56 |
|
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 | + ``` |
44 | 63 |
|
| 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 名称,以便更容易的识别动态配置的卷。 |
45 | 69 |
|
| 70 | +<!-- |
| 71 | +1. Choose one of your PersistentVolumes and change its reclaim policy: |
| 72 | +--> |
46 | 73 | 2. 选择你的 PersistentVolumes 中的一个并更改它的回收策略:
|
47 | 74 |
|
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 | +--> |
54 | 102 | 3. 验证你选择的 PersistentVolume 拥有正确的策略:
|
55 | 103 |
|
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` 时,它不会被自动删除。 |
71 | 127 |
|
72 | 128 | ## {{% heading "whatsnext" %}}
|
73 | 129 |
|
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) |
78 | 136 |
|
79 | 137 | ### 参考
|
80 | 138 |
|
81 | 139 | * [PersistentVolume](/docs/api-reference/{{< param "version" >}}/#persistentvolume-v1-core)
|
82 | 140 | * [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` 字段 |
87 | 142 |
|
0 commit comments