Restore PersistentVolumeClaim
Restore a deleted persistent volume claim
If the persistent volume claim was accidentally deleted, and the persistent volume is still present (status Released
), you can restore the PVC and PV by performing the following actions:
- Make sure there is no persistent volume claim (pvc) present for this volume (pv) (e.g. if you provisoned a new one with the same name, resulting in a new empty persistent volume)
- Modify the persistent volume claim reference
- Create a new PVC, with volumeName pointing to the PV
Requirement
- Note that for this to be possible, your persisent volume needs to be configured with a reclaim policy
Retain
. - If it's configured with
Delete
, your persistent volume will be deleted and you need to restore from a back-up, such as volumesnapshots or other methods.
Steps
Validate the PersistentVolume
C that the persistent volume has the status Released
. Do this by using:
If it's not released but for example Bound
, a pvc is still present for this volume. You will note that CLAIM
still has the previous PVC name present.
Update the claim ref
Edit the persistent volume, which is marked as Released
. If the Persistent Volume is marked as Available, no other action needs to be taken. If it is marked as any other value, do not modify the claimRef. You may need to perform step 1 first.
Edit this block from the persistent volume that you want to link to the new persistent volume claim:
- Remove the fields
resourceVersion
anduid
. - Update the
name
andnamespace
if necessary. These refer to the new pvc you will be creating. Usually these will be the same as before.
Claim the persistent volume
To claim the persistent volume, create a new PVC, which references the persistent volume. Note that volumeName is the name of the persistent volume in the example below.
If this PVC is part of a chart install, you may need to include the meta.helm.sh labels and annotations as well. They are present in the example, but needn't be present if the original PVC was not installed or managed with helm.
Create the PVC:
Validate
To validate the actions have been performed correctly, you query the available persistent volumes. It should now should the PV marked as Bound
. The PVC should display the correct PV name.
Last updated on