Container deployment method and device, computer equipment, readable storage medium and program product
By dynamically matching environment identifiers and combining common configuration files, the problems of large resource consumption and low efficiency in traditional container deployment methods are solved, and efficient container deployment across multiple application environments is achieved.
Patent Information
- Application Number
- CN202411734386.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-29
- Publication Date
- 2025-03-14
AI Technical Summary
Traditional container deployment methods require the construction of different images for each application environment, resulting in high resource consumption and low efficiency.
By obtaining the common configuration file and the preset parameter information group of each application environment, dynamically match the environment identifier to determine the target preset parameter information group, and building the target configuration file with the general configuration file to realize the deployment of the container.
This method avoids building configuration files for each application environment separately, improves the efficiency of container deployment, and enables container deployment in multiple different application environments.
Smart Images

Figure CN119621243A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of cloud native technology, and in particular to a container deployment method, apparatus, computer device, computer-readable storage medium, and computer program product. Background Art
[0002] With the development of cloud-native technology, more and more enterprise applications are deployed in containers. In the process from container development to application, the application environment of the container is different. Therefore, container images in different environments are required to enable containers to run in different environments.
[0003] In traditional technologies, developers pre-build configuration files corresponding to different environments based on the parameters required for container operation in different application environments. Specifically, developers pre-define the environment parameters corresponding to an application environment for each configuration file in Pod (the smallest deployable unit in Kubernetes, which can contain one or more containers) or Deployment (a controller in Kubernetes that manages the deployment and update of Pods), and finally obtain a configuration file corresponding to each application environment, so as to build the image corresponding to the application environment in each application environment. Then, when deploying the container, the configuration file of the image corresponding to the target application environment is used to deploy the container in the target application environment.
[0004] However, in the traditional method, an image corresponding to each application environment is built. Due to the high complexity of the application environment and the large amount of information in the configuration file, the container deployment consumes a lot of resources, which leads to low efficiency of container deployment. Summary of the invention
[0005] Based on this, it is necessary to provide a container deployment method, apparatus, computer device, computer-readable storage medium and computer program product to address the above technical issues.
[0006] In a first aspect, the present application provides a container deployment method, comprising:
[0007] Obtaining a general configuration file, a preset parameter information group in each application environment, and a second environment identifier corresponding to the target application environment, each of the preset parameter information groups carrying a first environment identifier;
[0008] Matching the first environment identifier with the second environment identifier, and determining a target preset parameter information group corresponding to the second environment identifier in each of the preset parameter information groups based on the matching result;
[0009] A target configuration file is constructed according to the target preset parameter information group and the general configuration file, and a target container in the target application environment is deployed according to the target configuration file.
[0010] In one embodiment, matching the first environment identifier with the second environment identifier, and determining a target preset parameter information group corresponding to the second environment identifier in each preset parameter information group based on the matching result, includes:
[0011] Matching the first environment identifier with the second environment identifier, and determining the target first environment identifier that matches the second environment identifier as a matching result;
[0012] Based on the association relationship between the preset parameter information group and the first environment identifier, a target preset parameter information group corresponding to the target first environment identifier in the matching result is determined.
[0013] In one of the embodiments, the target preset parameter information group includes candidate parameters and parameter values corresponding to the candidate parameters, and the general configuration file includes variable parameters;
[0014] The step of constructing a target configuration file according to the target preset parameter information group and the general configuration file includes:
[0015] Based on the variable parameters in the general configuration file and the candidate parameters in the target preset parameter information group, determining a target parameter in the candidate parameters and a target parameter value corresponding to the target parameter;
[0016] A target configuration file is constructed according to the target parameter value and the variable parameters.
[0017] In one embodiment, constructing a target configuration file according to the target parameter value and the variable parameter includes:
[0018] The target parameter value is used as the parameter value corresponding to the variable parameter in the general configuration file, and is added to the general configuration file to obtain the target configuration file.
[0019] In one embodiment, deploying the target container in the target application environment according to the target configuration file includes:
[0020] In response to a container startup instruction, mounting the target configuration file into the target container according to a mount path of the target configuration file;
[0021] The target container in the target application environment is started according to the startup script and the target configuration file in the target container.
[0022] In one embodiment, before obtaining the common configuration file and the preset parameter information groups in each application environment and the second environment identifier corresponding to the target application environment, and each of the preset parameter information groups carries the first environment identifier, the method further includes:
[0023] Obtain the parameter type corresponding to the target container and the preset parameter information group corresponding to each application environment;
[0024] Creating a general configuration file according to the default parameters and variable parameters included in the parameter type corresponding to the target container;
[0025] Based on the correspondence between each of the application environments and the preset parameter information groups, generating a first environment identifier and the preset parameter information groups corresponding to each of the first environment identifiers;
[0026] The general configuration file, the first environment identifier, the preset parameter information group, and the association relationship between each of the first environment identifiers and the preset parameter information group are stored.
[0027] In a second aspect, the present application also provides a container deployment device, including:
[0028] A first acquisition module is used to acquire a common configuration file, a preset parameter information group in each application environment, and a second environment identifier corresponding to the target application environment, each of the preset parameter information groups carrying a first environment identifier;
[0029] a matching module, configured to match the first environment identifier with the second environment identifier, and determine a target preset parameter information group corresponding to the second environment identifier in each of the preset parameter information groups based on the matching result;
[0030] A deployment module is used to construct a target configuration file according to the target preset parameter information group and the general configuration file, and deploy a target container in the target application environment according to the target configuration file.
[0031] In one of the embodiments, the matching module is specifically used to match the first environment identifier with the second environment identifier, and determine the target first environment identifier that matches the second environment identifier as a matching result;
[0032] Based on the association relationship between the preset parameter information group and the first environment identifier, a target preset parameter information group corresponding to the target first environment identifier in the matching result is determined.
[0033] In one of the embodiments, the target preset parameter information group includes candidate parameters and parameter values corresponding to the candidate parameters, and the general configuration file includes variable parameters; the deployment module is specifically used to determine the target parameters in the candidate parameters and the target parameter values corresponding to the target parameters based on the variable parameters in the general configuration file and the candidate parameters in the target preset parameter information group;
[0034] A target configuration file is constructed according to the target parameter value and the variable parameters.
[0035] In one of the embodiments, the deployment module is specifically configured to add the target parameter value as the parameter value corresponding to the variable parameter in the general configuration file to the general configuration file to obtain the target configuration file.
[0036] In one of the embodiments, the deployment module is specifically configured to mount the target configuration file into the target container according to the mount path of the target configuration file in response to a container startup instruction;
[0037] The target container in the target application environment is started according to the startup script and the target configuration file in the target container.
[0038] In one embodiment, the device further comprises:
[0039] A second acquisition module is used to acquire a parameter type corresponding to the target container and a preset parameter information group corresponding to each application environment;
[0040] A creation module, used to create a general configuration file according to the default parameters and variable parameters included in the parameter type corresponding to the target container;
[0041] A generating module, configured to generate a first environment identifier and the preset parameter information group corresponding to each of the first environment identifiers based on a correspondence between each of the application environments and the preset parameter information group;
[0042] A storage module is used to store the general configuration file, the first environment identifier, the preset parameter information group, and the association relationship between each of the first environment identifiers and the preset parameter information group.
[0043] In a third aspect, the present application further provides a computer device, including a memory and a processor, wherein the memory stores a computer program, and when the processor executes the computer program, the following steps are implemented:
[0044] Obtaining a general configuration file, a preset parameter information group in each application environment, and a second environment identifier corresponding to the target application environment, each of the preset parameter information groups carrying a first environment identifier;
[0045] Matching the first environment identifier with the second environment identifier, and determining a target preset parameter information group corresponding to the second environment identifier in each of the preset parameter information groups based on the matching result;
[0046] A target configuration file is constructed according to the target preset parameter information group and the general configuration file, and a target container in the target application environment is deployed according to the target configuration file.
[0047] In a fourth aspect, the present application further provides a computer-readable storage medium having a computer program stored thereon, wherein when the computer program is executed by a processor, the following steps are implemented:
[0048] Obtaining a general configuration file, a preset parameter information group in each application environment, and a second environment identifier corresponding to the target application environment, each of the preset parameter information groups carrying a first environment identifier;
[0049] Matching the first environment identifier with the second environment identifier, and determining a target preset parameter information group corresponding to the second environment identifier in each of the preset parameter information groups based on the matching result;
[0050] A target configuration file is constructed according to the target preset parameter information group and the general configuration file, and a target container in the target application environment is deployed according to the target configuration file.
[0051] In a fifth aspect, the present application further provides a computer program product, including a computer program, which implements the following steps when executed by a processor:
[0052] Obtaining a general configuration file, a preset parameter information group in each application environment, and a second environment identifier corresponding to the target application environment, each of the preset parameter information groups carrying a first environment identifier;
[0053] Matching the first environment identifier with the second environment identifier, and determining a target preset parameter information group corresponding to the second environment identifier in each of the preset parameter information groups based on the matching result;
[0054] A target configuration file is constructed according to the target preset parameter information group and the general configuration file, and a target container in the target application environment is deployed according to the target configuration file.
[0055] The container deployment method, apparatus, computer equipment, computer-readable storage medium and computer program product described above obtain the first environment identifier corresponding to each preset parameter information, the general configuration file corresponding to the target container and the second environment identifier of the target application environment; match the first environment identifier with the second environment identifier, and determine the target preset parameter information corresponding to the second environment identifier based on the association relationship between the preset parameter information and the first environment identifier; construct a target configuration file according to the target preset parameter information and the general configuration file, and start the target container in the target application environment according to the target configuration file. With this method, the preset parameter information group required for the target application environment is dynamically selected through the first environment identifier and the second environment identifier, and the preset parameter information group and the general configuration file are combined to obtain the target configuration file, so that a combination of a general configuration file and different preset parameter information groups can realize the deployment of containers in multiple different application environments, avoiding the construction of a configuration file for each application environment separately, thereby improving the efficiency of container deployment. BRIEF DESCRIPTION OF THE DRAWINGS
[0056] In order to more clearly illustrate the technical solutions in the embodiments of the present application or related technologies, the drawings required for use in the embodiments of the present application or related technical descriptions will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without paying creative work.
[0057] Figure 1 An application environment diagram of a container deployment method in an embodiment;
[0058] Figure 2 A schematic diagram of a process for constructing a target preset parameter information group in one embodiment;
[0059] Figure 3 A schematic diagram of a process for constructing a target configuration file in one embodiment;
[0060] Figure 4 A schematic diagram of a process of deploying a target container in another embodiment;
[0061] Figure 5 A schematic diagram of a process for pre-configuring a general configuration file and a preset parameter information group in one embodiment;
[0062] Figure 6 It is a structural block diagram of a container deployment device in one embodiment;
[0063] Figure 7 FIG. 4 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION
[0064] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0065] In traditional technologies, developers pre-configure the parameters required for container operation in different environments into Deployment, and the configuration of Deployment is usually static. Once deployed, modifying the configuration file requires redeploying the entire application. In addition, updating the configuration in Deployment (such as environment variables) requires re-creating or updating the Deployment object, which will cause a brief service interruption.
[0066] The container deployment method proposed in the present application dynamically selects the preset parameter information group required by the target application environment through the first environment identifier and the second environment identifier, and combines the preset parameter information group with the general configuration file to obtain the target configuration file without waiting for the application to be restarted or redeployed. At the same time, the combination of a general configuration file and different preset parameter information groups can realize the deployment of containers in a variety of different application environments, avoiding the construction of a separate configuration file for each application environment. Before the container image corresponding to the container application is initialized, the target preset information group corresponding to the application environment is selected to generate the target configuration file, thereby eliminating the need to build container images corresponding to different application environments. Using one container image can meet the container deployment requirements of multiple application environments, thereby improving the efficiency of container deployment.
[0067] Before introducing the specific embodiments of the present invention, the professional terms involved in the present invention are explained first:
[0068] Kubernetes (k8s for short): an open source container orchestration platform for automating the deployment, expansion, and management of containerized applications.
[0069] Pod: The smallest deployable unit in Kubernetes, which can contain one or more containers.
[0070] Deployment: A controller in Kubernetes that manages the deployment and updates of Pods.
[0071] ConfigMap: A resource object used to store configuration data in Kubernetes.
[0072] Init Container: A temporary container that runs before the application container is started and is used to perform some initialization tasks.
[0073] CI / CD: Continuous Integration / Continuous Deployment is a software development practice that aims to automate the process of building, testing, and deploying code.
[0074] Prometheus: An open source monitoring system for collecting and storing time series data.
[0075] In one embodiment, Figure 1 As shown, a container deployment method is provided. This embodiment uses the method applied to a server as an example. It can be understood that the method can also be applied to a system including a terminal and a server and implemented through the interaction between the terminal and the server. In this embodiment, the method includes the following steps:
[0076] Step 102, obtaining a common configuration file, a preset parameter information group in each application environment, and a second environment identifier corresponding to the target application environment, wherein each preset parameter information group carries a first environment identifier.
[0077] In an embodiment of the present application, a general configuration file can be stored in a ConfigMap, and the general configuration file is used in the Init Container image definition. The Init Container image performs initialization tasks before the main application target container is started. First, the server obtains the general configuration file from the ConfigMap through the Init Container image and reads the configuration information. At the same time, the server pre-stores preset parameter information groups corresponding to the main application target container under different application environments, and each preset parameter information group carries a first environment identifier, which is used to characterize the application environment adapted by each preset parameter information group. Among them, the application environment can be a development environment, a test environment, and a production environment, etc., and the configuration parameters in the configuration files such as container resource configuration, storage configuration, and environment variables corresponding to different application environments are different. The server can use the environment information of the current application, and the environment information can include a second environment identifier, or the server can also determine the second environment identifier corresponding to the current target application environment through the transmission of command line parameters. The second environment identifier is used to determine the target preset parameter information group required for the target application environment.
[0078] Step 104: Match the first environment identifier with the second environment identifier, and determine a target preset parameter information group corresponding to the second environment identifier in each preset parameter information group based on the matching result.
[0079] The preset parameter information group includes detailed configuration parameters in a specific application environment.
[0080] In an embodiment of the present application, the server matches the second environment identifier in the first environment identifier corresponding to multiple application environments according to the preset matching logic, and determines whether there is a preset parameter information group that matches the application environment corresponding to the second environment identifier based on the first environment identifier. For example, if the first environment identifier includes a development environment (dev), a test environment (test), a production environment (prod), etc., and the second environment identifier is a branch (dev-feature-1) under the development environment, the server can determine the preset parameter information group corresponding to the first identifier development environment (dev) as the target preset parameter information group, as the basis for the subsequent construction of the target configuration file of the Init Container image corresponding to the target container.
[0081] In an optional embodiment, if there is no environment identifier in the first environment identifier that directly matches the second environment identifier, the server may generate a target preset parameter information group based on a default value.
[0082] Step 106: construct a target configuration file according to the target preset parameter information group and the general configuration file, and deploy a target container in the target application environment according to the target configuration file.
[0083] In an embodiment of the present application, the server combines the parameters in the target preset parameter information group with the general configuration file to construct a target configuration file suitable for the target application environment. For example, the server can use a template engine (e.g., Jinja2, Go templates) or a text replacement tool to insert the parameters in the target preset parameter information group into the general configuration file to generate a target configuration file. Then, the server mounts the constructed target configuration file to the specified path of the target container. The server can be implemented through Kubernetes' ConfigMap or Secret resources, or mounted through Docker's -v parameter. At the same time, it is necessary to ensure that the target configuration file is mounted to the correct path inside the target container so that the target container can read the target configuration file when it starts. For example, the target configuration file is mounted to the " / etc / app / config" directory. Then, when the main application target container is started, it mounts the target configuration file generated by Init Container and reads the configuration information in the target configuration file through the entrypoint.sh script. Separating the configuration information from the application code and storing it in ConfigMap can improve the maintainability of the code and make the configuration information easier to manage and audit. At the same time, by creating different ConfigMaps for different environments (such as development, testing, and production), environment isolation can be easily achieved to avoid configuration conflicts. Using ConfigMap, you can easily deploy the same application in different environments by simply changing the configuration information in ConfigMap, which greatly simplifies the complexity of multi-environment management. Through the unified ConfigMap and Init Container mode, the configuration management process can be standardized to reduce human errors. In addition, by storing sensitive information (such as passwords and keys) in Secret instead of writing them directly in application code or configuration files, security is improved.
[0084] In an optional embodiment, the server can also automatically manage and update ConfigMap through CI / CD tools (such as Jenkins, GitLabCI) to achieve continuous delivery and continuous deployment. ConfigMap is managed by Kubernetes. Through ConfigMap, the validity of configuration information can be detected when the application starts, reducing application failures caused by configuration errors. It has high availability, and even if a node fails, ConfigMap can still work normally.
[0085] In an optional embodiment, the server can monitor the status and changes of ConfigMap in real time through Kubernetes monitoring tools (such as Prometheus and Grafana) to ensure the correctness and consistency of the configuration information.
[0086] In the above container deployment method, the preset parameter information group required by the target application environment is dynamically selected through the first environment identifier and the second environment identifier, and the preset parameter information group and the general configuration file are combined to obtain the target configuration file, so that a general configuration file and different preset parameter information groups can be combined to realize the deployment of containers in a variety of different application environments, avoiding the construction of a separate configuration file for each application environment, thereby improving the efficiency of container deployment.
[0087] In an exemplary embodiment, Figure 2 As shown, step 104 includes steps 202 to 204. Among them:
[0088] Step 202: Match the first environment identifier with the second environment identifier, and determine the target first environment identifier that matches the second environment identifier as a matching result.
[0089] In an embodiment of the present application, the server can match the first environment identifier with the second environment identifier in a fuzzy matching manner, determine the target first environment identifier in the first environment identifier that has the same field in the name as the second environment identifier, and use the target first environment identifier as the matching result. For example, if the first environment identifier includes a development environment (dev), a test environment (test), and a production environment (prod), and the second environment identifier contains specific version number information, such as a branch (dev-feature-1) in the development environment, then through the fuzzy matching method, it can be determined that the first environment identifier dev and the second environment identifier have the same field in their names, then the server determines the first environment identifier dev as the first target environment identifier, and uses it as the matching result between the first environment identifier and the second environment identifier.
[0090] In another embodiment, the first environment identifier and the second environment identifier are matched in an exact match, that is, only when the first environment identifier and the second environment identifier are completely consistent, it is determined that there is a first environment identifier that matches the second environment identifier. At this time, each application environment version corresponds to a preset parameter information group, and further, different application environment versions can also be distinguished in the first environment identifier. For example, the preset parameter information group contains various branches in the development environment (dev-feature-1, dev-feature-2, dev-feature-3, etc.).
[0091] Step 204: Based on the association relationship between the preset parameter information group and the first environment identifier, determine the target preset parameter information group corresponding to the target first environment identifier in the matching result.
[0092] In the embodiment of the present application, the server pre-stores preset parameter information groups under multiple application environments. For example, the preset parameter information of the development environment (dev) includes data connection strings, log levels, maximum number of connections, and environmental parameters and resource configuration parameters under the development environment. Each preset parameter information group has a corresponding first environment identifier, and the first environment identifier is used to characterize the application environment to which each preset parameter information group is adapted. The server finally determines the preset parameter information group corresponding to the target first environment identifier based on the association between the preset parameter information group and the first environment identifier, and determines the preset parameter information group corresponding to the target first environment identifier as the target preset parameter information group. The target preset parameter information group is used as the parameter basis for generating the target configuration file, providing data support for the subsequent generation of the target configuration file.
[0093] In this embodiment, based on the association between the preset parameter information group and the first environment identifier, the target preset parameter information group corresponding to the second environment information of the target application environment is dynamically selected, thereby achieving flexible selection of the target preset parameter information group for the target application environment, avoiding the configuration of independent parameter information for various application environments, and thus improving the efficiency and flexibility of container deployment.
[0094] In an exemplary embodiment, the target preset parameter information group includes candidate parameters and parameter values corresponding to the candidate parameters, and the general configuration file includes variable parameters; the server selects the configuration parameters adapted to the current application environment, such as Figure 3 As shown, step 106 includes steps 302 to 304. Among them:
[0095] Step 302: Based on the variable parameters in the general configuration file and the candidate parameters in the target preset parameter information group, determine the target parameters in the candidate parameters and the target parameter values corresponding to the target parameters.
[0096] In the embodiment of the present application, the general configuration file is used as a general configuration file template, including multiple variable parameters and default parameters, the variable parameters are used to replace the pre-configured parameter items in the target preset parameter information group that match the target application environment, and the default parameters can be the port or IP (Internet Protocol Address) corresponding to the target container of the main application, which is used to confirm the Pod corresponding to the target container. The server selects according to the variable parameters in the general configuration file and the candidate parameters contained in the target preset parameter information group, wherein the target parameters corresponding to the candidate parameters in the variable parameters are parameter items that need to be adaptively adjusted according to the target application environment. If some parameter items in the variable parameters do not have corresponding target parameters in the target preset parameter information group, it means that the default parameter values can be used for such parameter items in the variable parameters, that is, the current target application environment has no special requirements for such parameter items.
[0097] The server first determines the parameter items corresponding to the variable parameters in the general configuration file, then determines the parameter items corresponding to the candidate parameters in the target preset parameter information group, and determines the parameter items contained in the candidate parameters and the variable parameters as the target parameters, and determines the target parameter values corresponding to the target parameters. For example, if the variable parameters contained in the general configuration file are A, B, and C, and the candidate parameters contained in the target preset parameter information group include B and C, then the server uses the candidate parameters B and C as the target parameters, and determines the target parameter values B1 and C1 corresponding to the candidate parameters B and C, respectively.
[0098] Step 304: construct a target configuration file according to the target parameter value and the variable parameters.
[0099] In an embodiment of the present application, the server can directly use the target parameter value as the parameter value corresponding to the variable parameter according to the correspondence between the target parameter and the variable parameter, or calculate the target parameter value according to a pre-set conversion mapping rule, or adjust the target parameter value accordingly according to the available resources of the current server, determine the parameter value range corresponding to the variable parameter, and construct a target configuration file based on the parameter value range.
[0100] In this embodiment, based on the association between the preset parameter information group and the first environment identifier, the target preset parameter information group corresponding to the second environment information of the target application environment is dynamically selected to generate a target configuration file suitable for different application environments, thereby achieving a flexible combination of a common configuration file and multiple preset parameter information groups, avoiding the need to construct a configuration file separately for each application environment, and significantly improving the efficiency and flexibility of container deployment.
[0101] In an exemplary embodiment, step 304 specifically includes:
[0102] Step 3041: Add the target parameter value as the parameter value corresponding to the variable parameter in the general configuration file to the general configuration file to obtain the target configuration file.
[0103] In an embodiment of the present application, according to the correspondence between the target parameter value and the variable parameter, the server can directly assign the target parameter value to the variable parameter. Specifically, the server adds or updates the determined target parameter value as the corresponding value of the variable parameter in the general configuration file, thereby generating a target configuration file suitable for the current application environment. For example, the general configuration file contains variable parameters, and the variable parameters may be CPU_CORES, GPU_COUNT, etc., and the target preset parameter information group of the development environment is determined according to the development environment (dev) to contain the target parameters CPU_CORES: 4, GPU_COUNT: 1. The server will then replace the variable parameters in the general configuration file with the target parameter values, and generate a target configuration file, thereby setting the parameter values of the target parameters CPU_CORES and GPU_COUNT in the target configuration file to the target parameters corresponding to the target application environment.
[0104] In this embodiment, based on the association between the preset parameter information group and the environment identifier, the second environment information corresponding to the target application environment is dynamically selected, thereby achieving a flexible combination of a general configuration file and multiple preset parameter information groups, effectively avoiding the need to construct a separate configuration file for each application environment, and significantly improving the efficiency and flexibility of container deployment.
[0105] In an exemplary embodiment, Figure 4 As shown, step 106 includes steps 402 to 404. Among them:
[0106] Step 402, in response to the container startup instruction, mount the target configuration file into the target container according to the mount path of the target configuration file.
[0107] In an embodiment of the present application, when the server receives an instruction to start a container from a user input or an API (Application Programming Interface) call, the server executes the container startup command according to the startup script. In response to the container startup instruction, the server determines the generation path of the target configuration file as the mount path of the target configuration file in the target container, so that the Init Container corresponding to the target container can correctly read the target configuration file. For example, in Kubernetes, the server mounts the target configuration file to the specified path of the target container according to ConfigMap or secret.
[0108] Step 404: Start the target container in the target application environment according to the startup script and the target configuration file in the target container.
[0109] In an embodiment of the present application, the server includes a predefined startup script, which includes a series of instructions for initializing the container environment and starting the main application according to the target configuration file. Specifically, the server loads the target configuration file mounted in the container according to the mount path of the target configuration file, and reads the parameters in the target configuration file. Furthermore, the server sets the environment variables according to the parameters in the target configuration file, and allocates the system resources (e.g., memory, CPU, etc.) required by the main application according to the parameters contained in the target configuration file. After initialization is completed, the server startup script executes the startup command of the application. The startup command is usually an executable file or script that starts the main process of the application. The startup command loads the parameters in the target configuration file and configures the behavior of the application according to the parameters. For example, setting database connections, log levels, API endpoints, etc.
[0110] In an optional embodiment, during the application startup process, the server continuously monitors the running status of the container and records logs. The log files are usually recorded in a specified path in the container and may contain important events and error information during the startup process. The monitoring system can monitor the running status of the application in real time and take corresponding measures (for example, restarting the container, sending an alarm, etc.) when an abnormality occurs.
[0111] In this embodiment, the initialization of the container and the startup of the application are completed according to the startup script and the target configuration file. This process ensures that the container can correctly load the configuration file when it starts and run the application according to the parameters in the configuration file. In this way, the configuration of different application environments can be flexibly managed, and the same container image can be deployed in different environments, thereby improving deployment efficiency and consistency.
[0112] In an exemplary embodiment, Figure 5 As shown, step 102 includes steps 502 to 508. Among them:
[0113] Step 502: Obtain the parameter type corresponding to the target container and the preset parameter information group corresponding to each application environment.
[0114] In an embodiment of the present application, the developer inputs the preset parameter information group constructed by the environmental parameters and required resource configuration corresponding to the main application in different application environments into the server, and the server can obtain detailed information of the target container according to the k8s platform, including the container name, image version, operating environment, etc. Optionally, the server can also obtain the preset parameter information group corresponding to each application environment (such as development environment, test environment, production environment) from the configuration management database or configuration file. Among them, the preset parameter information group includes default parameters and variable parameters. The default parameters are the basic parameters required when the container is started, and the variable parameters are the parameters that can be adjusted according to different application environments.
[0115] Step 504: Create a general configuration file according to the default parameters and variable parameters included in the parameter type corresponding to the target container.
[0116] In the embodiment of the present application, the server creates a general configuration file template according to the parameter type corresponding to the target container. The general configuration file template contains placeholders for default parameters and variable parameters, and directly fills the values of the default parameters into the general configuration file. Since the default parameters are fixed in all environments, the parameter values corresponding to the default parameters are static in the configuration file.
[0117] Step 506: Based on the correspondence between each application environment and the preset parameter information group, generate the first environment identifier and the preset parameter information group corresponding to each first environment identifier.
[0118] In an embodiment of the present application, the server generates a unique first environment identifier (e.g., dev, test, prod) for each application environment. The first environment identifier is used to distinguish different application environments and associate the preset parameter information group of the corresponding environment. The server generates an environment parameter information group for each application environment based on the correspondence between each application environment and the preset parameter information group.
[0119] Step 508: store the general configuration file, the first environment identifier, the preset parameter information group, and the association relationship between each first environment identifier and the preset parameter information group.
[0120] In an embodiment of the present application, the server stores the created universal configuration file in a configuration management database or a configuration storage system. The universal configuration file is usually stored in a version control system (e.g., Git) for version management and rollback. For storing the first environment identifier and the preset parameter information group, the server stores the generated first environment identifier and the corresponding environment parameter information group in the configuration management database. The first environment identifier and the corresponding environment parameter information are stored in the form of a key-value pair, where the key is the environment identifier and the value is the environment parameter information group. The system stores the association relationship between each environment identifier and the preset parameter information group. The association relationship can be a mapping table structure, which records which first environment identifier corresponds to which preset parameter information groups.
[0121] In this embodiment, by pre-building a common configuration file and storing the preset parameter information group and the association relationship between each first environment identifier and the preset parameter information group, it can be ensured that the target container can dynamically adjust the configuration according to the preset parameter information group in different application environments, thereby improving the flexibility and consistency of deployment.
[0122] It should be understood that, although the various steps in the flowcharts involved in the above-mentioned embodiments are displayed in sequence according to the indication of the arrows, these steps are not necessarily executed in sequence according to the order indicated by the arrows. Unless there is a clear explanation in this article, the execution of these steps does not have a strict order restriction, and these steps can be executed in other orders. Moreover, at least a part of the steps in the flowcharts involved in the above-mentioned embodiments can include multiple steps or multiple stages, and these steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily to be carried out in sequence, but can be executed in turn or alternately with other steps or at least a part of the steps or stages in other steps.
[0123] Based on the same inventive concept, the embodiment of the present application also provides a container deployment device for implementing the container deployment method involved above. The implementation solution provided by the device to solve the problem is similar to the implementation solution recorded in the above method, so the specific limitations in one or more container deployment device embodiments provided below can refer to the limitations of the container deployment method above, and will not be repeated here.
[0124] In an exemplary embodiment, Figure 6 As shown, a container deployment device 600 is provided, comprising: a first acquisition module 601, a matching module 602 and a deployment module 603, wherein:
[0125] A first acquisition module 601 is used to acquire a common configuration file, a preset parameter information group in each application environment, and a second environment identifier corresponding to a target application environment, wherein each preset parameter information group carries a first environment identifier;
[0126] A matching module 602 is used to match the first environment identifier with the second environment identifier, and determine a target preset parameter information group corresponding to the second environment identifier in each preset parameter information group based on the matching result;
[0127] The deployment module 603 is used to construct a target configuration file according to the target preset parameter information group and the general configuration file, and deploy a target container in a target application environment according to the target configuration file.
[0128] In one embodiment, the matching module 602 is specifically used to match the first environment identifier with the second environment identifier, and determine the target first environment identifier that matches the second environment identifier as a matching result;
[0129] Based on the association relationship between the preset parameter information group and the first environment identifier, a target preset parameter information group corresponding to the target first environment identifier in the matching result is determined.
[0130] In one embodiment, the target preset parameter information group includes candidate parameters and parameter values corresponding to the candidate parameters, and the general configuration file includes variable parameters; the deployment module 603 is specifically used to determine the target parameters in the candidate parameters and the target parameter values corresponding to the target parameters based on the variable parameters in the general configuration file and the candidate parameters in the target preset parameter information group;
[0131] Build a target profile based on target parameter values and variable parameters.
[0132] In one embodiment, the deployment module 603 is specifically configured to add the target parameter value as the parameter value corresponding to the variable parameter in the general configuration file to the general configuration file to obtain the target configuration file.
[0133] In one embodiment, the deployment module 603 is specifically used to mount the target configuration file into the target container according to the mount path of the target configuration file in response to the container startup instruction;
[0134] Start the target container in the target application environment according to the startup script and the target configuration file in the target container.
[0135] In one embodiment, the apparatus 600 further includes:
[0136] A second acquisition module is used to acquire a parameter type corresponding to the target container and a preset parameter information group corresponding to each application environment;
[0137] A creation module is used to create a general configuration file according to the default parameters and variable parameters contained in the parameter type corresponding to the target container;
[0138] A generating module, configured to generate a first environment identifier and a preset parameter information group corresponding to each first environment identifier based on a correspondence between each application environment and a preset parameter information group;
[0139] The storage module is used to store the general configuration file, the first environment identifier, the preset parameter information group, and the association relationship between each first environment identifier and the preset parameter information group.
[0140] Each module in the above container deployment device can be implemented in whole or in part by software, hardware, or a combination thereof. Each module can be embedded in or independent of a processor in a computer device in the form of hardware, or can be stored in a memory in a computer device in the form of software, so that the processor can call and execute operations corresponding to each module.
[0141] In an exemplary embodiment, a computer device is provided. The computer device may be a terminal, and its internal structure diagram may be as shown in FIG. Figure 7As shown. The computer device includes a processor, a memory, an input / output interface, a communication interface, a display unit and an input device. Among them, the processor, the memory and the input / output interface are connected through a system bus, and the communication interface, the display unit and the input device are connected to the system bus through the input / output interface. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The input / output interface of the computer device is used to exchange information between the processor and the external device. The communication interface of the computer device is used to communicate with an external terminal in a wired or wireless manner, and the wireless manner can be implemented through WIFI, a mobile cellular network, near field communication (Near Field Communication, NFC) or other technologies. When the computer program is executed by the processor, a container deployment method is implemented. The display unit of the computer device is used to form a visually visible picture, which can be a display screen, a projection device or a virtual reality imaging device. The display screen can be a liquid crystal display screen or an electronic ink display screen, and the input device of the computer device can be a touch layer covering the display screen, or a button, trackball or touchpad set on the computer device shell, or an external keyboard, touchpad or mouse.
[0142] Those skilled in the art will understand that Figure 7 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0143] In an exemplary embodiment, a computer device is provided, including a memory and a processor, wherein a computer program is stored in the memory, and when the processor executes the computer program, the following steps are implemented:
[0144] Obtaining a general configuration file, a preset parameter information group in each application environment, and a second environment identifier corresponding to the target application environment, wherein each preset parameter information group carries a first environment identifier;
[0145] Matching the first environment identifier with the second environment identifier, and determining a target preset parameter information group corresponding to the second environment identifier in each preset parameter information group based on the matching result;
[0146] A target configuration file is constructed according to the target preset parameter information group and the general configuration file, and a target container in a target application environment is deployed according to the target configuration file.
[0147] In one embodiment, when the processor executes the computer program, the processor further implements the following steps:
[0148] Matching the first environment identifier with the second environment identifier, and determining the target first environment identifier that matches the second environment identifier as a matching result;
[0149] Based on the association relationship between the preset parameter information group and the first environment identifier, a target preset parameter information group corresponding to the target first environment identifier in the matching result is determined.
[0150] In one embodiment, when the processor executes the computer program, the processor further implements the following steps:
[0151] Build a target profile based on the target preset parameter information group and the common profile, including:
[0152] Determine, based on the variable parameters in the general configuration file and the candidate parameters in the target preset parameter information group, the target parameters in the candidate parameters and the target parameter values corresponding to the target parameters;
[0153] Build a target profile based on target parameter values and variable parameters.
[0154] In one embodiment, when the processor executes the computer program, the processor further implements the following steps:
[0155] The target parameter value is taken as the parameter value corresponding to the variable parameter in the general configuration file, and is added to the general configuration file to obtain the target configuration file.
[0156] In one embodiment, when the processor executes the computer program, the processor further implements the following steps:
[0157] In response to the container startup instruction, the target configuration file is mounted into the target container according to the mount path of the target configuration file;
[0158] Start the target container in the target application environment according to the startup script and the target configuration file in the target container.
[0159] In one embodiment, when the processor executes the computer program, the processor further implements the following steps:
[0160] Obtain the parameter type corresponding to the target container and the preset parameter information group corresponding to each application environment;
[0161] Create a general configuration file based on the default parameters and variable parameters contained in the parameter type corresponding to the target container;
[0162] Based on the correspondence between each application environment and the preset parameter information group, generate a first environment identifier and a preset parameter information group corresponding to each first environment identifier;
[0163] The general configuration file, the first environment identifier, the preset parameter information group, and the association relationship between each first environment identifier and the preset parameter information group are stored.
[0164] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the steps in the above-mentioned method embodiments are implemented.
[0165] In one embodiment, a computer program product is provided, including a computer program, which implements the steps in the above method embodiments when executed by a processor.
[0166] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with relevant regulations.
[0167] A person of ordinary skill in the art can understand that all or part of the processes in the above-mentioned embodiment method can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to the memory, database or other medium used in the embodiments provided in the present application can include at least one of non-volatile memory and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM). The database involved in each embodiment provided in this application may include at least one of a relational database and a non-relational database. Non-relational databases may include distributed databases based on blockchains, etc., but are not limited to this. The processor involved in each embodiment provided in this application may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, an artificial intelligence (AI) processor, etc., but are not limited to this.
[0168] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this application.
[0169] The above-described embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the present application. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the attached claims.
Claims
1. A container deployment method, characterized in that: The method comprises: Obtaining a general configuration file, a preset parameter information group in each application environment, and a second environment identifier corresponding to the target application environment, each of the preset parameter information groups carrying a first environment identifier; Matching the first environment identifier with the second environment identifier, and determining a target preset parameter information group corresponding to the second environment identifier in each of the preset parameter information groups based on the matching result; A target configuration file is constructed according to the target preset parameter information group and the general configuration file, and a target container in the target application environment is deployed according to the target configuration file.
2. The method according to claim 1, characterized in that: The matching of the first environment identifier and the second environment identifier, and determining a target preset parameter information group corresponding to the second environment identifier in each preset parameter information group based on the matching result, includes: Matching the first environment identifier with the second environment identifier, and determining the target first environment identifier that matches the second environment identifier as a matching result; Based on the association relationship between the preset parameter information group and the first environment identifier, a target preset parameter information group corresponding to the target first environment identifier in the matching result is determined.
3. The method according to claim 1, characterized in that The target preset parameter information group includes candidate parameters and parameter values corresponding to the candidate parameters, and the general configuration file includes variable parameters; The step of constructing a target configuration file according to the target preset parameter information group and the general configuration file includes: Based on the variable parameters in the general configuration file and the candidate parameters in the target preset parameter information group, determining a target parameter in the candidate parameters and a target parameter value corresponding to the target parameter; A target configuration file is constructed according to the target parameter value and the variable parameters.
4. The method according to claim 3, characterized in that The step of constructing a target configuration file according to the target parameter value and the variable parameter includes: The target parameter value is used as the parameter value corresponding to the variable parameter in the general configuration file, and is added to the general configuration file to obtain the target configuration file.
5. The method according to claim 1, characterized in that The step of deploying the target container in the target application environment according to the target configuration file includes: In response to a container startup instruction, mounting the target configuration file into the target container according to a mount path of the target configuration file; The target container in the target application environment is started according to the startup script and the target configuration file in the target container.
6. The method according to claim 1, characterized in that Before obtaining the common configuration file and the preset parameter information groups in each application environment and the second environment identifier corresponding to the target application environment, and each of the preset parameter information groups carries the first environment identifier, the method further includes: Obtain the parameter type corresponding to the target container and the preset parameter information group corresponding to each application environment; Creating a general configuration file according to the default parameters and variable parameters included in the parameter type corresponding to the target container; Based on the correspondence between each of the application environments and the preset parameter information groups, generating a first environment identifier and the preset parameter information groups corresponding to each of the first environment identifiers; The general configuration file, the first environment identifier, the preset parameter information group, and the association relationship between each of the first environment identifiers and the preset parameter information group are stored.
7. A container deployment device, characterized in that: The device comprises: A first acquisition module is used to acquire a common configuration file, a preset parameter information group in each application environment, and a second environment identifier corresponding to the target application environment, each of the preset parameter information groups carrying a first environment identifier; a matching module, configured to match the first environment identifier with the second environment identifier, and determine, based on the matching result, a target preset parameter information group corresponding to the second environment identifier in each of the preset parameter information groups; A deployment module is used to construct a target configuration file according to the target preset parameter information group and the general configuration file, and deploy a target container in the target application environment according to the target configuration file.
8. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 6 are implemented.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 6 are implemented.
10. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 6 are implemented.
Citation Information
Patent Citations
Cloud service construction method and device
CN113672351A
Application delivery method and device, computer equipment and storage medium
CN117648121A
Application deployment method and device and computer readable storage medium
CN117762427A
Container deployment method and device, electronic equipment and storage medium
CN118227252A
Configuration method and apparatus for pod, device, and nonvolatile readable storage medium
WO2024113819A1