<p>Recently I tried to resize <code>PersistentVolumeClaim</code> with help of <code>Kubectl edit pvc</code> to increase storage from <code>10 Gi</code> to <code>70 Gi</code> but it’s giving error:</p>
<pre><code>persistentvolumeclaims &quot;myclaim&quot; was not valid:
* spec: Forbidden: spec is iimmutable after creation except resources.requests for bound claims
</code></pre>
<p>How can I do this with out error with help of <code>Kubectl edit</code>.</p>
<p><a href="https://i.stack.imgur.com/2SVjD.jpg" rel="noreferrer">Screen of error</a></p>

Aftab
<p>I have verified this on my GKE test cluster which supports <a href="https://kubernetes.io/docs/concepts/storage/dynamic-provisioning/" rel="nofollow noreferrer">Dynamic Provisioning</a>. As I mentioned in comments, you are trying to edit <code>spec</code> part of <a href="https://gist.github.com/cloudyuga/f9926cd706df0d26fd19c9add15314fb" rel="nofollow noreferrer">PersistentVolumeClaim</a> which is <code>immutable</code>, except <code>resources.requests</code>.</p>
<p>However, <code>storage</code> field path is <code>spec.resources.requests.storage</code> and I do not have any issue with editing this. When you are using <code>kubectl edit</code> as default it's using <code>vi editor</code> which controls might be hard/it's easy for a typo. I guess you accidentally changed more than just <code>storage</code> in your example (maybe typo in <code>selectors</code>, <code>labels</code>).</p>
<p>You can always use another editor like <code>nano</code>.
<code>KUBE_EDITOR=&quot;nano&quot; kubectl edit pvc &lt;pvc-name&gt;</code></p>
<p>For test Ive used <a href="https://gist.github.com/cloudyuga/f9926cd706df0d26fd19c9add15314fb" rel="nofollow noreferrer">This YAML</a> on GKE cluster.</p>
<pre><code>$ 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
</code></pre>
<p>Instead of <code>editing</code> resource you can also <a href="https://kubernetes.io/docs/reference/kubectl/cheatsheet/#patching-resources" rel="nofollow noreferrer">patch resources</a>.</p>
<p><code>kubectl patch pvc &lt;pvc-name&gt; -p '{&quot;spec&quot;:{&quot;resources&quot;:{&quot;requests&quot;:{&quot;storage&quot;:&quot;70Gi&quot;}}}}'</code></p>
<pre><code>$ kubectl patch pvc mongodb-pv-claim -p '{&quot;spec&quot;:{&quot;resources&quot;:{&quot;requests&quot;:{&quot;storage&quot;:&quot;70Gi&quot;}}}}'
persistentvolumeclaim/mongodb-pv-claim patched
</code></pre>
<p>After that, if you will describe <code>PVC</code> you can find information like below:</p>
<pre><code>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.
</code></pre>
<p>After while:</p>
<pre><code>$ 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
</code></pre>
<p>Please keep in mind that as per error message, that it's wokring only for <code>bound claims</code>.</p>
<p>If <code>patch</code> or <code>edit with nano</code> won't work for you, please provide your <code>PVC</code> yaml.</p>
<p><strong>EDIT</strong></p>
<p>As per OP's comment below answer, creating <code>storageclass</code> which supports <a href="https://kubernetes.io/docs/concepts/storage/dynamic-provisioning/#enabling-dynamic-provisioning" rel="nofollow noreferrer">Dynamic Provisioning</a> resolved this issue.</p>
