Mirror image creating method and device based on virtual machine running in container and disk configuration device

By deploying Kubevirt and CDI in Kubernetes cluster, creating vmimage CRD resource types and controllers, and using snapshots to quickly create pvcs, solving the problems of long import time for virtual machine images and high configuration error rates, realizing rapid creation and ease of use of virtual machine machines promote.

CN119045946APending Publication Date: 2024-11-29CHINA-ASEAN INFORMATION PORT CO LTD
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202411065329.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-08-05
Publication Date
2024-11-29

AI Technical Summary

Technical Problem

When creating virtual machines, the existing technology has a long mirror import time, a high configuration error rate, and users need to have a high learning threshold, which reduces the ease of use of virtual machine creation.

Method used

Deploy Kubevirt and CDI in Kubernetes cluster, create vmimage CRD resource types and controllers, quickly create pvcs through snapshots, realize quick import of mirror files and rapid creation of virtual machines, and combine Cloud-Init templates to inject user information to simplify virtual machine configuration.

Benefits of technology

Improves the efficiency of virtual machine creation, reduces the error rate, improves the user experience, and simplifies the virtual machine creation process.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119045946A_ABST
    Figure CN119045946A_ABST
Patent Text Reader

Abstract

The invention discloses a mirror image creating method based on a virtual machine running in a container, and relates to a cloud computing virtual machine, a Kubernetes cluster is deployed, and Kubevirt and CDI are deployed on the Kubernetes cluster; a CRD resource type of a vmimage is created in the Kubernetes cluster, and a Controller of the CRD resource type is deployed; on the basis of the CRD resource type, a user-defined resource object instance is created in the Kubernetes cluster, and user-defined field information in the user-defined resource object instance is edited; and when the controller detects that the CRD resource type of the vmimage is changed, executing a mode of quickly creating a pvc through a snapshot according to the custom field information to quickly create the virtual machine. The invention further discloses a mirror image creating device based on the virtual machine running in the container and a disk configuration device. According to the invention, the virtual machine conforming to the mirror image expectation is created according to the mirror image specification, and the new virtual machine disk is created in a snapshot quick recovery mode, so that the virtual machine creation efficiency is improved, the error rate is reduced, and the user experience is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to a cloud computing virtual machine, and more specifically, to an image creation method and device based on running a virtual machine in a container, and a disk configuration device. Background Art

[0002] Kubernetes is a portable, extensible, open source platform for managing containerized workloads and services. Kubevirt is based on Kubernetes's CRD (custom resource) and adds management of virtual machine resource types.

[0003] kubevirt provides multiple ways of virtual machine disks, but if data persistence is required, that is, the data still exists after the virtual machine is restarted or rebuilt, you need to use the persistentVolumeClaim (pvc) persistent storage volume method. To use pvc as a virtual machine image disk, you need to import the virtual machine image into pvc. Use block volume directly as a raw block device to provide it to the virtual machine as a virtual machine disk. If the image is large, importing the image will be slow. The larger the image, the longer the import time, which reduces the experience of quickly creating a virtual machine.

[0004] In order to correctly create a virtual machine, users need to select the correct system image, and after importing the pvc, set the correct virtual machine specification configuration, such as CPU, memory, disk size, system reserved memory, etc. If the configuration is wrong, it is very likely that the virtual machine will not be able to start. In order to set the initial user password and network settings for the virtual machine, the kubevirt virtual machine needs to be injected through Cloud-Init and other methods. Cloud-Init is a tool for automating the initial settings of virtual machines (such as configuring host names, network interfaces, and authorization keys). Users need a certain learning threshold to use it, which greatly reduces the ease of creating virtual machines. Summary of the invention

[0005] The technical problem to be solved by the present invention is to provide a method and device for creating an image based on running a virtual machine in a container, and a disk configuration device, in view of the deficiencies in the prior art, thereby improving the efficiency of virtual machine creation and reducing the error rate.

[0006] The present invention provides a method for creating an image based on running a virtual machine in a container, the method comprising:

[0007] Deploy a Kubernetes cluster, and deploy Kubevirt and CDI on the Kubernetes cluster;

[0008] Create a CRD resource type of vmimage in the Kubernetes cluster and deploy a Controller of the CRD resource type;

[0009] Based on the CRD resource type, create a custom resource object instance in the Kubernetes cluster, and edit the custom field information therein;

[0010] When the Controller detects that the CRD resource type of the vmimage has changed, the Controller quickly creates a virtual machine by quickly creating a pvc through a snapshot according to the custom field information.

