This guide explains how to replace a PersistentVolumeClaim to reference a copy of the original OpenStack volume.
Depending on your application, it may be easier to alternatively delete the PVC & PV, have an empty one provisioned and restore from a backup or if the application is clustered, by streaming from another replica.
This tutorial requires:
First, we create a copy of the original OpenStack volume with the new storage type.
Get the OpenStack volume ID backing the PV bound to the PVC
kubectl get pv $(kubectl -n $namespace get pvc $name -o jsonpath='{.spec.volumeName}') -o jsonpath='{.spec.csi.volumeHandle}'
Create a copy of the OpenStack volume
See guide in OpenStack documentation.
Now, create a separate PV which is backed by the new volume.
It will be pre-bound to a PVC that's created later.
That way, the new PVC will not trigger dynamic provisioning.
Get yaml of existing PV
kubectl get pv $(kubectl -n $namespace get pvc $name -o jsonpath='{.spec.volumeName}') -o yaml | tee pv.yml
Overwrite fields
Change fields in pv.yml
:
metadata.uid
: removemetadata.resourceVersion
: removemetadata.name
: Replace with unique name (e.g. add -ceph
suffix)spec.csi.volumeHandle
: Replace with ID of the newly created OpenStack volumespec.claimRef.uid
: removespec.claimRef.resourceVersion
: removeCreate PV with kubectl
kubectl create -f pv.yml
Lastly, replace (delete & create) the PVC.
The new one will immediately be bound to the PV we created.
We need to keep the same name, so a Pod referencing the PVC will be able to use it.
Get yaml of existing PVC
kubectl -n $namespace get pvc $name -o yaml | tee pvc.yml
Overwrite fields
Change fields in pvc.yml
:
metadata.uid
: removemetadata.resourceVersion
: removemetadata.annotations["pv.kubernetes.io/bind-completed"]
: removespec.storageClassName
: Replace with sys11-ceph
.spec.volumeName
: Replace with name of the new PVDelete PVC
Danger: This will also delete the original PV unless its reclaimPolicy is set to Retain
.
kubectl delete -n $namespace $name
Create PVC from manifest
kubectl create -f pvc.yml
Once verified that everything worked as expected, you may delete: