Appearance
Volume Migration
How to migrate a persistent volume to another availability zone or even cluster
Migrating a volume from one availability zone to another can be done with pv-migrate.
Prepare a target volume
To migrate an existing persistent volume you will first need to create a new one with the same parameters as the old volume on the target AZ or cluster.
Get the current persistent volume:
bash
kubectl get pvc/<pvc-name> -o yamlyaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
annotations:
kubectl.kubernetes.io/last-applied-configuration: |
{"apiVersion":"v1","kind":"PersistentVolumeClaim","metadata":{"annotations":{},"name":"pvc-example","namespace":"examples"},"spec":{"accessModes":["ReadWriteOnce"],"resources":{"requests":{"storage":"10Gi"}},"storageClassName":"kubevirt-san-kcsi-standard"}}
pv.kubernetes.io/bind-completed: "yes"
pv.kubernetes.io/bound-by-controller: "yes"
volume.beta.kubernetes.io/storage-provisioner: csi.kubevirt.io
volume.kubernetes.io/selected-node: test-78959c569c-b2jrq
volume.kubernetes.io/storage-provisioner: csi.kubevirt.io
creationTimestamp: "2026-01-29T15:16:09Z"
finalizers:
- kubernetes.io/pvc-protection
name: pvc-example
namespace: default
resourceVersion: "52228848"
uid: b8462e6e-a0fe-47e7-823c-5811523570fd
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi
storageClassName: kubevirt-san-kcsi-standard-olt
volumeMode: Filesystem
volumeName: pvc-b8462e6e-a0fe-47e7-823c-5811523570fd
status:
accessModes:
- ReadWriteOnce
capacity:
storage: 10Gi
phase: BoundNow use this as the basis to create a new persistent volume claim on the target zone / cluster. Ensure that your new volume at least matches the old one in size, or is bigger.
Given the above example, a new target volume might look like this:
yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: new-pvc
namespace: default
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 200Gi
storageClassName: kubevirt-san-kcsi-standard-zoi
volumeMode: Filesystem💡 Note
Observe the change of storageClassName in the above example. The new volume will be created in the ZOI availability zone, while the old one was in OLT.
Apply the new volume to your cluster:
bash
kubectl apply -f pvc.yamlThen check if the new PersistentVolumeClaim has been created successfully:
bash
kubectl get pvc
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS VOLUMEATTRIBUTESCLASS AGE
new-pvc Bound pvc-c605e87a-f559-4855-b78c-832a76bcfa65 200Gi RWO kubevirt-san-kcsi-standard-zoi <unset> 41s
pvc-example Bound pvc-b8462e6e-a0fe-47e7-823c-5811523570fd 10Gi RWO kubevirt-san-kcsi-standard-olt <unset> 52mPrepare pv-migrate
Next we need to create a file called values.yaml with the following content:
yaml
rsync:
nodeSelector:
topology.kubernetes.io/zone: "zoi"This will ensure that pv-migrate will target the correct availability zone for its rsync pod.
Before running the migration however you will need to ensure the current volume is not being accessed and actively written to anymore.
⚠️ Warning
Make sure to shutdown / scale down all pods that are using the current volume to 0 before running the migration!
Migrate the volume
Once no pod is actively using the volume anymore, run the migration with the following command:
bash
pv-migrate migrate -n default -N default -s svc pvc-example new-pvc -f values.yaml
Jan 29 17:03:10.482 INF ⚠️ Using legacy mode with PVC names as arguments, consider switching to --source and --dest flags
Jan 29 17:03:10.482 INF 🚀 Starting migration
Jan 29 17:03:10.592 INF 💭 Attempting migration source=default/pvc-example dest=default/new-pvc strategies=svc
Jan 29 17:03:10.592 INF 🚁 Attempt using strategy source=default/pvc-example dest=default/new-pvc attempt_id=bdeed strategy=svc
Jan 29 17:03:10.592 INF 🔑 Generating SSH key pair source=default/pvc-example dest=default/new-pvc attempt_id=bdeed strategy=svc algorithm=ed25519
📂 Copying data... 100% |██████████████████████████████████████████████████| (435 MB/s)
Jan 29 17:15:29.951 INF 🧹 Cleaning up source=default/pvc-example dest=default/new-pvc attempt_id=bdeed strategy=svc
Jan 29 17:15:30.671 INF ✨ Cleanup done source=default/pvc-example dest=default/new-pvc attempt_id=bdeed strategy=svc
Jan 29 17:15:30.671 INF ✅ Migration succeeded source=default/pvc-example dest=default/new-pvc attempt_id=bdeed strategy=svcThe final step now would be to change the reference that the pod is using to point to the new volume. For a Deployment this would usually be located under spec.template.spec.volumes[*].persistentVolumeClaim.claimName.