[0011] Furthermore, the custom field information includes upload type, image volume data source, image specification, storage class name, image format, operating system type, disk volume size, disk device type, Cloud-Init template and image status information.

[0012] Furthermore, the upload type includes a URL method and a local upload method; the local upload method requires uploading the image file to a proxy server, and after the upload is completed, the proxy server provides a URL file service interface.

[0013] Furthermore, the method of quickly creating a virtual machine by quickly creating a pvc through a snapshot specifically includes:

[0014] When uploading the image file, the Controller updates the progress in the custom field information according to the upload progress, calculates the image size of the image file and updates the image size field in the custom field information;

[0015] After the image file is uploaded, the image file is imported into the pvc by importing the URL image through the CDI, and during the import process, the Controller updates the progress in the custom field information according to the import progress;

[0016] When the import is complete, the updated custom field information is set in the snapshot, and a snapshot of the pvc is created;

[0017] When the snapshot is created, the mirror volume data source of the vmimage is updated to the snapshot information; and the pvc is restored by volume snapshot recovery according to the snapshot information to generate a new pvc.

[0018] Furthermore, when the snapshot is created, the intermediate products generated during the snapshot creation process are cleaned up.

[0019] Furthermore, when the Controller detects that an object in the vmimage is deleted, the corresponding pvc and its snapshot are deleted in association.

[0020] Furthermore, if the type of the image file is a url type, the Controller is skipped from updating the progress in the custom field information according to the upload progress, calculating the image size of the image file and updating the image size field in the custom field information.

[0021] A device applying the image creation method based on running a virtual machine in a container is characterized by comprising:

[0022] An upload module, used to receive an image file uploaded by a user, and to implement the image file upload process by applying the image creation method;

[0023] An import module, used to apply the image creation method to import the image file into the pvc of the virtual machine;

[0024] The monitoring module is used to apply the mirror image creation method to realize the generation of a new pvc.

[0025] A disk configuration device, characterized by comprising:

[0026] A disk volume configuration module is used to generate a PVC resource configuration and create a PVC; a new disk volume configuration is generated by using the disk volume size, storage class name, and image volume data source of the new PVC generated by the image creation method based on running a virtual machine in a container;

[0027] The webhook verification module is used to verify whether the new disk volume configuration meets the minimum requirements based on the virtual machine's image specifications; if not, the virtual machine creation fails;

[0028] The Cloud-Init injection module is used to enter the user information submitted by the user into the Cloud-Init configuration by placeholder replacement, and inject the user information into the new disk volume configuration through the Cloud-Init template.

[0029] As a further improvement, the user information includes user password, IP, network segment, and DNS information.

[0030] Beneficial Effects

[0031] The advantages of the present invention are: a virtual machine is quickly created by quickly creating a PVC through a snapshot, thereby improving the efficiency of virtual machine creation, reducing the error rate, and improving the user experience. BRIEF DESCRIPTION OF THE DRAWINGS

[0032] Figure 1This is a schematic diagram of the image creation method of the present invention;

[0033] Figure 2 It is a schematic diagram of the modular structure of the image creation device of the present invention;

[0034] Figure 3 It is a schematic diagram of the modular structure of the disk configuration device of the present invention. DETAILED DESCRIPTION

[0035] 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.

[0036] See also Figure 1 The present invention provides a method for creating an image based on running a virtual machine in a container, the method comprising the following steps:

[0037] The first step is to deploy a Kubernetes cluster, and deploy Kubevirt and CDI on the Kubernetes cluster. CDI is a containerized data importer.

[0038] Step 2: Create a CRD resource type of vmimage in the Kubernetes cluster. The status information of vmimage is: initialization status, and the progress is 0. Deploy the Controller of the CRD resource type.

[0039] Step 3: Based on the CRD resource type, create a custom resource object instance in the Kubernetes cluster and edit the custom field information. Custom field information includes upload type, image volume data source, image specification, storage class name, image format, operating system type, disk volume size, disk device type, Cloud-Init template, and image status information. Image specifications include minimum CPU, memory, and system reserved memory size. Cloud-Init template is a JSON string used to set cloud-init configuration. Fields of administrator user and network configuration information such as IP, network segment, DNS, etc. can be represented by placeholders. Image status information includes image progress, image status, description information, and image file size. The image progress includes upload progress and import progress; the image status includes initialization, uploading, importing, snapshot generation, success, failure, etc. Upload types include URL method and local upload method. The local upload method requires uploading the image file to the proxy server, and the proxy server provides a URL file service interface after the upload is completed.

