6

Recently I tried to resize PersistentVolumeClaim with help of Kubectl edit pvc to increase storage from 10 Gi to 70 Gi but it’s giving error:

persistentvolumeclaims "myclaim" was not valid:
* spec: Forbidden: spec is iimmutable after creation except resources.requests for bound claims

How can I do this with out error with help of Kubectl edit.

Screen of error

PjoterS
  • 12,841
  • 1
  • 22
  • 54
Aftab
  • 71
  • 1
  • 1
  • 4
  • 1
    "*... but it’s giving error ....*" - Please [edit] the post and include the error. Also, please include the resource definition as text. – Turing85 Sep 19 '20 at 06:15
  • Please edit your question and add more details, like your environment, how did you create this PVC, did you unbound it before changing? – PjoterS Sep 21 '20 at 08:25
  • 2
    As this question is still closed I will provide short answer in comment. `spec` in `PVC` is `immutable` which means you cannot change this value after creation. In PVC you can only change resource requests. `spec is immutable after creation **except resources.requests for bound claims** ` If you need to change storage size, you need to remove this PVC and create another one with storage 70Gi – PjoterS Sep 25 '20 at 05:48
  • @PjoterS its open now – Jonas Sep 25 '20 at 06:01

1 Answers1

7

I have verified this on my GKE test cluster which supports Dynamic Provisioning. As I mentioned in comments, you are trying to edit spec part of PersistentVolumeClaim which is immutable, except resources.requests.

However, storage field path is spec.resources.requests.storage and I do not have any issue with editing this. When you are using kubectl edit as default it's using vi editor which controls might be hard/it's easy for a typo. I guess you accidentally changed more than just storage in your example (maybe typo in selectors, labels).

You can always use another editor like nano. KUBE_EDITOR="nano" kubectl edit pvc <pvc-name>

For test Ive used This YAML on GKE cluster.

$ kubectl get pvc
NAME               STATUS   VOLUME                                     CAPACITY   ACCESS MODES   STORAGECLASS   AGE
mongodb-pv-claim   Bound    pvc-802714bf-3922-4b41-b70f-97394f252a00   10Gi       RWO            standard       16s

Instead of editing resource you can also patch resources.

kubectl patch pvc <pvc-name> -p '{"spec":{"resources":{"requests":{"storage":"70Gi"}}}}'

$ kubectl patch pvc mongodb-pv-claim -p '{"spec":{"resources":{"requests":{"storage":"70Gi"}}}}}'
persistentvolumeclaim/mongodb-pv-claim patched

After that, if you will describe PVC you can find information like below:

Conditions:
  Type                      Status  LastProbeTime                     LastTransitionTime                Reason  Message
  ----                      ------  -----------------                 ------------------                ------  -------
  FileSystemResizePending   True    Mon, 01 Jan 0001 00:00:00 +0000   Fri, 25 Sep 2020 06:40:17 +0000           Waiting for user to (re-)start a pod to finish
 file system resize of volume on node.

After while:

$ kubectl get pvc
NAME               STATUS   VOLUME                                     CAPACITY   ACCESS MODES   STORAGECLASS   AGE
mongodb-pv-claim   Bound    pvc-802714bf-3922-4b41-b70f-97394f252a00   70Gi       RWO            standard       8m37s

Please keep in mind that as per error message, that it's wokring only for bound claims.

If patch or edit with nano won't work for you, please provide your PVC yaml.

EDIT

As per OP's comment below answer, creating storageclass which supports Dynamic Provisioning resolved this issue.

user3142695
  • 15,844
  • 47
  • 176
  • 332
PjoterS
  • 12,841
  • 1
  • 22
  • 54
  • May be you are using a dynamic storage class, because according to my search and Kubernetes documentation only A PVC can be edited if the storage class is Dynamic so first i created a dynamic storage class and then edited same pvc smoothly without any error. – Aftab Sep 26 '20 at 06:12
  • @Aftab I've used GKE so I was using `Dynamic Provisioning`. – PjoterS Sep 28 '20 at 07:35
  • Right, Solved then, – Aftab Sep 29 '20 at 08:13
  • Hello @Aftab I am also trying to create POD using a PVC which is using a SC. But when I start the pod it gives me below error in my local Virtualbox cluster... did you faced any such problem? Warning FailedScheduling 81s (x2 over 82s) default-scheduler 0/3 nodes are available: 1 node(s) had taint {node-role.kubernetes.io/master: }, that the pod didn't tolerate, 2 node(s) didn't find available persistent volumes to bind. – Nitin G May 30 '21 at 11:09