Had a question to edit pvc using kubectl edit or kubectl patch. I tried doing ed . . .

Bansi:
Had a question to edit pvc using kubectl edit or kubectl patch. I tried doing edit and changes storage size but that did not work. Ended up deleting and recreating. Is there a way to edit pvc storage? Thank you in Advance.

Sanjay Kumar:
@Bansi - to edit the pvc it will not make the change directly as pvc is being used by a pod. So delete the pod (grab the yaml of the pod before deleting it) first that is using the pvc and then you can increase the storage size directly by editing the pvc. Once that is complete then you can recreate the pod.
I hope this helps!

Bansi:
Thank you @Sanjay Kumar will try that out.

Bansi:
@Sanjay Kumar I just tried this got below error. Do you happen to have a working example?

error: persistentvolumeclaims “task-pv-claim” could not be patched: persistentvolumeclaims “task-pv-claim” is forbidden: only dynamically provisioned pvc canbe resized and the storageclass that provisions the pvc must support resize
You can run kubectl replace -f /tmp/kubectl-edit-156wk.yaml to try this update again

Sanjay Kumar:
@Bansi - your pvc should be created from specific storage class that have allowVolumeExpansion set to true. For example you can create the normal storage class first.

First create the storage class and the make to create both pv and pvc that use that storage class and test your scenario again.

Follow this article - https://kubernetes.io/blog/2018/07/12/resizing-persistent-volumes-using-kubernetes/|https://kubernetes.io/blog/2018/07/12/resizing-persistent-volumes-using-kubernetes/

Mohamed Ayman:
You can try with kubectl edit pvc pvc-name --record but only dynamically provisioned PVC can be resized and the storageclass that provisions the PVC must support resize.

Mohamed Ayman:
Regarding the resize of PVC which is associated with PV, you will need to delete the PVC then resize It and create It again.

Mohamed Ayman:
Using kubectl patch
Check this:
https://www.runlevl4.com/kubernetes/patching-kubernetes-resources#more-476