A container deployment method and system for decoupling dependent files
By building a lightweight initialization image and configuring an initialization container, copying dependent files into a service container, solving the problem of maintaining multiple mirror versions in the existing technology, realizing the decoupling of dependent files and deployment environments, reducing the operation Dimensions and costs.
Patent Information
- Application Number
- CN202111515308.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-13
- Publication Date
- 2024-11-26
- Estimated Expiration
- 2041-12-13
AI Technical Summary
In the prior art, forcibly merge dependent files into directories within the service, resulting in the need to maintain two versions of basic images and service images, which increases the difficulty of security and R&D operation and maintenance, especially after the test is completed, the service needs to be provided. Mirroring is done secondary modification.
By building a lightweight initialization image, storing the dependency files in it, and configuring the initialization container according to the running environment, copying the dependency files into the service container using the shared data volume. Only two initialization container images need to be maintained, and the service image does not need to consider dependencies. File problems, the images that have been tested can be directly synchronized to the production environment.
This greatly reduces the workload of test operation and maintenance, reduces maintenance costs and storage costs. Operation and maintenance personnel can easily create initialization images, avoiding the coupling between dependency files and deployment environments, and realizing the decoupling between dependency files and deployment environments.
Smart Images

Figure CN114489927B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of container technology, and more specifically, to a container deployment method and system for decoupling dependent files. Background Art
[0002] Before container technology became popular, projects were generally deployed directly on the server environment, and dependency files were also stored on the server. Services were started by directly reading the corresponding dependency files.
[0003] After the birth of Docker container technology, it was quickly accepted and used by many users due to its many advantages such as high efficiency, lightweight, easy to build, port, and "package once, run everywhere". Docker containers require that dependency files are self-contained, and services can be started independently in the container, that is, the container should contain all the dependency files required for the service to start, and be decoupled from the server environment. However, some projects that were developed earlier do not have enough developers to redevelop due to legacy code issues, and services still need to read dependency files from the specified path. If there are multiple sets of dependency files that match each environment, the container will be coupled with the deployment environment, increasing the difficulty of testing and operation and maintenance.
[0004] If you forcefully merge the dependency files into the directory within the service, that is, put the dependency files in the base image, and use the base image to package the service image, the service image that has passed the test in the R&D test environment cannot be used directly in the production environment, and the dependency files need to be modified. This requires maintaining two versions of the base image and the service image, and making a second modification to the service image after the test is completed. The above practices undoubtedly affect security and the difficulty of R&D operations. Summary of the invention
[0005] According to the present invention, a container deployment method and system for decoupling dependent files are provided to solve the technical problem in the prior art that if the dependent files are forcibly merged into the directory within the service, two versions of the base image and the service image need to be maintained, and the service image needs to be modified again after the test is completed, which undoubtedly affects the security and the difficulty of R&D and operation and maintenance.
[0006] According to a first aspect of the present invention, a container deployment method for decoupling dependent files is provided, comprising:
[0007] Build a lightweight initialization image and store dependent files in the initialization image;
[0008] According to the initialization image, importing the dependent file into the initialization image;
[0009] Configure an initialization container according to the initialization image corresponding to the operating environment;
[0010] After starting the initialization container, start the service container and read the dependency file.
[0011] Optionally, building a lightweight initialization image and storing dependent files in the initialization image includes:
[0012] Copy the dependent files into the Linux operating system image and create corresponding initialization images according to different system environments;
[0013] The compilation and packaging of the service image uses the normal operating system image as the base image.
[0014] Optionally, configuring an initialization container according to an initialization image corresponding to the operating environment includes:
[0015] Deploy and configure the shared data volume of the emptyDir type according to the initialization image corresponding to the test environment, the initialization environment corresponding to the production environment, and the server image packaged in the server container;
[0016] The shared data volume is bound to the initialization container and the server container, and the shared data volume path is the path where the dependent files need to be stored.
[0017] Optionally, configuring the initialization container according to the initialization image corresponding to the operating environment further includes:
[0018] Configure the run instruction (command) item to execute the copy command when the container starts.
[0019] Optionally, after starting the initialization container, starting the service container and reading the dependency file include:
[0020] Start the initialization container, copy the dependent files in the initialization image to the shared storage, and start the service container;
[0021] According to the service container, read the dependency file;
[0022] If a service image that has passed the test in the test environment needs to be launched in the production environment, modify the image of the initialization container to the initialization image of the production environment and redeploy the container.
[0023] According to another aspect of the present invention, a container deployment system for decoupling dependent files is provided, including:
[0024] A module for storing dependent files is used to build a lightweight initialization image and store dependent files in the initialization image;
[0025] An import dependency file module, used for importing the dependency file into the initialization image according to the initialization image;
[0026] A configuration initialization container module is used to configure an initialization container according to an initialization image corresponding to the operating environment;
[0027] The dependent file reading module is used to start the service container and read the dependent file after starting the initialization container.
[0028] Optionally, store dependency file modules, including:
[0029] Determine the initialization image submodule, which is used to copy dependent files into the Linux operating system image and create corresponding initialization images according to different system environments;
[0030] Determine the base image submodule, which is used to compile and package the service image and use the normal operating system image as the base image.
[0031] Optionally, configure the initialization container module, including:
[0032] The deployment data volume submodule is used to deploy and configure the emptyDir type shared data volume according to the initialization image corresponding to the test environment, the initialization environment corresponding to the production environment, and the server image packaged in the server container;
[0033] The data volume binding submodule is used to bind the shared data volume to the initialization container and the server container, and the shared data volume path is the path where the dependent files need to be stored.
[0034] Optionally, configuring the initialization container module also includes:
[0035] The execution copy command submodule is used to configure the run instruction (command) item and execute the copy command when the container starts.
[0036] Optionally, read dependent file modules, including:
[0037] Start the service container submodule, which is used to start the initialization container, copy the dependent files in the initialization image to the shared storage, and start the service container;
[0038] A dependent file reading submodule is used to read the dependent file according to the service container;
[0039] The redeployment container submodule is used to modify the image of the initialization container to the initialization image of the production environment and then redeploy the container if the service image that has passed the test in the test environment needs to be launched in the production environment.
[0040] Therefore, only two initialization container images need to be maintained for the R&D test environment and the production environment. Even if there are more dependent file categories in the project, only multiple initialization images need to be maintained. The initialization image only needs to copy the dependent files. The production and maintenance costs, transmission costs, and storage costs are very low, and general operation and maintenance personnel can easily make them. When building a service image, there is no need to consider the issue of dependent files. Only a base image of the service image needs to be maintained. The dependent files are copied to the operating environment by the initialization container image, and the images that have passed the test in the R&D test cluster can be directly synchronized to the production cluster for use. Only the image of the initialization container needs to be replaced, and no modification is required to the service image, which greatly reduces the workload of test operation and maintenance. BRIEF DESCRIPTION OF THE DRAWINGS
[0041] A more complete understanding of exemplary embodiments of the present invention may be obtained by referring to the following drawings:
[0042] Figure 1 A schematic diagram of a process of a container deployment method for decoupling dependent files according to this embodiment;
[0043] Figure 2 This is a schematic diagram of a container deployment architecture diagram for decoupling dependent files according to this implementation;
[0044] Figure 3 This is a schematic diagram of a container deployment system for decoupling dependent files according to this embodiment. DETAILED DESCRIPTION
[0045] Now, exemplary embodiments of the present invention are described with reference to the accompanying drawings. However, the present invention can be implemented in many different forms and is not limited to the embodiments described herein. These embodiments are provided to disclose the present invention in detail and completely and to fully convey the scope of the present invention to those skilled in the art. The terms used in the exemplary embodiments shown in the accompanying drawings are not intended to limit the present invention. In the accompanying drawings, the same units / elements are marked with the same reference numerals.
[0046] Unless otherwise specified, the terms (including technical terms) used herein have the commonly understood meanings to those skilled in the art. In addition, it is understood that the terms defined in commonly used dictionaries should be understood to have the same meanings as those in the context of the relevant fields, and should not be understood as idealized or overly formal meanings.
[0047] According to a first aspect of the present invention, a container deployment method 100 for decoupling dependent files is provided. Figure 1 As shown, the method 100 includes:
[0048] S101: Build a lightweight initialization image and store dependent files in the initialization image;
[0049] S102: According to the initialization image, import the dependent file into the initialization image;
[0050] S103: configuring an initialization container according to the initialization image corresponding to the operating environment;
[0051] S104: After starting the initialization container, start the service container and read the dependency file.
[0052] Specifically, current containerized deployment applications are generally deployed based on kubernetes, so the present invention is also based on kubernetes. For dependent files that must be read in a local path, a lightweight initialization image is specially constructed to store dependent files. The specific operation is: copy the dependent files into a Linux operating system image such as Alpine or Centos, and make initialization images according to different environments. If there are two sets of dependent files for the environment, make two initialization images. This type of initialization image only needs to have copy instructions and dependent files, without adding other toolkits, so it can be very lightweight, start quickly, and does not take up too many resources. After the initialization image is prepared according to the above steps, the compilation and packaging of the service image can use a normal operating system image as the basic image. The subsequent dependent files are copied and imported into the operating environment by the initialization image, and there is no need to consider the problem of dependent files when building a service image.
[0053] When deploying a service, refer to Figure 2 As shown, the initialization container (initContainer) needs to be configured. The image selects the corresponding initialization image according to the environment. If it is a test environment, the initialization image with the test environment dependency files is used. The production environment uses the initialization image with the production environment dependency files. The service container uses the packaged service image. At the same time, the emptyDir type shared data volume (volumes) is configured for deployment. The initialization container and the service container bind the shared data volume (volumeMounts) to themselves, and the path is the path where the dependency files need to be stored. The running instruction (command) item also needs to be configured in the initialization container. When the container starts, the copy command is executed to copy the dependency files in the initialization image to the shared storage.
[0054] When starting a service, the initialization container will be started first. Before the service container is started, the dependent files will be copied to the shared storage. Since the shared storage has been mounted to the specified path of the service container, the service container is started at this time and the program can read the dependent files normally. If the service image that has passed the test in the test environment needs to be launched in the production environment, you only need to modify the image of the initialization container to the initialization image of the production environment and then redeploy it. There is no need to make a second modification to the service image, which realizes the decoupling of the dependent files and the deployment environment.
[0055] If you follow the traditional method and place the dependency files in the base image for building the service image, you will need to maintain at least two base images (for R&D testing and production environments). The base image for the service is larger and more complex, and the production and maintenance costs, transmission costs, and storage costs are higher. If there are more categories of dependency files in the project, and the dependency files used by services in the same environment are different, you will need to maintain more base images, and the image after the test needs to modify the dependency files before it can be used in the production environment, which violates the test specifications.
[0056] The present invention only needs to maintain two initialization container images for the R&D test environment and the production environment. Even if there are more dependent file categories in the project, it is only necessary to maintain multiple initialization images. The initialization image only needs to copy the dependent files. The production maintenance cost, transmission cost and storage cost are very low, and general operation and maintenance personnel can easily make them. There is no need to consider the problem of dependent files when building a service image. Only a base image of a service image needs to be maintained. The dependent files are copied to the operating environment by the initialization container image, and the images that pass the test in the R&D test cluster can be directly synchronized to the production cluster for use. It is only necessary to replace the image of the initialization container, and there is no need to modify the service image, which greatly reduces the workload of test operation and maintenance.
[0057] Optionally, building a lightweight initialization image and storing dependent files in the initialization image includes:
[0058] Copy the dependent files into the Linux operating system image and create corresponding initialization images according to different system environments;
[0059] The compilation and packaging of the service image uses the normal operating system image as the base image.
[0060] Optionally, configuring an initialization container according to an initialization image corresponding to the operating environment includes:
[0061] Deploy and configure the shared data volume of the emptyDir type according to the initialization image corresponding to the test environment, the initialization environment corresponding to the production environment, and the server image packaged in the server container;
[0062] The shared data volume is bound to the initialization container and the server container, and the shared data volume path is the path where the dependent files need to be stored.
[0063] Optionally, configuring the initialization container according to the initialization image corresponding to the operating environment further includes:
[0064] Configure the run instruction (command) item to execute the copy command when the container starts.
[0065] Optionally, after starting the initialization container, starting the service container and reading the dependency file include:
[0066] Start the initialization container, copy the dependent files in the initialization image to the shared storage, and start the service container;
[0067] According to the service container, read the dependency file;
[0068] If a service image that has passed the test in the test environment needs to be launched in the production environment, modify the image of the initialization container to the initialization image of the production environment and redeploy the container.
[0069] According to another aspect of the present invention, a container deployment system 300 for decoupling dependent files is provided. Figure 3 As shown, the system 300 includes:
[0070] A dependency file storage module 310 is used to construct a lightweight initialization image and store the dependency files in the initialization image;
[0071] An import dependency file module 320 is used to import the dependency file into the initialization image according to the initialization image;
[0072] A configuration initialization container module 330 is used to configure an initialization container according to an initialization image corresponding to the operating environment;
[0073] The dependency file reading module 340 is used to start the service container and read the dependency file after starting the initialization container.
[0074] Optionally, the storage dependency file module 310 includes:
[0075] Determine the initialization image submodule, which is used to copy dependent files into the Linux operating system image and create corresponding initialization images according to different system environments;
[0076] Determine the base image submodule, which is used to compile and package the service image and use the normal operating system image as the base image.
[0077] Optionally, configuring the initialization container module 330 includes:
[0078] The deployment data volume submodule is used to deploy and configure the emptyDir type shared data volume according to the initialization image corresponding to the test environment, the initialization environment corresponding to the production environment, and the server image packaged in the server container;
[0079] The data volume binding submodule is used to bind the shared data volume to the initialization container and the server container, and the shared data volume path is the path where the dependent files need to be stored.
[0080] Optionally, configuring the initialization container module 330 further includes:
[0081] The execution copy command submodule is used to configure the run instruction (command) item and execute the copy command when the container starts.
[0082] Optionally, the dependent file reading module 340 includes:
[0083] Start the service container submodule, which is used to start the initialization container, copy the dependent files in the initialization image to the shared storage, and start the service container;
[0084] A dependent file reading submodule is used to read the dependent file according to the service container;
[0085] The redeployment container submodule is used to modify the image of the initialization container to the initialization image of the production environment and then redeploy the container if the service image that has passed the test in the test environment needs to be launched in the production environment.
[0086] A container deployment system 300 for decoupling dependent files in an embodiment of the present invention corresponds to a container deployment method 100 for decoupling dependent files in another embodiment of the present invention, and will not be described in detail herein.
[0087] Those skilled in the art will appreciate that the embodiments of the present application can be provided as methods, systems, or computer program products. Therefore, the present application can adopt the form of complete hardware embodiments, complete software embodiments, or embodiments in combination with software and hardware. Moreover, the present application can adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that contain computer-usable program code. The scheme in the embodiments of the present application can be implemented in various computer languages, for example, object-oriented programming language Java and literal scripting language JavaScript, etc.
[0088] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0089] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0090] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0091] Although the preferred embodiments of the present application have been described, those skilled in the art may make other changes and modifications to these embodiments once they have learned the basic creative concept. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications falling within the scope of the present application.
[0092] Obviously, those skilled in the art can make various changes and modifications to the present application without departing from the spirit and scope of the present application. Thus, if these modifications and variations of the present application fall within the scope of the claims of the present application and their equivalents, the present application is also intended to include these modifications and variations.
Claims
1. A container deployment method for decoupling dependent files, characterized in that: include: Build a lightweight initialization image and store dependent files in the initialization image; According to the initialization image, importing the dependent files into the initialization image; Configure the initialization container according to the initialization image corresponding to the operating environment; After starting the initialization container, start the service container and read the dependency file; Build a lightweight initialization image and store dependent files in the initialization image, including: Copy the dependent files into the Linux operating system image and create corresponding initialization images according to different system environments; Compile and package the service image and use the normal operating system image as the base image; Configuring an initialization container according to the initialization image corresponding to the operating environment includes: Deploy and configure shared data volumes of the emptyDir type based on the initialization image corresponding to the test environment, the initialization environment corresponding to the production environment, and the server image packaged with the server container; Bind the shared data volume to the initialization container and the server container, and the shared data volume path is the path where the dependent files need to be stored; After starting the initialization container, start the service container and read the dependency file, including: Start the initialization container, copy the dependent files in the initialization image to the shared storage, and start the service container; According to the service container, read the dependency file; If a service image that has passed the test in the test environment needs to be launched in the production environment, modify the image of the initialization container to the initialization image of the production environment and redeploy the container.
2. The method according to claim 1, characterized in that Configuring an initialization container according to the initialization image corresponding to the operating environment also includes: Configure the command item to execute the copy command when the container starts.
3. A container deployment system that decouples dependent files, characterized in that: include: A dependency file storage module is used to build a lightweight initialization image and store dependency files in the initialization image; An import dependency file module, configured to import the dependency file into the initialization image according to the initialization image; Configure the initialization container module to configure the initialization container according to the initialization image corresponding to the operating environment; A dependency file reading module is used to start the service container and read the dependency file after starting the initialization container; Storage dependency file modules, including: Determine the initialization image submodule, which is used to copy dependent files into the Linux operating system image and create corresponding initialization images according to different system environments; Determine the base image submodule, which is used to compile and package the service image and use the normal operating system image as the base image; Configure the initialization container module, including: The data volume deployment submodule is used to deploy and configure the shared data volume of the emptyDir type based on the initialization image corresponding to the test environment, the initialization environment corresponding to the production environment, and the server image packaged in the server container; The data volume binding submodule is used to bind the shared data volume to the initialization container and the server container, and the shared data volume path is the path where the dependent files need to be stored; Read dependent file modules, including: Start the service container submodule, which is used to start the initialization container, copy the dependent files in the initialization image to the shared storage, and start the service container; A dependent file reading submodule is used to read the dependent file according to the service container; The redeployment container submodule is used to modify the image of the initialization container to the initialization image of the production environment and then redeploy the container if the service image that has passed the test in the test environment needs to be launched in the production environment.
4. The system according to claim 3, characterized in that Configuring the initialization container module also includes: The copy command execution submodule is used to configure the run instruction (command) item and execute the copy command when the container starts.