[0040] The following is a vmimage CRD custom field initialization configuration:

[0041] dataSource:{}

[0042] cloudInit:{}

[0043] diskBus:virtio

[0044] diskSize:10

[0045] displayName:centos7

[0046] imageType:raw_qcow2

[0047] osType:windows

[0048] sourceType:download

[0049] storageClassName:ceph

[0050] url:http: / / localhost:8000 / centos7.qcow2

[0051] flavor:

[0052] cpu:1

[0053] displayName:flavor-default

[0054] memory:1

[0055] reservedMemory:250

[0056] status:

[0057] message:

[0058] phase:Initialized

[0059] progress:0

[0060] size:0

[0061] After the virtual machine is created, during the process of uploading the image file to the virtual machine, when the Controller detects that the CRD resource type of vmimage has changed, the corresponding processing flow is executed according to the information of the expected state attribute of the CRD resource type customized by vmimage. Specifically, when uploading the image file, the Controller updates the progress in the custom field information according to the upload progress, calculates the image size of the image file and updates the image size field in the custom field information. After the image file is uploaded, the image file is imported into the pvc by importing the URL image through CDI, and during the import process, the Controller updates the progress in the custom field information according to the import progress. When the import is completed, the updated custom field information is set to the snapshot, and a snapshot of the pvc is created. When the snapshot is created, the intermediate product needs to be cleaned up, and then the image volume data source of the vmimage is updated to the snapshot information. According to the snapshot information, the pvc is restored by volume snapshot recovery to generate a new pvc.

[0062] If there is an exception during the image creation process, the Controller will update the image status to failure. When the Controller detects the deletion of an object in the vmimage, the corresponding pvc and its snapshot will be deleted.

[0063] During the upload process, if the image file type is URL type, the Controller will skip updating the progress in the custom field information according to the upload progress, calculating the image size of the image file and updating the image size field in the custom field information.

[0064] like Figure 2 As shown, a device applying the above-mentioned image creation method based on running a virtual machine in a container includes:

[0065] The upload module is used to receive the image file uploaded by the user and implement the image file upload process by applying the image creation method. Specifically, the upload module receives the image file uploaded by the user and uploads the file to the proxy service through the file stream. During the upload process, the Controller updates the progress in the image status according to the upload progress. At this time, the image status is uploading; calculate the image size and update the image size field in the image status. If the upload type is url type, skip this step.

[0066] The import module is used to apply the image creation method to import the image file into the pvc of the virtual machine. Specifically, the import module imports the image file into the pvc by importing the URL image through CDI. During the import process, the Controller updates the progress in the image status according to the import progress. At this time, the image status is importing.

[0067] The monitoring module is used to apply the image creation method to realize the generation of a new pvc. Specifically, the monitoring module keeps monitoring the progress of the import module. When the import is completed, the image state is set to snapshot, and a snapshot of the image volume pvc is created. When the snapshot is created, the intermediate product is cleaned up, and the vmimage state is updated to success. At this time, the image volume data source of the vmimage is updated to the snapshot information. When the virtual machine disk volume is created, a new pvc is generated by volume snapshot recovery based on the image volume data source information.

[0068] A new virtual machine can be quickly created and started by restoring the snapshot. After starting the virtual machine, the user can log in to the virtual machine using the user password or connect to the virtual machine via IP.

[0069] like Figure 3 As shown, a disk configuration device comprises:

[0070] The disk volume configuration module is used to generate PVC resource configuration and create PVC. The new disk volume configuration is generated by the disk volume size, storage class name, and image volume data source of the new PVC generated based on the image creation method of the virtual machine running in the container. Users can set up the virtual machine according to the default configuration in the basic information of the image, such as: CPU, memory, virtual machine reserved memory, disk device type, etc. These items can be set to default to reduce user input.

[0071] The webhook verification module is used to verify whether the new disk volume configuration meets the minimum requirements based on the virtual machine's image specifications; if not, the virtual machine creation fails.

[0072] The Cloud-Init injection module is used to enter the user information submitted by the user into the Cloud-Init configuration by replacing the placeholder, and inject the user information into the new disk volume configuration through the Cloud-Init template. The user information includes the user password, IP, network segment, and DNS information.

[0073] The following is an example of a generic Cloud-Init template:

