<p>Suppose I have a one node Database service (PostgreSQL, MySQL, whatever...) deployed on kubernetes using a PersistentVolumeClaim of 10G That will be running on GKE or AWS or Azure (It does not really matter). What is the procedure to scale up the disk to 20G? Is there a way, for instance, to have a PVC bind to a existing disk (a snapshot of the 10G disk) or something like that? </p>

<p>What I want is to increase the storage size of a disk that belongs to a PVC AND maintain the old data (the disk will not necessarily be a database, so I'm not looking to restore a database backup or something like that). </p>

<p>I'm looking for something like: take a snapshot of the old disk, create a bigger disk from the snapshot and "make the PVC use the new disk".</p>

<p>Thank you</p>

<p>You have a PVC with PV 10G. You want to increase its size. Unfortunately resize is not supported yet. So, you need to create new PVC with 20G size.</p>

<p>Lets say, your existing PVC with 10G called <code>older</code>.</p>

<p>Follow these steps:</p>

<p><strong>Step 1:</strong> Create new PVC with 20G, lets say its called <code>latest</code>.</p>

<p><strong>Step 2:</strong> Mount <code>older</code> &amp; <code>latest</code> both in a container. Copy data from <code>older</code> to <code>latest</code>. </p>

<p><strong>Step 3:</strong> Delete PVC <code>older</code>, we do not need <code>older</code> any more. Data copied to <code>latest</code> PV.</p>

<p><strong>Step 4:</strong> Make PV of <code>latest</code> Available.</p>

<pre><code>$ kubectl get pvc latest
NAME      STATUS    VOLUME                                     CAPACITY   ACCESS MODES   STORAGECLASS   AGE
latest    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>latest</code>. </p>

<pre><code>$ kubectl delete pvc latest

$ 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/latest   standard                 3m
</code></pre>

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

<p>Now, make this <code>latest</code> PV available to be claimed by another PVC, our <code>older</code> as we want to use 20G under this PVC <code>older</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 5:</strong> Claim <code>latest</code> PV by <code>older</code> PVC</p>

<pre><code>apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: older
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/older   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/older   standard                 9m
</code></pre>

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

<p>This is how, your PVC <code>older</code> has had <code>latest</code> PV with 20G.</p>
