How to re-attach persistent volume to pod when claim is deleted?

Hello.
How to re-attach persistent volume to a pod when persistent volume claim accidentally deleted?

I have service with one PV for mongodb and I remove claim. When I re-create claim with the same name new PV created instead of use PV. How to fix it?

And a more general question. Can I attach manualy created volume to the pod via PVC/PV?

Thanks.

2 Replies

Hey there,

What you'll need to do is set the storageClassName in your PVC manifest to linode-block-storage-retain, it sounds like it's currently set to linode-block-storage which will delete the associated PV when a PVC is deleted. You can learn more about this in our Deploy a Persistent Volume Claim with the Linode Block Storage CSI Driver](https://www.linode.com/docs/kubernetes/deploy-volumes-with-the-linode-block-storage-csi-driver/#create-a-persistent-volume-claim) guide.

When it comes to attaching a manually created volume to a pod via a PVC, that unfortunately is not something that can be done at this time. After reaching out to our LKE team, if you wanted to copy data off of an existing Block Storage volume onto another one to be used by your Kubernetes Cluster you should be able to follow these steps to do so.

  1. Provision a Persistent Volume in your cluster.
  2. Once that's created, you'll then mount the new Block Storage volume along with the existing one to a Linode and use that to copy your data over to the new Volume.
  3. You should be all set to detach both volumes from the Linode and have your data accessible to your Kubernetes Cluster now.

I hope this is helpful. Please let us know if you have any other questions. We're here for you 24/7.

Regards,
Ryan L.
Linode Support Staff

What you'll need to do is set the storageClassName in your PVC manifest to linode-block-storage-retain, it sounds like it's currently set to linode-block-storage which will delete the associated PV when a PVC is deleted. You can learn more about this in our Deploy a Persistent Volume Claim with the Linode Block Storage CSI Driver](https://www.linode.com/docs/kubernetes/deploy-volumes-with-the-linode-block-storage-csi-driver/#create-a-persistent-volume-claim) guide.

Not certainly in that way. First of all create PVC with some name (with linode-block-storage-retain class). Then I delete PVC, PV is change status to "Released". But when I re-create new PVC with same claim name, driver create new PV instead of re-attach existed PV.

But I figured out how to do it:
Just change new PVC uid in PV spec.

TL, DR.

At first I get new PVC uid by command:
kubectl get pvc my-pvc-0 -o yaml | grep uid
Then I edit new empty volume, what provisioned by CSI Driver and remove claim - pv binding by removing claimRef section in:
kubectl edit pv pvc-yyyyyyyyyyyy
After that new PV change status to "Available" and can be deleted.
Then I edit old PV, what I want to bind with pod via new claim and put PVC uid to claimRef section:
kubectl edit pv pvc-xxxxxxxxxxx
After that, the old volume became associated with the new claim.

I hope I wrote it clearly.
Will be crate to create claim without provision or, will better, have more control of PVC/PC by possibility of connecting the manually created volume to the POD.

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct