How to manual recover a PV

前端 未结 3 932
误落风尘
误落风尘 2020-12-16 02:45

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 d

3条回答
  •  渐次进展
    2020-12-16 03:22

    The process to manually recover the volume is as below.

    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)

    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
    

    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
    

    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-volume
      persistentVolumeClaim:
        claimName: dhanvi-test-pvc
    

    Update: Volume cloning might help https://kubernetes.io/blog/2019/06/21/introducing-volume-cloning-alpha-for-kubernetes/

提交回复
热议问题