You can use the Flexvolume2CSI CLI to batch covert persistent volume claims (PVCs) and persistent volumes (PVs) managed by FlexVolume to PVCs and PVs managed by CSI. This topic describes how to use Flexvolume2CSI to batch convert PVCs and PVs.
How it works
You can use Flexvolume2CSI to list all PVCs in a cluster, PVCs in the specified namespace, or the specified PVCs and the corresponding PVs. Then, use Flexvolume2CSI to convert the PVCs and PVs managed by FlexVolume to PVCs and PVs managed by CSI, including labels and FlexVolume fields.
You can use Flexvolume2CSI to convert the PVs and PVCs of only standard File Storage NAS (NAS), Object Storage Service (OSS), and disk volumes. We recommend that you verify the YAML file generated by Flexvolume2CSI for CSI before you use it to provision volumes.
Step 1: Install Flexvolume2CSI
Run the following command to install Flexvolume2CSI.
Flexvolume2CSI supports MacOS and Linux.
curl https://ack-csiplugin.oss-cn-hangzhou.aliyuncs.com/flexvolume2csi/get-translator.sh | bash
Run the following command to verify that Flexvolume2CSI is installed:
flexvolume2csi version
Expected output:
flexvolume2csi: v1.0.2+b1de5bd BuildDate: 2024-04-09T07:20:26Z GitCommit: b1de5bdce11b4b59ddce38d91d868b5f35a431c1 GitTreeState: clean GoVersion: go1.18.4 Compiler: gc Platform: darwin/arm64
The output indicates that Flexvolume2CSI is installed.
Step 2: Configure cluster information for Flexvolume2CSI
Run the following command to configure cluster information for Flexvolume2CSI:
flexvolume2csi configure
Expected output:
Configuring profile 'default' ... Default Cluster Id (ClusterId of ACK Flexvolume Cluster) [c4869a2f603ca4e74****************]: Default Kubeconfig Path (default is ~/.kube/config) []: Saving profile[default] ... Done.
Parameter
Description
Cluster Id
The ID of the cluster that uses FlexVolume.
Kubeconfig Path
The path of the kubeconfig file of the cluster that uses FlexVolume. The default is ~/.kube/config.
Step 3: Convert PVs and PVCs managed by FlexVolume in the cluster to PVs and PVCs managed by CSI
Optional parameters
Run the following command to query the optional parameters of Flexvolume2CSI:
flexvolume2csi translate help
Expected output:
flexvolume2csi source add [-n namespace] [-c pvc] [-o outputfile] [-p prefix] [-s suffix] [-b backupfile] [-a apiversion] [-t storageclass]
Usage:
flexvolume2csi translate [-n namespace] [-c pvc] [-o outputfile] [-p prefix] [-s suffix] [-b backupfile] [-a apiversion] [-t storageclass] [flags]
Examples:
# Translate PVCs and related PVs in all namespaces
flexvolume2csi translate -o output.txt
# Translate PVCs and related PVs in default namespace
flexvolume2csi translate -n default -o output.txt
# Translate PVC test-pvc and related PV in default namespace
flexvolume2csi translate -n default -p test-pvc -o output.txt
Flags:
-a, --apiversion string change pv/pvc apiversion (default "v1")
-b, --backupfile string path to backup (flexvolume) file (default "./backupfile.txt")
-h, --help help for translate
-n, --namespace string specified namespace
-o, --outputfile string path to output (CSI) file (default "./outputfile.txt")
-p, --prefix string change pv/pvc name to prefix-xxx
-c, --pvc string specified pvc
-t, --storageclass string change storageclass name
-s, --suffix string change pv/pvc name to xxx-suffix
Optional parameter | Description |
-o | The path of the YAML file for the PVCs and PVs managed by CSI. By default, the file is named |
-b | The path of the backup YAML file for the original PVCs and PVs managed by FlexVolume. By default, the file is named |
-n | The name of the namespace. If you specify a namespace, only PVs and PVCs in the specified namespace are converted. By default, PVs and PVCs in all namespaces are converted. |
-c | The name of the PVC. If you specify a PVC, only the specified PVC and PV are converted. This parameter must be used together with the |
-p | The prefix for the PVCs and PVs managed by CSI. By default, no prefix is specified. For example, if the PVC managed by FlexVolume is named pvc-test and the prefix is csi, the PVC managed by CSI is named csi-pvc-test. |
-s | The suffix for the PVCs and PVs managed by CSI. By default, no prefix is specified. For example, if the PVC managed by FlexVolume is named pvc-test and the suffix is csi, the PVC managed by CSI is named pvc-test-csi. |
Example
Create a file named pv.yaml in a cluster that uses FlexVolume and add the following content to the file:
apiVersion: v1 kind: PersistentVolume metadata: name: pv-nas spec: capacity: storage: 5Gi storageClassName: nas accessModes: - ReadWriteMany flexVolume: driver: "alicloud/nas" options: server: "0cd8b4a576-u****.cn-hangzhou.nas.aliyuncs.com" #Replace the value with the actual mount target. path: "/k8s" vers: "3" options: "nolock,tcp,noresvport"
Run the following command to create a PV in the cluster:
kubectl apply -f pv.yaml
Create a file named pvc.yaml in the cluster and add the following content to the file:
apiVersion: v1 kind: PersistentVolumeClaim metadata: name: pvc-nas spec: accessModes: - ReadWriteMany storageClassName: nas resources: requests: storage: 5Gi
Run the following command to create a PVC in the cluster:
kubectl apply -f pvc.yaml
Run the following command to verify that the PV is bound to the PVC:
kubectl get pvc | grep pvc-nas
Expected output:
pvc-nas Bound pv-nas 5Gi RWO nas 10s
Run the following command to use Flexvolume2CSI to convert the PV and PVC in the cluster:
flexvolume2csi translate
Run the following command to print the content of the YAML files of the PV and PVC managed by CSI:
cat ./outputfile.yaml
Expected output:
--- apiVersion: v1 kind: PersistentVolume metadata: labels: alicloud-pvname: pv-nas name: pv-nas spec: accessModes: - ReadWriteMany capacity: storage: 5Gi csi: driver: nasplugin.csi.alibabacloud.com volumeAttributes: path: /k8s server: 0cd8b4a576-u****.cn-hangzhou.nas.aliyuncs.com volumeHandle: pv-nas mountOptions: - nolock,tcp,noresvport - vers=3 persistentVolumeReclaimPolicy: Retain storageClassName: nas volumeMode: Filesystem --- apiVersion: v1 kind: PersistentVolumeClaim metadata: name: pvc-nas namespace: default spec: accessModes: - ReadWriteMany resources: requests: storage: 5Gi selector: matchLabels: alicloud-pvname: pv-nas storageClassName: nas volumeMode: Filesystem volumeName: pv-nas
The output indicates that the PV and PVC are converted.
References
Use csi-compatible-controller to migrate from FlexVolume to CSI
Migrate from FlexVolume to CSI for clusters where no data is stored
Use CSI to take over the statically provisioned NAS volumes that are managed by FlexVolume
Use CSI to take over the statically provisioned OSS volumes that are managed by FlexVolume