Virtual machine cross-storage class migration method and device

By exporting the original PVC of the virtual machine on the Kubevirt platform, converting and compressing it, generating the minimum image and importing the target PVC, the problem of virtual machine migration across storage classes is solved, and the optimization of storage space and data integrity is achieved.

CN119690593APending Publication Date: 2025-03-25CHINA ASEAN INFORMATION PORT CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411882266.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-19
Publication Date
2025-03-25

AI Technical Summary

Technical Problem

The existing technology is difficult to support the migration of virtual machines across different storage classes on the Kubevirt platform, resulting in waste of storage space and inefficient use.

Method used

By mounting the original PVC of the virtual machine into the conversion container to export the image, generating the minimum image through mirror conversion and compression, and importing the minimum image into the target PVC and replacing the original PVC of the virtual machine, cross-storage class migration is achieved.

Benefits of technology

It realizes cross-storage class migration of virtual machines, is compatible with different storage class providers and storage modes, optimizes the use of storage space, and ensures data integrity during the migration process.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119690593A_ABST
    Figure CN119690593A_ABST
Patent Text Reader

Abstract

The invention discloses a cross-storage-class migration method for a virtual machine, and relates to data processing, and the method comprises the following steps: mounting an original PVC (polyvinyl chloride) of the virtual machine into a conversion container to export a mirror image, then generating a minimum mirror image through mirror image conversion and compression, and importing the minimum mirror image into a target PVC to replace the original PVC of the virtual machine to realize cross-storage-class migration. The invention discloses a device for cross-storage class migration of a virtual machine. According to the method and the device, the problem of cross-storage migration of the virtual machine in the prior art is solved, the storage space is saved, and the data integrity in the migration process is ensured.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to data processing, and more particularly to a method and device for migrating a virtual machine across storage classes. Background Art

[0002] With the development of cloud computing technology, Kubernetes has become the mainstream platform for container orchestration, and Kubevirt, as a solution for running virtual machines on Kubernetes, has also received widespread attention. However, in actual applications, virtual machines may need to be migrated across different storage classes to meet performance, capacity or cost requirements. Currently, this requirement has not been well supported on the Kubevirt platform.

[0003] Kubevirt is a Redhat open source project that runs virtual machines in containers and manages the lifecycle of virtual machines in a Kubernetes cloud-native way. Kubevirt provides multiple virtual machine disks, including PVC as the backend storage, which is suitable for data persistence. The PV types used can be block and filesystem. When using filesystem, the disk.img on the PVC is used as a RAW file as the hard disk. In block mode, the block volume is used directly as the raw block device to the virtual machine.

[0004] StorageClass defines the properties and behaviors required by a PersistentVolumeClaim. It allows administrators to define a set of storage volume templates so that persistent volumes can be created dynamically based on requests for persistent volume claims. A PersistentVolume is the actual storage resource, and a PersistentVolumeClaim is a request for a PersistentVolume. Different storage classes can correspond to different storage providers, and different providers provide different storage mechanisms at the bottom layer.

[0005] In actual application scenarios, the use of virtual machines needs to consider switching storage classes to meet performance, capacity or cost requirements. Cloning through storage classes will cause the storage space in thin mode to be fully occupied after the storage volume is cloned, which will affect the storage efficiency and cause a large amount of storage space waste. Summary of the invention

[0006] The technical problem to be solved by the present invention is to provide a method and device for migrating virtual machines across storage classes in view of the deficiencies in the prior art, thereby solving the problems existing in the prior art in migrating virtual machines across storage classes and saving storage space.

[0007] The present invention discloses a method for migrating a virtual machine across storage classes. The method comprises: mounting an original PVC of the virtual machine into a conversion container to export an image, converting and compressing the image to generate a minimum image, and importing the minimum image into a target PVC to replace the original PVC of the virtual machine to achieve migration across storage classes.

[0008] Preferably, the method specifically comprises:

[0009] Obtain the original PVC list, obtain the PVC resource configuration according to the original PVC list, then generate a new PVC resource configuration according to the PVC resource configuration, and create a target PVC through the new PVC resource configuration;

[0010] Create a temporary scrach PVC as a temporary storage space for image conversion;

[0011] Create a temporary conversion container, and mount the scrach PVC, the original PVC, and the target PVC into the conversion container;

[0012] Export and compress the original PVC of the virtual machine in the conversion container through the virt-sparsify tool to obtain a minimum image;

[0013] Import the minimum image into the target PVC path through the qemu-img tool;

[0014] Replace the name of the PVC mounted on the virtual machine with the target PVC name.

[0015] Preferably, after the target PVC is generated, it is checked whether the state of the target PVC is normal, and if normal, the step of creating a temporary scrach PVC is performed.

[0016] Preferably, the size of the generated target PVC is the same as the size of the original PVC, and the name of the target PVC is the name of the original PVC plus a timestamp suffix.

[0017] Preferably, the size of the scrach PVC is at least the sum of the sizes of all the original PVCs.

[0018] Preferably, for the original PVC and the target PVC to be mounted in a conversion container:

[0019] If the original PVC is in block mode, the original PVC and the target PVC are mounted as block devices in the conversion container through volumeDevices;

[0020] If the original PVC is in filesystem mode, the original PVC and the target PVC are mounted to the directory path in the conversion container by means of volumeMounts.

[0021] Preferably, when executing this method, the virtual machine is first shut down, and then an instruction to create a virtual machine cross-storage class migration CRD resource object is sent. When the cross-storage class migration controller receives the instruction, it checks whether the virtual machine resource configuration meets the requirements of the virtual machine cross-storage class migration CRD resource object; if so, save the current virtual machine resource configuration and obtain the original PVC list by parsing the virtual machine resource configuration.

[0022] Preferably, after replacing the PVC name mounted on the virtual machine with the target PVC name, the virtual machine is started. If the virtual machine is abnormally started, the virtual machine resource configuration is used to roll back the virtual machine specifications, and the PVC name mounted on the virtual machine is replaced with the original PVC name.

[0023] Preferably, after the minimal image is imported into the target PVC path, the conversion container is deleted and the scrach PVC is released.

[0024] A device for migrating a virtual machine across storage classes includes a virtual machine and a mirror conversion compression module. The mirror conversion compression module applies the method described above to migrate an original PVC in the virtual machine across storage classes to generate a target PVC.

[0025] Beneficial Effects

[0026] The advantages of the present invention are: by mounting the virtual machine storage volume into the conversion container to export the image, and then generating a minimum image through the image conversion and compression mechanism, the minimum image is imported into the target storage volume to replace the original storage volume of the virtual machine to achieve cross-storage class migration, compatible with different storage class providers, compatible with filesystem and block mode storage volumes, optimize storage space, and ensure data integrity during the migration process. BRIEF DESCRIPTION OF THE DRAWINGS

[0027] Figure 1 A schematic diagram of the method flow of virtual machine cross-storage class migration of the present invention;

[0028] Figure 2 A schematic diagram of a PVC mounting process of a method for migrating a virtual machine across storage classes according to the present invention;

[0029] Figure 3 A schematic diagram of the modular structure of the device for migrating virtual machines across storage classes of the present invention. DETAILED DESCRIPTION

[0030] The present invention will be further described below in conjunction with the embodiments, but it does not constitute any limitation to the present invention. Any limited number of modifications made by anyone within the scope of the claims of the present invention are still within the scope of the claims of the present invention.

[0031] See also Figure 1-Figure 2 The present invention provides a method for migrating a virtual machine across storage classes. The storage volume (i.e., the original PVC) of the virtual machine is mounted into a conversion container to export an image. Then, the image is converted and compressed to generate a minimum image. After the minimum image is imported into a target PVC, the original PVC of the virtual machine is replaced to realize the migration across storage classes. Specifically, the following steps are included:

