A method and apparatus for packaging a container into an image
By using the container controller and visualization platform in a Kubernetes cluster, users can quickly locate and save containers as images on the interface, solving the problems of complex image creation and difficult operation in traditional image creation, and realizing a simplified image processing workflow.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-12-15
- Publication Date
- 2026-03-20
AI Technical Summary
In the process of containerizing traditional applications, the orchestration and creation of images are complex and cumbersome. Especially in Kubernetes clusters, where operation permissions are restricted, it is difficult to frequently debug and save images, and errors are prone to occur.
This paper provides a method for packaging containers into images. Through the container controller and visualization platform in the Kubernetes cluster, the user locates the target container in the container visualization list interface provided by the platform, obtains parameter information through the kube-apiserver gateway, generates an image packaging object, and the container controller packages the image on the node and pushes it to the target image repository.
It enables simple and easy-to-use image processing in Kubernetes clusters. Users can quickly find the target container and save it as an image through a visual interface, simplifying the image creation process and reducing operational complexity and error rate.
Smart Images

Figure CN115857970B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of computer, in particular to a method and device for packing container into image. BACKGROUND
[0002] In the prior art, due to the characteristics of the container, compared with the traditional deployment, the container deployment has obvious advantages in simplifying the configuration, code pipeline management, development efficiency, isolating applications, multi-tenant environment and rapid deployment, etc., so that the container technology and the corresponding container orchestration kubernetes are more and more widely used. However, in the process of converting traditional applications to containers, the image arrangement and production process is still relatively complex and difficult. Taking the docker container runtime as an example, there are generally two ways to produce docker images: writing a file Dockerfile used to build the image or modifying the runtime container and then saving it. In the process of converting traditional applications to containers, writing Dockerfile often cannot be done in one step, and it is often necessary to fine-tune and modify the application in the running container, and finally save the image through docker commit. This requires operation in a separate machine container environment, which is not easy to operate in a real environment (for example, it is often deployed in a kubernetes cluster, and the machine node has permission control and cannot be operated at will), and frequent debugging and saving makes the image production very tedious and prone to errors.
[0003] In the runtime container, some modifications can be made to the original image, and many times the modifications made need to be saved and encapsulated into a new image. In a single container (for example, taking the docker runtime as an example), the container can be simply encapsulated into a new image using the command tool: docker commit command, but in the kubernetes cluster, facing many kubernetes nodes and a large number of container expansion or enhancement type container pods and various restrictions on machine operation permissions, it becomes difficult to save the runtime container as an image. SUMMARY
[0004] An object of the present application is to provide a method and device for packing container into image, which optimizes the image processing of the container, and users can easily find the target container corresponding to the target application pod in the container visualization list interface provided by the platform, and only need to perform the save image operation in the operation menu, so that the runtime container can be saved as an image and pushed to the target image repository specified by the user.
[0005] According to one aspect of the present application, a method for packing container into image is provided, which is applied to a kubernetes cluster, and the method comprises:
[0006] The kubernetes cluster comprises at least two kubernetes nodes, and a container controller container-controller for listening to container image packaging object resources in the cluster is deployed on each kubernetes node.
[0007] When a user accesses a platform corresponding to the kubernetes cluster, a target container to be packaged is determined through a container visual list interface provided by the platform, and parameter information of the target container is obtained by accessing a kube-apiserver gateway, wherein the parameter information comprises an identifier of the target container, a node to which the target container belongs, and a target image repository to be pushed.
[0008] The kube-apiserver gateway creates an image packaging object of the target container according to the parameter information.
[0009] When a container-controller on a target kubernetes node listens to the image packaging object as a self-node task of the target kubernetes node, the container-controller on the target kubernetes node generates a new image after performing image packaging on the target container, and pushes the new image to the target image repository.
[0010] Further, in the above method, when the user accesses the platform corresponding to the kubernetes cluster, the target container to be packaged is determined through the container visual list interface provided by the platform, and the parameter information of the target container is obtained by accessing the kube-apiserver gateway, comprising:
[0011] When the user accesses the platform corresponding to the kubernetes cluster, in response to a query operation performed by the user on the container visual list interface provided by the platform, a target container to be packaged is found and determined.
[0012] The platform accesses the kube-apiserver gateway through a software development kit SDK of kubernetes, and obtains the parameter information of the target container.
[0013] Further, in the above method, the method further comprises:
[0014] The container-controller on each kubernetes node listens to container image packaging object resources in the kubernetes cluster in real time.
[0015] If a container-controller on a target kubernetes node detects that the image packaging object exists in the kubernetes cluster, the parameter information carried by the image packaging object is used to determine whether the image packaging object is a self-node task of the target kubernetes node,
[0016] If not, the node task corresponding to the image packaging object is discarded.
[0017] Further, in the above method, when the container-controller on the target kubernetes node detects that the image packaging object is a self-node task of the target kubernetes node, the container-controller on the target kubernetes node generates a new image corresponding to the target container after packaging the target container, and pushes the new image to the target image repository, including:
[0018] When the container-controller on the target kubernetes node detects that the image packaging object is a self-node task of the target kubernetes node, the container-controller calls the software development kit of the container to find the target container on the target kubernetes node, and packages the target container;
[0019] After completing the packaging of the target container, a new image corresponding to the target container is generated, and the new image is pushed to the target image repository.
[0020] Further, in the above method, the method further includes:
[0021] In response to the access operation of the user on the repository interface provided by the platform, the new image corresponding to the target container is visually displayed to the user on the repository interface.
[0022] According to another aspect of the present application, a non-volatile storage medium is also provided, which stores computer readable instructions, and the computer readable instructions can be executed by a processor to enable the processor to implement the method of container packaging into an image.
[0023] According to another aspect of the present application, an apparatus for container packaging into an image is also provided, wherein the apparatus includes:
[0024] one or more processors;
[0025] A computer readable medium for storing one or more computer readable instructions,
[0026] When the one or more computer readable instructions are executed by the one or more processors, the one or more processors implement the method of packaging a container into an image as described above.
[0027] Compared with the prior art, the method and device for packaging a container into an image provided by the application are applied to a kubernetes cluster, the kubernetes cluster includes at least two kubernetes nodes, and each kubernetes node is deployed with a container controller container-controller for listening to a container image packaging object resource in the cluster; when a user accesses a platform corresponding to the kubernetes cluster, a target container to be packaged is determined through a container visual list interface provided by the platform, and parameter information of the target container is obtained by accessing a kube-apiserver gateway, the parameter information includes an identifier of the target container, a node to which the target container belongs, and a target image warehouse to be pushed; the kube-apiserver gateway creates an image packaging object of the target container according to the parameter information; when the container-controller on a target kubernetes node listens to the image packaging object as a self node task of the target kubernetes node, the container-controller on the target kubernetes node generates a new image corresponding to the target container after performing image packaging on the target container, and pushes the new image to the target image warehouse. When the container is processed into an image, simple and easy-to-operate optimization is achieved, the user can easily find a target container corresponding to a pod of a target application in a container visual list interface provided by the platform, only needs to perform a save image operation in an operation menu, and a container at runtime can be saved as an image and pushed to a target image warehouse specified by the user. BRIEF DESCRIPTION OF DRAWINGS
[0028] Other features, objects, and advantages of the application will become more apparent from the following detailed description of non-limiting embodiments, read in conjunction with the accompanying drawings:
[0029] Figure 1 A flowchart of a method for packaging a container into an image according to an aspect of the application is shown;
[0030] Figure 2 A framework diagram of a method for packaging a container into an image according to an aspect of the application in an actual application scenario is shown;
[0031] The same or similar reference numerals in the drawings denote the same or similar components. DETAILED DESCRIPTION
[0032] The application will be further described below in conjunction with the accompanying drawings.
[0033] In one typical configuration of the present application, the terminal, the device of the service network and the trusted party each comprises one or more processors (CPU), input / output interface, network interface and memory.
[0034] The memory can include non-persistent memory in computer-readable media, random access memory (RAM), and / or non-volatile memory, such as read-only memory (ROM) or flash memory (flash RAM). The memory is an example of computer-readable media.
[0035] Computer-readable media includes permanent and non-permanent, removable and non-removable media that can be implemented by any method or technology for storing information. Information can be computer-readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase-change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disc read-only memory (CD-ROM), digital versatile disc (DVD) or other optical storage, magnetic cassette, magnetic tape disk storage or other magnetic storage device, or any other non-transmission medium that can be used to store information accessible by a computing device. According to the definition herein, computer-readable media does not include non-transitory computer-readable media, such as modulated data signals and carriers.
[0036] In the prior art, the disadvantages of making images by the command tool: docker commit method are obvious. An application often has environment dependencies, such as login services and permission services, so the application is often deployed in the form of microservices in the kubernetes cluster. It is necessary to have node operation permissions when the container of the application is frequently modified and saved, and then it is necessary to find the node where the container is located in the cluster and the pod where the container is located. These series of operations are difficult and tedious.
[0037] In view of the above technical defects, one aspect of the present application proposes a method for packaging a container into an image. The specific flowchart of the method is as follows Figure 1As shown, the method can be implemented in Golang language, or other program languages (such as Java, etc.). The method is applied to a kubernetes cluster, as shown in Figure 2 As shown, the kubernetes cluster includes at least two kubernetes nodes, each of which is deployed with a container controller container-controller for listening to container image packaging object resources in the cluster, each of which includes at least two containers container, and the kubernetes cluster further includes a visual platform for interacting with users and an image repository for storing images corresponding to all containers in the kubernetes cluster. The specific process of the method includes steps S11, S12 and S13, which specifically include the following steps:
[0038] Step S11, when a user accesses the platform corresponding to the kubernetes cluster, determines the target container to be packaged through the container visualization list interface provided by the platform, and obtains the parameter information of the target container by accessing the kube-apiserver gateway, the parameter information including the identification of the target container, the node to which it belongs and the target image repository to be pushed; all containers of the applications deployed in the kubernetes cluster by the user can be displayed in the container visualization list interface, and in the container visualization list interface, the user can find the target container to be packaged and initiate the operation of packaging the image of the target container, which realizes that the target container to be packaged can be quickly located through the container visualization list interface provided by the platform, such as saving the image operation of the target container in the operation menu in the container visualization list interface, so that the target container running at the moment can be saved as an image.
[0039] Step S12, the kube-apiserver gateway creates an image packaging object of the target container according to the parameter information, i.e. a custom resource definition container-crd of the container;
[0040] Step S13, when the container-controller on a target kubernetes node listens to the image packaging object as a self-node task of the target kubernetes node, the container-controller on the target kubernetes node generates a corresponding new image after packaging the image of the target container, and pushes the new image to the target image repository.
[0041] Through the steps S11 to S13, the simple and easy-to-operate optimization is realized when the container is imaged, the user can easily find the target container corresponding to the pod of the target application in the container visualization list interface provided by the platform, and only needs to perform the save image operation in the operation menu, and the container at runtime can be saved as an image and pushed to the target image repository specified by the user.
[0042] In the above embodiment of the present application, when the user accesses the platform corresponding to the kubernetes cluster, the target container to be packaged is determined through the container visualization list interface provided by the platform, and the parameter information of the target container is obtained by accessing the kube-apiserver gateway, specifically including:
[0043] When the user accesses the platform corresponding to the kubernetes cluster, the user wants to initiate the image packaging operation on the target container, and will perform the query operation on the target container in the container visualization list interface provided by the platform, which includes but is not limited to the directional search input or the screening operation of the target container, etc. The platform responds to the query operation performed by the user on the container visualization list interface provided by the platform, finds and determines the target container to be packaged; the platform accesses the kube-apiserver gateway through the software development kit SDK of kubernetes, and obtains the parameter information of the target container, so as to obtain the parameter information of the target container to be packaged through the kube-apiserver gateway.
[0044] In the above embodiment of the present application, the method further includes:
[0045] In the kubernetes cluster, the container-controller on each kubernetes node listens to the container image packaging object resource in the kubernetes cluster in real time: kubernetes resource (that is, whether there is an image packaging object, that is, container-crd);
[0046] If the container-controller on a target kubernetes node of the kubernetes cluster detects the image packaging object in the kubernetes cluster, the parameter information (identification of the target container, belonging node, and target image warehouse to be pushed, etc.) carried by the image packaging object is used to determine whether the image packaging object is a self-node task of the target kubernetes node. If yes, the container-controller on the target kubernetes node generates a new image after packaging the target container, and pushes the new image to the target image warehouse, thereby realizing the task of container image packaging through the container-controller. If no, the target kubernetes node discards the node task corresponding to the image packaging object, and continues to listen to whether there is another image packaging object in the kubernetes cluster, thereby realizing the listening of the image packaging object and the task completion of image packaging through the container-controller on each kubernetes node.
[0047] According to the above embodiment of the present application, when the container-controller on a target kubernetes node detects that the image packaging object is a self-node task of the target kubernetes node, the container-controller on the target kubernetes node generates a new image after packaging the target container, and pushes the new image to the target image warehouse, which includes:
[0048] When the container-controller on a target kubernetes node detects that the image packaging object is a self-node task of the target kubernetes node, the container-controller calls the software development kit of the container, finds the target container on the target kubernetes node, and packages the target container. After completing the image packaging of the target container, a new image is generated and pushed to the target image warehouse, thereby realizing the image packaging of the target container and the pushing to the target image warehouse.
[0049] According to the above embodiment of the present application, the method further includes:
[0050] In response to the user's access operation on the warehouse interface provided by the platform, the new image corresponding to the target container is visualized and displayed to the user on the warehouse interface. For example, the user can access the image warehouse again through the warehouse interface provided by the platform, and can see the new image corresponding to the newly packaged target container, so as to use the new image corresponding to the target container for subsequent service deployment and the like.
[0051] In a specific practical application scenario of the present application, as shown in Figure 2 The method for packaging a container into an image provided by the present application is composed of two components (a platform and a container-controller) and a custom kubernetes resource (container-crd), and relies on the environment of a kubernetes cluster. The specific process includes the following steps:
[0052] 1. The user accesses the platform, and the platform provides a container visualization list interface, which can display all the containers of the applications deployed in the kubernetes cluster by the user. The user can quickly locate and find the target container to be packaged through a query operation, and initiate a packaging image operation on the target container.
[0053] 2. The platform accesses the kube-apiserver gateway through the software development kit (SDK) of the kubernetes, and downloads the parameter information of the target container to be packaged.
[0054] 3. The kube-apiserver creates an image packaging object, i.e. a container-crd, according to the parameter information of the target container. In the present application, the definition of the container-crd, which is a link between the platform and the kubernetes cluster, saves the parameter information of the target container, including but not limited to the identification id of the target container, the node to which the target container belongs, and the target image warehouse to be pushed, and the like.
[0055] 4、Another component in the present application is the container controller container-controller, whose operation mode is daemon set. A container-controller is deployed on each node of the kubernetes cluster. The container-controller on each node listens to the container-crd resource in the kubernetes cluster. Once a target kubernetes node in the kubernetes cluster finds a new image packaging object container-crd, it will enter the processing flow. By analyzing the parameter information carried by the image packaging object container-crd, it is confirmed whether the container-crd is the own node task of the target kubernetes node.
[0056] 5、When the container-controller on the target kubernetes node finds that the container-crd is the own node task of the target kubernetes node, it will call the container software development kit docker sdk, find the target container on the target kubernetes node, and image package the target container to obtain the new image corresponding to the target container.
[0057] 6、After the container-controller on the target kubernetes node completes the image packaging of the target container, it will push the generated new image to the corresponding target image warehouse.
[0058] 7、The user accesses the image warehouse again through the warehouse interface provided by the platform, and can see the packaged new image, which can be used for subsequent service deployment.
[0059] In all embodiments of the present application, the platform provides a visual list interface of the container for the user, so that the target container to be packaged can be quickly located. Through the definition of the image packaging object container-crd, the resource definition is the link between the platform and the kubernetes cluster, and saves the parameter information of the target container, including but not limited to the identification id of the container, the belonging node and the target image warehouse for pushing, etc. A container-controller is deployed in each kubernetes node, which mainly executes the work of container image packaging, so as to realize the container image packaging in the kubernetes cluster environment.
[0060] According to another aspect of the present application, there is also provided a non-transitory storage medium having stored thereon computer readable instructions, which, when executed by a processor, cause the processor to implement the method of packaging a container into an image as described above.
[0061] According to another aspect of the present application, there is also provided an apparatus for packaging a container into an image, wherein the apparatus comprises:
[0062] one or more processors;
[0063] a computer readable medium for storing one or more computer readable instructions,
[0064] when the one or more computer readable instructions are executed by the one or more processors, cause the one or more processors to implement the method of packaging a container into an image as described above.
[0065] Here, the details of each embodiment of the apparatus for packaging a container into an image can be specifically referred to the corresponding part of the embodiment of the method of packaging a container into an image as described above, and here, will not be repeated.
[0066] In summary, the application provides a container packaging into an image method and device, applied to a kubernetes cluster, the kubernetes cluster includes at least two kubernetes nodes, each of the kubernetes nodes is deployed with a container controller container-controller for listening to container image packaging object resources in the cluster; when a user accesses the platform corresponding to the kubernetes cluster, determines the target container to be packaged through the container visual list interface provided by the platform, and obtains the parameter information of the target container by accessing the kube-apiserver gateway, the parameter information includes the identification of the target container, the node to which it belongs, and the target image warehouse to be pushed; the kube-apiserver gateway creates an image packaging object of the target container according to the parameter information; when the container-controller on a target kubernetes node listens to the image packaging object as a self-node task of the target kubernetes node, the container-controller on the target kubernetes node generates a corresponding new image after packaging the target container into an image, and pushes the new image to the target image warehouse. When the container is imaged, simple and easy-to-operate optimization is achieved, the user can easily find the target container corresponding to the pod of the target application in the container visual list interface provided by the platform, and only needs to save the image operation in the operation menu, the container at runtime can be saved as an image, and pushed to the target image warehouse specified by the user.
[0067] It should be noted that the present application can be implemented in software and / or a combination of software and hardware, for example, can be implemented by using an application specific integrated circuit (ASIC), a general purpose computer or any other similar hardware device. In one embodiment, the software program of the present application can be executed by a processor to implement the steps or functions described above. Similarly, the software program of the present application (including related data structures) can be stored in a computer readable recording medium, such as a RAM memory, a magnetic or optical drive or a soft disk and the like. In addition, some steps or functions of the present application can be implemented by hardware, for example, as a circuit cooperating with the processor to perform the respective steps or functions.
[0068] In addition, part of the present application can be applied as a computer program product, for example, computer program instructions, when executed by a computer, through the operation of the computer, the method and / or technical solutions according to the present application can be invoked or provided. The program instructions invoking the method of the present application can be stored in a fixed or removable recording medium, and / or transmitted through a data stream in a broadcast or other signal bearing medium, and / or stored in the working memory of the computer device running according to the program instructions. Here, according to an embodiment of the present application includes an apparatus comprising a memory for storing computer program instructions and a processor for executing program instructions, wherein when the computer program instructions are executed by the processor, the apparatus is triggered to run the method and / or technical solutions based on the foregoing according to the plurality of embodiments of the present application.
[0069] It is obvious to those skilled in the art that the present application is not limited to the details of the above exemplary embodiments, and can be implemented in other specific forms without departing from the spirit or essential characteristics of the present application. Therefore, the embodiments should be regarded as exemplary and non-limiting, and the scope of the present application is defined by the appended claims rather than the above description, and therefore all changes falling within the meaning and scope of the equivalent elements of the claims are intended to be included in the present application. Any reference signs in the claims should not be regarded as limiting the claims involved. In addition, it is obvious that the word "comprising" does not exclude other units or steps, and the singular does not exclude the plural. The plurality of units or devices stated in the device claim can also be implemented by one unit or device through software or hardware. The words first, second, etc. are used to indicate names, not any specific order.
Claims
1. A method for packaging containers into images, applied in a Kubernetes cluster, wherein, The method includes: The Kubernetes cluster includes at least two Kubernetes nodes, and each Kubernetes node is deployed with a container controller for monitoring container image packaging objects within the cluster. When a user accesses the platform corresponding to the Kubernetes cluster, the target container to be packaged is determined through the container visualization list interface provided by the platform, and the parameter information of the target container is obtained by accessing the kube-apiserver gateway. The parameter information includes the identifier of the target container, the node to which it belongs, and the target image repository to be pushed. The kube-apiserver gateway creates a container image package object for the target container based on the parameter information; When the container controller on a target Kubernetes node detects that the container image packaging object is the target Kubernetes node's own node task, the container controller on the target Kubernetes node packages the target container into a new image and pushes the new image to the target image repository. The method further includes: The container controller on each Kubernetes node monitors the container image packaging objects within the Kubernetes cluster in real time. If a container controller on a target Kubernetes node detects that a container image package object exists within the Kubernetes cluster, it determines whether the container image package object is a task of the target Kubernetes node itself by using the parameter information carried by the container image package object. If not, then discard the node task corresponding to the container image packaging object.
2. The method according to claim 1, wherein, When a user accesses the platform corresponding to the Kubernetes cluster, the system determines the target container to be packaged through the container visualization list interface provided by the platform and obtains the parameter information of the target container by accessing the kube-apiserver gateway, including: When a user accesses the platform corresponding to the Kubernetes cluster, in response to the user's query operation on the container visualization list interface provided by the platform, the target container to be packaged is found and determined. The platform accesses the kube-apiserver gateway through the Kubernetes Software Development Kit (SDK) and obtains the parameter information of the target container.
3. The method according to claim 1, wherein, When a container controller on a target Kubernetes node detects that the container image packaging object is a task of the target Kubernetes node itself, the container controller on the target Kubernetes node packages the target container into a new image and pushes the new image to the target image repository, including: When a container controller on a target Kubernetes node detects that the container image packaging object is the target Kubernetes node's own node task, the container controller calls the container's software development kit to find the target container on the target Kubernetes node and packages the target container into an image. After completing the image packaging of the target container, a corresponding new image is generated and the new image is pushed to the target image repository.
4. The method according to claim 1, wherein, The method further includes: In response to the user's access to the repository interface provided by the platform, the new image corresponding to the target container is visually displayed to the user on the repository interface.
5. A non-volatile storage medium having stored computer-readable instructions thereon, which, when executed by a processor, cause the processor to perform the method as described in any one of claims 1 to 4.
6. An apparatus for packaging containers into an image, wherein, The device includes: One or more processors; Computer-readable medium for storing one or more computer-readable instructions. When the one or more computer-readable instructions are executed by the one or more processors, the one or more processors implement the method as described in any one of claims 1 to 4.
Citation Information
Patent Citations
Application-based visual container configuration management method, device and system
CN110333877A
Cluster node telescoping system based on cloud platform, implementation method and operation method
CN113220416A