问题描述
根据官方文档 https://kubernetes. io/docs/tasks/administer-cluster/change-pv-reclaim-policy/使用保留"策略,可以手动恢复PV.这实际上是什么意思,有没有一种工具可以让我从该保留" PV中读取数据并将其写入另一个PV中,或者这意味着您可以安装该卷手册以获取访问权限?
according to the official docs https://kubernetes.io/docs/tasks/administer-cluster/change-pv-reclaim-policy/ with the "Retain" policy a PV can be manually recovered . What does that actually mean and is there a tool how I can read the data from that "retained" PV and write it into to another PV , or does it mean you can mount that volume manual in order to gain access ?
推荐答案
手动恢复卷的过程如下.
The process to manually recover the volume is as below.
即使删除了PVC,也可以使用同一PV将数据与数据一起安装到不同的Pod(PV必须存在,如果storageclass的回收策略为Retain,则通常存在)
You can use the same PV to mount to different pod along with the data even after the PVC is deleted (PV must exist, will typically exist if the reclaim policy of storageclass is Retain)
验证PV处于释放状态. (即,目前没有pvc声称拥有它)
Verify that PV is in released state. (ie no pvc has claimed it currently)
➜ ~ kubectl get pv
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
pvc-eae6acda-59c7-11e9-ab12-06151ee9837e 16Gi RWO Retain Released default/dhanvi-test-pvc gp2 52m
编辑PV(kubectl edit pv pvc-eae6acda-59c7-11e9-ab12-06151ee9837e
)并删除spec.claimRef部分. PV声明将无法设置,如下所示.
Edit the PV (kubectl edit pv pvc-eae6acda-59c7-11e9-ab12-06151ee9837e
) and remove the spec.claimRef part. The PV claim would be unset like below.
➜ ~ kubectl get pv
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
pvc-eae6acda-59c7-11e9-ab12-06151ee9837e 16Gi RWO Retain Available gp2 57m
然后使用以下PVC声明PV.
Then claim the PV using PVC as below.
---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: dhanvi-test-pvc
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 16Gi
volumeName: "pvc-eae6acda-59c7-11e9-ab12-06151ee9837e"
可以在如下所示的吊舱中使用.
Can be used in the pods as below.
volumes:
- name: dhanvi-test-pv
persistentVolumeClaim:
claimName: dhanvi-test-pvc
更新:卷克隆可能会帮助 https ://kubernetes.io/blog/2019/06/21/introducing-volume-cloning-alpha-for-kubernetes/
Update: Volume cloning might help https://kubernetes.io/blog/2019/06/21/introducing-volume-cloning-alpha-for-kubernetes/
这篇关于如何手动恢复PV的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!