0

I've got this 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

But I deleted the PVC.

If I create a new PVC, how can I specify that I want to re-use that same existing PV? i.e. I want the same data back.

For reference, my PVC YAML looks like:

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: mariadb-pvc
spec:
  accessModes:
    - ReadWriteOnce 
  resources:
    requests:
      storage: 10Gi
  storageClassName: persistent-block-storage
mpen
  • 423
  • 1
  • 6
  • 15

1 Answers1

2

If you choose Retain as the reclaim policy, you cannot attach PV to another PVC unless you manually delete the associated storage asset(delete the claimRef field with 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.

Hang Du
  • 136
  • 1
  • Wait, so if I leave the PV as "delete" it won't actually delete my data when I delete the PVC? And then what..? How do I re-attach it? How will the new PVC knows it belongs with that old PV? – mpen Jun 10 '20 at 06:42
  • For volume plugins that support the Delete reclaim policy, deletion removes both the PersistentVolume object from Kubernetes, as well as the associated storage asset in the external infrastructure You can get more details from the following link. https://kubernetes.io/docs/concepts/storage/persistent-volumes/#reclaiming – Hang Du Jun 10 '20 at 07:15