![如何重新连接持久卷?](https://linux22.com/image/753525/%E5%A6%82%E4%BD%95%E9%87%8D%E6%96%B0%E8%BF%9E%E6%8E%A5%E6%8C%81%E4%B9%85%E5%8D%B7%EF%BC%9F.png)
我有这个PersistentVolume
:
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
pvc-01e19eb3-3d62-4772-bd49-1de4f08d5e81 10Gi RWO Retain Released kymark/mariadb-pvc persistent-block-storage 10d
但是我删除了PVC。
如果我创建一个新的 PVC,如何指定我想要重新使用相同的现有 PV?即我想要返回相同的数据。
作为参考,我的 PVC YAML 如下所示:
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: mariadb-pvc
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi
storageClassName: persistent-block-storage
答案1
如果选择 Retain 作为回收策略,则除非您手动删除关联的存储资产(使用 删除 claimRef 字段kubectl edit pv pvc-01e19eb3-3d62-4772-bd49-1de4f08d5e81
),否则您无法将 PV 附加到另一个 PVC。
The Retain reclaim policy allows for manual reclamation of the resource. When the PersistentVolumeClaim is deleted, the PersistentVolume still exists and the volume is considered "released". But it is not yet available for another claim because the previous claimant's data remains on the volume. An administrator can manually reclaim the volume with the following steps.
Delete the PersistentVolume. The associated storage asset in external infrastructure (such as an AWS EBS, GCE PD, Azure Disk, or Cinder volume) still exists after the PV is deleted.
Manually clean up the data on the associated storage asset accordingly.
Manually delete the associated storage asset, or if you want to reuse the same storage asset, create a new PersistentVolume with the storage asset definition.