Kubernetes

如何重新附加持久卷?

  • June 10, 2020

我有這個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

如果您選擇 Retain 作為回收策略,則無法將 PV 附加到另一個 PVC,除非您手動刪除關聯的儲存資產(使用 刪除 claimRef 欄位kubectl edit pv pvc-01e19eb3-3d62-4772-bd49-1de4f08d5e81)。

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.

引用自:https://serverfault.com/questions/1020802