[0074] cloudInit:

[0075] networkData:|-

[0076] version:2

[0077] ethernets:

[0078] eth0:

[0079] dhcp4:no

[0080] addresses:[{{cidrIP}}]

[0081] gateway4:{{gateway}}

[0082] nameservers:

[0083] addresses:[{{dnsServer}}]

[0084] match:

[0085] name:e*

[0086] userData:|-

[0087] #cloud-config

[0088] package_update:true

[0089] packages:

[0090] -qemu-guest-agent

[0091]

[0092] In this disk configuration device, the user password, IP, network segment, and DNS information are injected through the Cloud-Init injection module, and the created virtual machine is verified through the webhook module, which will be able to complete rapid creation and startup, greatly improving the creation efficiency, reducing the creation failure rate, and improving the user experience.

[0093] 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 creating an image based on a virtual machine running in a container, characterized in that: The method includes: Deploy a Kubernetes cluster, and deploy Kubevirt and CDI on the Kubernetes cluster; Create a CRD resource type of vmimage in the Kubernetes cluster and deploy a Controller of the CRD resource type; Based on the CRD resource type, create a custom resource object instance in the Kubernetes cluster, and edit the custom field information therein; When the Controller detects that the CRD resource type of the vmimage has changed, the Controller quickly creates a virtual machine by quickly creating a pvc through a snapshot according to the custom field information.

2. According to claim 1, a method for creating an image based on running a virtual machine in a container is characterized in that: The custom field information includes upload type, image volume data source, image specification, storage class name, image format, operating system type, disk volume size, disk device type, Cloud-Init template and image status information.

3. A method for creating an image based on running a virtual machine in a container according to claim 2, characterized in that: The upload types include URL mode and local upload mode; the local upload mode requires uploading the image file to the proxy server, and after the upload is completed, the proxy server provides a URL file service interface.

4. The method for creating an image based on running a virtual machine in a container according to claim 1, characterized in that: The method of quickly creating a virtual machine by quickly creating a pvc through a snapshot specifically includes: When uploading the image file, the Controller updates the progress in the custom field information according to the upload progress, calculates the image size of the image file and updates the image size field in the custom field information; After the image file is uploaded, the image file is imported into the pvc by importing the URL image through the CDI, and during the import process, the Controller updates the progress in the custom field information according to the import progress; When the import is complete, the updated custom field information is set in the snapshot, and a snapshot of the pvc is created; When the snapshot is created, the mirror volume data source of the vmimage is updated to the snapshot information; and the pvc is restored by volume snapshot recovery according to the snapshot information to generate a new pvc.

5. A method for creating an image based on running a virtual machine in a container according to claim 4, characterized in that: After the snapshot is created, clean up the intermediate products generated during the snapshot creation process.

6. A method for creating an image based on running a virtual machine in a container according to claim 4, characterized in that: When the Controller detects that an object in the vmimage is deleted, the corresponding pvc and its snapshot are deleted in association.

7. A method for creating an image based on running a virtual machine in a container according to claim 6, characterized in that: If the type of the image file is a url type, the controller is skipped from updating the progress in the custom field information according to the upload progress, calculating the image size of the image file and updating the image size field in the custom field information.

8. A device using the method for creating an image based on running a virtual machine in a container as described in any one of claims 1 to 7, characterized in that: include: An upload module, used to receive an image file uploaded by a user, and to implement the image file upload process by applying the image creation method; An import module, used to apply the image creation method to import the image file into the pvc of the virtual machine; The monitoring module is used to apply the mirror image creation method to realize the generation of a new pvc.

9. A disk configuration device, characterized in that: include: Disk volume configuration module, used to generate PVC resource configuration and create PVC; Generate a new disk volume configuration by using the disk volume size, storage class name, and image volume data source of a new PVC generated by the image creation method based on running a virtual machine in a container as described in any one of claims 1 to 7; The webhook verification module is used to verify whether the new disk volume configuration meets the minimum requirements based on the virtual machine's image specifications; if not, the virtual machine creation fails; The Cloud-Init injection module is used to enter the user information submitted by the user into the Cloud-Init configuration by placeholder replacement, and inject the user information into the new disk volume configuration through the Cloud-Init template.

10. The disk configuration device according to claim 9, characterized in that: The user information includes user password, IP, network segment, and DNS information.

Citation Information

Cited By

  • Kubernetes (K8S) custom resource definition (CRD)-based network function (NF) management

    WO2026164689A1