[0032] The first step is to shut down the virtual machine.

[0033] Step 2: Call the API interface to send an instruction to create a virtual machine cross-storage class migration CRD resource object, including: virtual machine name, namespace, and new storage class name.

[0034] Step 3: After receiving the instruction, the cross-storage class migration controller executes step 4.

[0035] Step 4: Check the virtual machine resource configuration, including whether the virtual machine exists, whether it has been shut down, whether the new storage class name is consistent with the old storage class, and whether the new storage class exists.

[0036] Step 5. Save the current virtual machine resource configuration.

[0037] Step 6. Parse the virtual machine resource configuration in step 5, obtain the original PVC list, and generate a new PVC resource configuration based on the PVC resource configuration. Then, create a new PVC, the target PVC, through the new PVC resource configuration, and check whether the target PVC status is normal.

[0038] Step 7. In step 6, the target PVC has the same size as the original PVC, but its name uses the old PVC name plus a timestamp suffix to ensure the consistency of the two PVCs and to facilitate the distinction between the old and new PVCs. The storage class uses the new storage class name passed in by the interface.

[0039] Step 8. Create a temporary scrach PVC as a temporary storage space for image conversion. The size of the scrach PVC should be at least the sum of the sizes of all original PVCs. The storage class of the scrach PVC can use the default storage class or the target storage class.

[0040] Step 9. Create a temporary conversion container and mount the scrach PVC, the original PVC, and the target PVC into the conversion container. The conversion container has the image conversion tool installed and the privileged mode enabled.

[0041] The scratch PVC is mounted to the / scratch directory path in the conversion container through volumeMounts.

[0042] If the original PVC is in block mode, the original PVC and the target PVC are mounted as block devices in the conversion container through volumeDevices, mounted as / dev / source-pvcname and / dev / source-pvcname respectively.

[0043] / dev / target-pvcname.

[0044] For the original PVC in block mode, use the virt-sparsify tool to export and compress the virtual machine's storage volume image to obtain the smallest image. Specifically, the process of the virt-sparsify tool to export and compress the virtual machine's storage volume image is as follows:

[0045] virt-sparsify--compress--convert qcow2--format raw

[0046] / dev / source-pvcname / scratch / scratch-pvcname.qcow2.

[0047] For the original PVC in block mode, use the qemu-img tool to import the exported minimal image into the target PVC path:

[0048] qemu-img convert-t none-O raw-f qcow2

[0049] / scratch / scratch-pvcname.qcow2 / dev / target-pvcname.

[0050] If the original PVC is in filesystem mode, both the original PVC and the target PVC are mounted to the directory path in the conversion container through volumeMounts, mounted as / source-pvcname and / target-pvcname respectively.

[0051] / target-pvcname.

[0052] For the original PVC in filesystem mode, use the virt-sparsify tool to export and compress the image of the virtual machine's storage volume to obtain the minimum image. Specifically, the process of the virt-sparsify tool to export and compress the image of the virtual machine's storage volume is as follows:

[0053] virt-sparsify--compress--convert qcow2--format raw

[0054] / source-pvcname / disk.img / scratch / scratch-pvcname.qcow2.

[0055] For the original PVC in filesystem mode, use the qemu-img tool to import the exported minimal image into the target PVC / target-pvcname path:

[0056] qemu-img convert-t none-O raw-f qcow2

[0057] / scratch / scratch-pvcname.qcow2 / target-pvcname / disk.img.

[0058] Step 10. Delete the temporary container, that is, convert the container; at the same time, release the scrach PVC.

[0059] Step 11. According to the current virtual machine resource configuration saved in step 5, use patch to modify the virtual machine specifications and replace the PVC name mounted on the virtual machine with the new PVC name.

[0060] Step 12. Turn on the virtual machine and check whether it starts normally.

