Assuming that you have dynamic provisioning enabled I advice you to use pv-migrate.
This is a cli tool/kubectl plugin to easily migrate the contents of one Kubernetes PersistentVolume
to another.
Common use cases:
- You have a database with a bound 30 GB
PersistentVolumeClaim
. It occurred 30 GB was not enough and you filled all the disk space rather quickly. And sadly your StorageClass
/provisioner doesn't support volume expansion. Now you need to create a new PVC of 100 GB and somehow copy all the data to the new volume, as-is, with its permissions and so on.
- You need to move a
PersistentVolumeClaim
from one namespace to another.
To migrate contents of PersistentVolumeClaim
pvc-a in namespace name-space-a to the PersistentVolumeClaim
pvc-b in namespace name-space-b, use the following command:
$ kubectl pv-migrate \
--source-namespace name-space-a \
--source pvc-a \
--dest-namespace name-space-b \
--dest pvc-b
Take also a look at: change-pv-reclaim-policy, resizing-persistent-volumes-using-kubernetes.