Virtual Machine Image Export
This feature is used to export the system image of a virtual machine and upload it to object storage, so that files in the object storage can be added as a source to the platform’s virtual machine image.
Procedure
Note: All the operations below must be performed on the master node of the cluster where the virtual machine is located.
Stop the Virtual Machine
-
In the left navigation bar, click Virtualization > Virtual Machines.
-
Click the name of the virtual machine whose system image you want to export. The page will redirect to the Container Platform’s virtual machine details page.
-
Click Stop.
Create vmexport Resource
-
Open the CLI tool.
-
Execute the following commands to set variables.
NAMESPACE=<namespace> VM_NAME=<vm_name> TTL_DURATION=2hParameter description:
- NAMESPACE: The name of the namespace where the virtual machine is located. Replace <namespace> with this name.
- VM_NAME: The name of the virtual machine whose system image needs to be exported. Replace <vm_name> with this name.
- TTL_DURATION: The lifetime of the export task, default is 2 hours, which can be increased as needed.
-
Execute the following command to create a vmexport resource.
cat <<EOF | kubectl create -f - apiVersion: export.kubevirt.io/v1alpha1 kind: VirtualMachineExport metadata: name: export-$VM_NAME namespace: $NAMESPACE spec: ttlDuration: $TTL_DURATION source: apiGroup: "kubevirt.io" kind: VirtualMachine name: $VM_NAME EOFIf you see output similar to the following, the creation was successful.
virtualmachineexport.export.kubevirt.io/export-k1 created -
Execute the following command to check the status of the vmexport resource.
kubectl -n $NAMESPACE get vmexport export-$VM_NAME -wOutput:
NAME SOURCEKIND SOURCENAME PHASE export-k1 VirtualMachine k1 Ready -
When the PHASE field in the above output changes to Ready, press ctrl (control) + c to stop the watch operation.
-
Execute the following command to get the TOKEN.
TOKEN=$(kubectl -n $NAMESPACE get secret export-token-export-$VM_NAME -o jsonpath={.data.token} | base64 -d)
Download Virtual Machine Image File
-
Execute the following command to get the IP address of the virtual machine export Pod in the specified namespace and store it in the EXPORT_SERVER_IP environment variable.
EXPORT_SERVER_IP=$(kubectl -n $NAMESPACE get po virt-export-export-$VM_NAME -o jsonpath='{.status.podIP}') -
Execute the following command to set the URL environment variable, which points to the virtual machine’s disk image file.
URL=https://$EXPORT_SERVER_IP:8443/volumes/$VM_NAME-rootfs/disk.img.gz -
Execute the following command to download the image file. The downloaded file name will be disk.img.gz.
curl -k -O -H "x-kubevirt-export-token: $TOKEN" $URL
Upload Virtual Machine Image File to Object Storage
Upload the downloaded image file to object storage. You can use any S3 tool for uploading. This document uses the mc (minio-client) tool as an example.
-
Execute the following command to configure the mc tool and connect to the specified S3 storage service.
mc alias set minio <ENDPOINT> <ACCESSKEY> <SECRETKEY>Parameter description:
- ENDPOINT: The address of the S3 storage service. Replace
with this address. - ACCESSKEY, SECRETKEY: The user ak, sk of the S3 storage service for authentication. For more information, refer to MinIO Object Storage .
- ENDPOINT: The address of the S3 storage service. Replace
-
Execute the following command to create a bucket for storing virtual machine image files.
mc mb minio/vmdisks -
Execute the following command to upload the exported virtual machine image file disk.img.gz to the created bucket.
mc put disk.img.gz minio/vmdisks
Create Virtual Machine Image
-
In the left navigation bar, click Virtualization > Images.
-
Click Add VM Image.
-
Fill in the image address as <ENDPOINT>/vmdisks/disk.img.gz. Replace <ENDPOINT> with the address of the S3 storage service. For other parameter descriptions, refer to Add Virtual Machine Image .
-
Click Add.
Related Operations
Create a Virtual Machine Using the New Virtual Machine Image
For detailed operations, refer to the relevant documentation in Container Platform > Virtualization > Create a virtual machine.