<p><strong>Is is possible to rename a PVC?</strong> I can't seem to find an evidence it is possible.</p>

<hr>

<p>I'm trying mitigate an "No space left of device" issue I just stumbled upon. Essentially my plan requires me to resize the volume, on which my service persists its data.</p>

<p>Unfortunately I'm still on Kubernetes 1.8.6 on GKE. It does not have the <a href="https://kubernetes.io/docs/admin/admission-controllers/#persistentvolumeclaimresize" rel="noreferrer"><code>PersistentVolumeClaimResize</code></a> admission plugin enabled:</p>

<ul>
<li>1.9.1: <a href="https://github.com/kubernetes/kubernetes/blob/v1.9.1/cluster/gce/config-default.sh#L300" rel="noreferrer">config-default.sh#L254@1.9.1</a></li>
<li>1.8.6: <a href="https://github.com/kubernetes/kubernetes/blob/v1.8.6/cluster/gce/config-default.sh#L254" rel="noreferrer">config-default.sh#L254@1.8.6</a></li>
</ul>

<p>Therefor I have to try and save the data manually. I made the following plan:</p>

<ol>
<li>create a new, bigger volume PVC,</li>
<li>create a temp container with attached "victim" pvc and a new bigger pvc,</li>
<li>copy the data,</li>
<li>drop "victim" PVC,</li>
<li><strong>rename</strong> new bigger pvc to take place of "victim".</li>
</ol>

<p>The PVC in question is attached to StatefulSet, so the old and new names must match (as StatefulSet expects follows the volume naming convention). </p>

<p>But I don't understand how to rename persistent volume claims.</p>

<p>The answer of your question is <strong>NO</strong>. There is no way to change any meta name in Kubernetes.</p>

<p>But, there is a way to fulfill your requirement.</p>

<p>You want to claim your new <em>bigger</em> PersistentVolume by old PersistentVolumeClaim.</p>

<p>Lets say, old PVC named <code>victim</code> and new PVC named <code>bigger</code>. You want to claim PV created for <code>bigger</code> by <code>victim</code> PVC. Because your application is already using <code>victim</code> PVC.</p>

<p>Follow these steps to do the hack.</p>

<p><strong>Step 1:</strong> Delete your old PVC <code>victim</code>.</p>

<p><strong>Step 2:</strong> Make PV of <code>bigger</code> Available.</p>

<pre><code>$ kubectl get pvc bigger
NAME      STATUS    VOLUME                                     CAPACITY   ACCESS MODES   STORAGECLASS   AGE
bigger    Bound     pvc-8badc3c2-08c5-11e8-b07a-080027b3e1a6   10Gi       RWO            standard       30s
</code></pre>

<p>Edit PV <code>pvc-8badc3c2-08c5-11e8-b07a-080027b3e1a6</code> to set persistentVolumeReclaimPolicy to <code>Retain</code>. So that deleting PVC will not delete PV.</p>

<p>Now, delete PVC <code>bigger</code>. </p>

<pre><code>$ kubectl delete pvc bigger

$ kubectl get pv
NAME                                       CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS     CLAIM            STORAGECLASS   REASON    AGE
pvc-8badc3c2-08c5-11e8-b07a-080027b3e1a6   10Gi       RWO            Retain           Released   default/bigger   standard                 3m
</code></pre>

<p>See the status, PV is Released.</p>

<p>Now, make this PV available to be claimed by another PVC, our <code>victim</code>.</p>

<p>Edit PV again to remove claimRef</p>

<pre><code>$ kubectl edit pv pvc-8badc3c2-08c5-11e8-b07a-080027b3e1a6

$ kubectl get pv
NAME                                       CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS      CLAIM     STORAGECLASS   REASON    AGE
pvc-8badc3c2-08c5-11e8-b07a-080027b3e1a6   10Gi       RWO            Retain           Available             standard                 6m
</code></pre>

<p>Now the status of PV is Available. </p>

<p><strong>Step 3:</strong> Claim <code>bigger</code> PV by <code>victim</code> PVC</p>

<pre><code>apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: victim
spec:
  accessModes:
    - ReadWriteOnce
  volumeName: pvc-8badc3c2-08c5-11e8-b07a-080027b3e1a6
  resources:
    requests:
      storage: 10Gi
</code></pre>

<p>Use volumeName <code>pvc-8badc3c2-08c5-11e8-b07a-080027b3e1a6</code></p>

<pre><code>kubectl get pvc,pv
NAME         STATUS    VOLUME                                     CAPACITY   ACCESS MODES   STORAGECLASS   AGE
pvc/victim   Bound     pvc-8badc3c2-08c5-11e8-b07a-080027b3e1a6   10Gi       RWO            standard       9s

NAME                                          CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS    CLAIM            STORAGECLASS   REASON    AGE
pv/pvc-8badc3c2-08c5-11e8-b07a-080027b3e1a6   10Gi       RWO            Retain           Bound     default/victim   standard                 9m
</code></pre>

<p><strong>Finally:</strong> Set persistentVolumeReclaimPolicy to <code>Delete</code></p>

<p>This is how, your PVC <code>victim</code> has had bigger PV.</p>
