如何在IBM Cloud Kubernetes中将Bronze保留型PV迁移至ibmc-file-retain-gold存储类
Got it, let's walk through how to migrate your Bronze PV (with a Retain policy) to the ibmc-file-retain-gold storage class while keeping all your data intact. I've broken this down into clear, safe steps to avoid data loss:
First, you need to halt any pods writing to the PV to prevent data corruption. Let's find which pods are using the PVC bound to your PV:
kubectl get pods --all-namespaces -o=jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.spec.volumes[*].persistentVolumeClaim.claimName}{"\n"}{end}' | grep <your-pvc-name>
Once you have the pod names, delete them (or scale down their deployment if they're managed by one):
# Delete individual pods kubectl delete pod <pod-name> -n <namespace> # Or scale down a deployment to stop all replicas kubectl scale deployment <deployment-name> -n <namespace> --replicas=0
Since your PV uses the Retain policy, deleting the PVC won't touch the underlying storage volume—instead, the PV will shift to a Released state. Run:
kubectl delete pvc <your-pvc-name> -n <namespace>
Verify the PV's status to confirm it's released:
kubectl get pv <your-pv-name>
You should see STATUS: Released in the output.
Next, we need the unique ID of the actual File Storage volume in IBM Cloud that's backing your PV. Describe the PV to find this detail:
kubectl describe pv <your-pv-name>
Look for annotations like ibm.io/volume-id or fields under PersistentVolumeSource > IBMCloudFile that show the volume GUID. Note this value down (we'll call it <volume-guid> for later).
Now you can safely delete the old PV—remember, the underlying storage volume is still intact thanks to the Retain policy:
kubectl delete pv <your-pv-name>
Create a YAML file (e.g., gold-pvc.yaml) that defines a PVC using the ibmc-file-retain-gold storage class and references your existing volume. Make sure the storage size and access mode match your original PV:
apiVersion: v1 kind: PersistentVolumeClaim metadata: name: <new-gold-pvc-name> namespace: <your-namespace> spec: storageClassName: ibmc-file-retain-gold accessModes: - ReadWriteOnce # Match the access mode of your original PV resources: requests: storage: <original-volume-size> # Must be exactly the same as your old volume volumeName: <volume-guid> # Use the volume ID you noted earlier
Apply this PVC to your cluster:
kubectl apply -f gold-pvc.yaml
Check that the new PVC is bound to a fresh Gold-class PV:
kubectl get pvc <new-gold-pvc-name> -n <your-namespace> kubectl get pv
You should see the new PV with STATUS: Bound and STORAGECLASS: ibmc-file-retain-gold.
Now restart your pods or scale up the deployment to use the new PVC:
# Scale up a deployment kubectl scale deployment <deployment-name> -n <namespace> --replicas=1 # Or create a new pod pointing to the new PVC
- The storage size in the new PVC must exactly match your original volume's size—you can't resize during this migration unless you first resize the underlying IBM Cloud File Storage volume.
- Double-check that the access mode (e.g.,
ReadWriteOnce,ReadWriteMany) matches your original PV to avoid compatibility issues. - If the PVC fails to bind, confirm the
ibmc-file-retain-goldstorage class exists in your cluster:kubectl get storageclasses
内容的提问来源于stack exchange,提问作者icordoba