[0061] Step 13. If the virtual machine starts abnormally, use the virtual machine resource configuration in step 4 to roll back the virtual machine specifications and replace the PVC name mounted on the virtual machine with the old PVC name, that is, the original PVC name.

[0062] like Figure 3 As shown, a device for virtual machine cross-storage class migration of the present invention includes a virtual machine and a mirror conversion compression module. The mirror conversion compression module applies the method described above to realize the migration of the original PVC in the virtual machine across storage classes to generate a target PVC.

[0063] The above is only a preferred embodiment of the present invention. It should be pointed out that for those skilled in the art, several modifications and improvements can be made without departing from the structure of the present invention, which will not affect the effect of the implementation of the present invention and the practicality of the patent.

Claims

1. A method for migrating a virtual machine across storage classes, characterized in that: The method comprises: mounting the original PVC of the virtual machine into the conversion container to export the image, converting and compressing the image to generate a minimum image, importing the minimum image into the target PVC and replacing the original PVC of the virtual machine to realize cross-storage class migration.

2. A method for migrating a virtual machine across storage classes according to claim 1, characterized in that: The method specifically includes: Obtain the original PVC list, obtain the PVC resource configuration according to the original PVC list, then generate a new PVC resource configuration according to the PVC resource configuration, and create a target PVC through the new PVC resource configuration; Create a temporary scrach PVC as a temporary storage space for image conversion; Create a temporary conversion container, and mount the scrach PVC, the original PVC, and the target PVC into the conversion container; Export and compress the original PVC of the virtual machine in the conversion container through the virt-sparsify tool to obtain a minimum image; Import the minimum image into the target PVC path through the qemu-img tool; Replace the name of the PVC mounted on the virtual machine with the target PVC name.

3. A method for migrating a virtual machine across storage classes according to claim 2, characterized in that: After the target PVC is generated, check whether the target PVC is in a normal state. If it is normal, perform the step of creating a temporary scrach PVC.

4. The method for migrating a virtual machine across storage classes according to claim 2, characterized in that: The size of the generated target PVC is the same as that of the original PVC, and the name of the target PVC is the name of the original PVC plus a timestamp suffix.

5. The method for migrating a virtual machine across storage classes according to claim 2, characterized in that: The size of the scrachPVC is at least the sum of the sizes of all the original PVCs.

6. A method for migrating a virtual machine across storage classes according to claim 2, characterized in that: For the source PVC and the target PVC mounted into the conversion container: If the original PVC is in block mode, the original PVC and the target PVC are mounted as block devices in the conversion container through volumeDevices; If the original PVC is in filesystem mode, the original PVC and the target PVC are mounted to the directory path in the conversion container by means of volumeMounts.

7. The method for migrating a virtual machine across storage classes according to claim 1, characterized in that: When executing this method, the virtual machine is first shut down, and then an instruction to create a virtual machine cross-storage class migration CRD resource object is sent. After the cross-storage class migration controller receives the instruction, it checks whether the virtual machine resource configuration meets the virtual machine cross-storage class migration CRD resource object requirements; if so, save the current virtual machine resource configuration and obtain the original PVC list by parsing the virtual machine resource configuration.

8. The method for migrating a virtual machine across storage classes according to claim 7, characterized in that: After replacing the PVC name mounted on the virtual machine with the target PVC name, the virtual machine is started. If the virtual machine is abnormally started, the virtual machine specification is rolled back using the virtual machine resource configuration, and the PVC name mounted on the virtual machine is replaced with the original PVC name.

9. The method for migrating a virtual machine across storage classes according to claim 2, characterized in that: After the minimal image is imported into the target PVC path, the conversion container is deleted and the scrach PVC is released.

10. A device for migrating a virtual machine across storage classes, characterized in that: It comprises a virtual machine and a mirror conversion compression module, wherein the mirror conversion compression module applies the method according to any one of claims 1 to 9 to realize the migration of the original PVC in the virtual machine across storage classes to generate a target PVC.