A container application deployment method, apparatus, electronic device, and storage medium.
By combining dynamic and static configuration information, using Ansible's scripts and roles, combined with databases and file systems, we solve the problems of cumbersomeness and single function of existing tools in container application deployment, and realize the efficiency and convenience of container applications. , reliable deployment, suitable for stand-alone and cluster environments.
Patent Information
- Application Number
- CN202011201558.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-11-02
- Publication Date
- 2024-08-23
- Estimated Expiration
- 2040-11-02
AI Technical Summary
Existing container application deployment tools, such as Kubernetes, Ansible, Puppet, and SaltStack, have problems such as cumbersome implementation, single functions, and increased operation and maintenance costs and error rates. They are particularly ineffective in stand-alone or small cluster environments.
Adopting a composite configuration method of dynamic configuration information and static configuration information, through Ansible's Playbook and Role, combined with the database and file system, automatic deployment of container applications is realized, a graphical page is provided to receive dynamic configuration information, and the database is used to store static configuration information to ensure deployment consistency.
It achieves efficient, convenient and reliable deployment of container applications, is suitable for stand-alone and cluster environments, reduces operation and maintenance costs, improves deployment consistency and flexibility, and is especially suitable for complex container applications.
Smart Images

Figure CN112346818B
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a container application deployment method, device, electronic device and storage medium. Background Art
[0002] Implementing applications in a containerized manner, that is, container applications, is the choice of more and more companies. The deployment of container applications is also the focus of operation and maintenance. At present, there are many tools such as Ansible, Puppet, SaltStack, and Kubernetes, but they all have some shortcomings. For example, Kubernetes is relatively cumbersome to implement and cannot play a big advantage on a single machine or a small cluster. The functions of Ansible, Puppet, SaltStack, etc. are relatively simple, which increases the cost of operation and maintenance and the error rate. Summary of the invention
[0003] The embodiments of the present application provide a container application deployment method, device, electronic device and storage medium to achieve efficient, convenient and highly reliable container application deployment.
[0004] The present application embodiment adopts the following technical solutions:
[0005] In a first aspect, an embodiment of the present application provides a container application deployment method, comprising: saving dynamic configuration information of the container application to a configuration file of a script, the script comprising multiple roles, each role corresponding to a container application; in response to a container application deployment request, reading static configuration information of the container application from a database, and reading the script from a file system; and deploying the container application according to the static configuration information and the script.
[0006] Optionally, saving the dynamic configuration information of the container application to the configuration file of the script includes: receiving the dynamic configuration information of the container application according to a graphical page, the entrance of the graphical page is implemented according to a preset TCP port, and the data storage service of the graphical page is implemented based on the database.
[0007] Optionally, the container application deployment method further includes: saving at least part of the dynamic configuration information in the database as static configuration information, and / or reading at least part of the static configuration information from the database and saving it in the configuration file.
[0008] Optionally, the deploying the container application according to the static configuration information and the script includes: determining a deployment status of a target container application; and if the target container application has been deployed, skipping the deployment of the target container application.
[0009] Optionally, determining the deployment status of the target container application includes: accessing a network address of the target container application to obtain a status code of the target container application; and determining the deployment status of the target container application according to the status code.
[0010] Optionally, the container application deployment method further includes: providing a script template, the script template including at least one role template; and saving a script generated according to the script template in the file system.
[0011] Optionally, the container application includes a container orchestration management application, so that the deployed container application has a container orchestration management function.
[0012] In a second aspect, an embodiment of the present application further provides a container application deployment device for implementing any of the container application deployment methods described above.
[0013] In a third aspect, an embodiment of the present application further provides an electronic device, comprising: a processor; and a memory arranged to store computer executable instructions, wherein when the executable instructions are executed, the processor executes any of the container application deployment methods described above.
[0014] In a fourth aspect, an embodiment of the present application further provides a computer-readable storage medium storing one or more programs, which, when executed by an electronic device including multiple application programs, enables the electronic device to execute any of the container application deployment methods described above.
[0015] At least one of the above technical solutions adopted in the embodiments of the present application can achieve the following beneficial effects:
[0016] The composite configuration method of dynamic configuration information and static configuration information is adopted, based on Ansible's Playbook and Role, to achieve the automatic deployment of container applications. Dynamic configuration information makes the deployment of container applications more flexible, while static configuration information eliminates the need to repeatedly provide some fixed dependent information during container deployment. The idempotence of Playbook can ensure the consistency of deployment of container applications in the cluster, and is also suitable for stand-alone deployment, especially for more complex container applications. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:
[0018] Figure 1 A schematic diagram of a process of deploying a container application according to an embodiment of the present application;
[0019] Figure 2 This is a schematic diagram of the structure of an electronic device in an embodiment of the present application. DETAILED DESCRIPTION
[0020] In order to make the purpose, technical solution and advantages of the present application clearer, the technical solution of the present application will be clearly and completely described below in combination with the specific embodiments of the present application and the corresponding drawings. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present application.
[0021] The technical concept of this application is to use Ansible as a basis, use the configuration file of the container application as part of the playbook, and store static configuration information in a database for multiple reuse, thereby realizing flexible and integrated deployment of complex container applications.
[0022] The technical solutions provided by various embodiments of the present application are described in detail below in conjunction with the accompanying drawings.
[0023] Figure 1 FIG. 1 is a flow chart of a container application deployment method according to an embodiment of the present application. Figure 1 As shown, the container application deployment method includes:
[0024] Step S110, saving the dynamic configuration information of the container application into a configuration file of the script, where the script includes multiple roles, and each role corresponds to a container application.
[0025] The script may refer to the Playbook in Ansible, or other tools that can achieve similar functions. Playbook can describe the Role through YAML (a serialization format), and multiple roles can be included in the directory structure of a Playbook. Each role in the Playbook can be called independently and repeatedly. When calling a role, you only need to read the content under the corresponding role directory and apply it. In the embodiment of the present application, each role corresponds to a container application, so that the container application can be deployed on multiple hosts at the same time. Due to the idempotence of Ansible (multiple executions can obtain the same results), the container applications deployed on each host can remain consistent.
[0026] The dynamic configuration information here can be information that needs to be set separately during each container application deployment process, such as but not limited to the host IP address of the deployed application, login password, SSH connection port, deployment path, port for deploying the container application, service image, etc. If the container application is deployed in a cluster, a virtual IP address is usually required.
[0027] Dynamic configuration information can be saved in the script's configuration file. The script usually has a tree-like directory structure, and the configuration file is stored under one of the directory nodes.
[0028] Step S120, in response to the container application deployment request, read the static configuration information of the container application from the database, and read the script from the file system.
[0029] The database may store relatively fixed information that can be used in multiple container deployments, such as but not limited to the service's image address, deployment steps, deployment model (stand-alone deployment or cluster deployment), logical volumes, exposed ports, etc.
[0030] In some embodiments, the database can be implemented using Python's SQlite3 module, which not only meets the requirements but also has the characteristics of being lightweight. When the code is implemented with a Python framework, there is no need to install a database additionally, thus saving computing resources.
[0031] Step S130, deploying the container application according to the static configuration information and the script.
[0032] The container application can be deployed according to the configured deployment mode (standalone or cluster, synchronous or asynchronous, etc.). The role directory can contain configurations that control the container structure and environment variables that need to be included in the container.
[0033] Specifically, you can log in to the corresponding host based on the host IP address, login password, SSH connection port and other information where the application is deployed, and use the configuration information for controlling the container structure contained in the role directory, as well as the environment variables that need to be passed into the container, such as the deployment path, the port for deploying the container application, the service image, etc., combined with the deployment steps, deployment model and other information in the static configuration information, to create a container accordingly, and deploy the application in the created container, thereby realizing the containerization of the application and realizing the deployment of the container application.
[0034] visible, Figure 1 The method shown in the figure uses a composite configuration method of dynamic configuration information and static configuration information, based on Ansible's Playbook and Role, to achieve automated deployment of container applications. Dynamic configuration information makes the deployment of container applications more flexible, while static configuration information eliminates the need to repeatedly provide some fixed dependent information during container deployment. The idempotence of Playbook ensures the consistency of deployment of container applications in the cluster, and is also suitable for stand-alone deployment, especially for more complex container applications.
[0035] In one embodiment of the present application, in the above-mentioned container application deployment method, saving the dynamic configuration information of the container application to the configuration file of the script includes: receiving the dynamic configuration information of the container application according to a graphical page, the entrance of the graphical page is implemented according to a preset TCP port, and the data storage service of the graphical page is implemented based on a database.
[0036] Ansible lacks a graphical operating interface, which increases the difficulty of operation and maintenance. The embodiment of the present application also proposes a solution for receiving dynamic configuration information through a graphical page to facilitate deployment. To this end, it is only necessary to open a preset TCP port in the server in advance as the entrance to the graphical page to access the graphical page. The implementation method of the graphical page is also not complicated. For example, the Flask micro Python framework can be used as the basic framework, and the view function can be associated using the blueprint concept of Flask to realize the UI (User Interface, user interaction interface) of the graphical page.
[0037] The data storage service relied upon can be implemented based on the same database as the aforementioned embodiment, without the need to set up an additional database. The database can store corresponding data of the UI, such as the title and the like.
[0038] To improve security, you can also use graphical pages to implement user verification functions to ensure that only the right people can deploy containers. Similarly, you can rely on the same database for data storage, and use tools such as webzeug to implement login verification, routing parsing, web exception encapsulation and other functions. Use SQLAlchemy to implement SQL functions and have flexibility. Use Gunicorn service to implement server gateway interface, which is lightweight, easy to implement and high-performance. If you use Python for development, you can also integrate Python modules such as os, sys, time, json, and waterl to implement the corresponding functions.
[0039] It should be noted that the above are only some feasible implementation examples of the graphical page, and other methods may be used to implement it according to requirements in other embodiments.
[0040] In one embodiment of the present application, the container application deployment method further includes: saving at least part of the dynamic configuration information in a database as static configuration information, and / or reading at least part of the static configuration information from the database and saving it in a configuration file.
[0041] In some cases, dynamic configuration information can be obtained when a specific container application is deployed, while static configuration information can be more versatile and pre-configured. If part or all of the dynamic configuration information can be used repeatedly in subsequent container application deployments, this information can be saved directly to the database, such as service image information. Similarly, some static configuration information in the database can also be saved to the script configuration file as needed to facilitate deployment, such as the container's port, name, etc.
[0042] It can be seen that the dynamic and static configuration information are relative. In addition, the two are used in different ways when deploying container applications. Specifically, the configuration file can be called through the Python os module, and the static configuration information in the database can be accessed through the SQlite3 module.
[0043] In one embodiment of the present application, in the above-mentioned container application deployment method, deploying the container application according to the static configuration information and the script includes: determining the deployment status of the target container application; if the target container application has been deployed, skipping the deployment of the target container application.
[0044] During the deployment of container applications, some container applications may have been deployed, and there is no need to redeploy them. The technical solution of the present application can be used for batch deployment of multiple container applications. In one example, when the first container application is deployed and the second container application is ready to be deployed, the deployment status of the second container application can be determined first. If it has been deployed, it is skipped, and the deployment status of the third container application is determined until a container application that has not been deployed is determined, and then it can be deployed.
[0045] Specifically, in one embodiment, determining the deployment status of the target container application includes: accessing the network address of the target container application to obtain a status code of the target container application; and determining the deployment status of the target container application according to the status code.
[0046] The container application has a network address url. In this embodiment, a status code can be obtained by accessing it. For example, a status code of 200 indicates that the container application has been deployed. If a status code other than 200 is obtained or no status code is obtained within a predetermined time, it is considered that the container application is not deployed and deployment can be started.
[0047] In one embodiment of the present application, in the above-mentioned container application deployment method, the container application deployment method also includes: providing a script template, the script template includes at least one role template; and saving a script generated according to the script template in a file system.
[0048] The embodiment of the present application also allows users to customize container applications through script templates to obtain customized scripts for container applications, which are suitable for different scenarios that require different container applications, different service structures, etc. Specifically, users can complete a new container application by copying the role template and modifying the configuration and environment variables in the tasks, var, defalts and other directories. In the conf directory, modify the configuration files that control the deployment order and quantity, define the number of hosts required for deployment and the distribution of container applications on each host, and complete the script of the new container application.
[0049] In one embodiment of the present application, in the above container application deployment method, the container application may include a container orchestration management application, so that the deployed container application has a container orchestration management function.
[0050] For example, the container orchestration management application can be Rancher, and other applications can also be selected in other embodiments. The advantage of this is that it makes up for the disadvantage that Ansible cannot implement container orchestration management, and can support service upgrade rollback, container image management, log viewing, etc., which improves the stability of operation and maintenance.
[0051] Of course, if the container orchestration management function is not needed, or the container orchestration management application has already been deployed, there is no need to redeploy the container orchestration management application.
[0052] An embodiment of the present application further provides a container application deployment device, which can implement the various steps of the container application deployment method provided in the aforementioned embodiment. The relevant explanations about the container application deployment method are applicable to the container application deployment device and will not be repeated here.
[0053] Figure 2 This is a schematic diagram of the structure of an electronic device according to an embodiment of the present application. Figure 2 At the hardware level, the electronic device includes a processor, and optionally also includes an internal bus, a network interface, and a memory. The memory may include a memory, such as a high-speed random access memory (RAM), and may also include a non-volatile memory (non-volatile memory), such as at least one disk storage. Of course, the electronic device may also include hardware required for other services.
[0054] The processor, network interface and memory can be interconnected through an internal bus, which can be an ISA (Industry Standard Architecture) bus, a PCI (Peripheral Component Interconnect) bus or an EISA (Extended Industry Standard Architecture) bus. The bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 2 Only one bidirectional arrow is used in the diagram, but this does not mean that there is only one bus or only one type of bus.
[0055] The memory is used to store the program. Specifically, the program may include a program code, and the program code includes a computer operation instruction. The memory may include a memory and a non-volatile memory, and provides instructions and data to the processor.
[0056] The processor reads the corresponding computer program from the non-volatile memory into the memory and then runs it, forming a container application deployment device at the logical level. The processor executes the program stored in the memory and is specifically used to execute:
[0057] The dynamic configuration information of the container application is saved in the configuration file of the script, where the script includes multiple roles, each role corresponds to a container application; in response to the container application deployment request, the static configuration information of the container application is read from the database, and the script is read from the file system; step S130, the container application is deployed according to the static configuration information and the script.
[0058] The container application deployment method executed by the container application deployment device can be applied to a processor or implemented by a processor. The processor may be an integrated circuit chip with signal processing capabilities. In the implementation process, each step of the above method can be completed by an integrated logic circuit of hardware in the processor or an instruction in software form. The above processor can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components. The methods, steps and logic block diagrams disclosed in the embodiments of the present application can be implemented or executed. The general processor can be a microprocessor or the processor can also be any conventional processor, etc. The steps of the method disclosed in the embodiments of the present application can be directly embodied as a hardware decoding processor for execution, or a combination of hardware and software modules in the decoding processor for execution. The software module can be located in a storage medium mature in the art such as a random access memory, a flash memory, a read-only memory, a programmable read-only memory, or an electrically erasable programmable memory, a register, etc. The storage medium is located in the memory, and the processor reads the information in the memory and completes the steps of the above method in combination with its hardware.
[0059] The electronic device may also perform Figure 1 In the container application deployment method, and implement the container application deployment method in Figure 1 The functions of the illustrated embodiment will not be described in detail in the embodiments of the present application.
[0060] The present application also provides a computer-readable storage medium, which stores one or more programs, wherein the one or more programs include instructions, which, when executed by an electronic device including multiple application programs, enable the electronic device to execute Figure 1 The container application deployment method in the illustrated embodiment is specifically used to execute:
[0061] The dynamic configuration information of the container application is saved in the configuration file of the script, where the script includes multiple roles, each role corresponds to a container application; in response to the container application deployment request, the static configuration information of the container application is read from the database, and the script is read from the file system; step S130, the container application is deployed according to the static configuration information and the script.
[0062] Those skilled in the art will appreciate that embodiments of the present invention may be provided as methods, systems, or computer program products. Therefore, the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the present invention may take 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.) containing computer-usable program code.
[0063] The present invention is described with reference to flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of processes and / or blocks 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 produce 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.
[0064] 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.
[0065] 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.
[0066] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.
[0067] The memory may include non-permanent storage in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. The memory is an example of a computer-readable medium.
[0068] Computer readable media include permanent and non-permanent, removable and non-removable media that can be implemented by any method or technology to store information. Information can be computer readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, magnetic tape magnetic disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer readable media does not include temporary computer readable media (transitory media), such as modulated data signals and carrier waves.
[0069] It should also be noted that the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, commodity or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, commodity or device. In the absence of more restrictions, the elements defined by the sentence "comprises a ..." do not exclude the existence of other identical elements in the process, method, commodity or device including the elements.
[0070] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment or an embodiment in combination with software and hardware. Moreover, the present application may 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.
[0071] The above is only an embodiment of the present application and is not intended to limit the present application. For those skilled in the art, the present application may have various changes and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application should be included in the scope of the claims of the present application.
Claims
1. A container application deployment method, It is characterized in that include: Saving the dynamic configuration information of the container application to a configuration file of a script, wherein the script includes multiple roles, each role corresponding to a container application; Saving the dynamic configuration information of the container application to the configuration file of the script includes: Receiving dynamic configuration information of the container application according to a graphical page, wherein the entry of the graphical page is implemented according to a preset TCP port, and the data storage service of the graphical page is implemented based on a database; The dynamic configuration information includes one or more of the host IP address, login password, SSH connection port, deployment path, port for deploying container application, service image, and virtual IP address of the deployed application; In response to a container application deployment request, read static configuration information of the container application from a database, and read the script from a file system; The static configuration information includes one or more of the service's image address, deployment steps, deployment model, logical volume, and exposed port; Deploy the container application according to the static configuration information and the script; The method further comprises: At least part of the dynamic configuration information is saved in the database as static configuration information, and / or at least part of the static configuration information is read from the database and saved in the configuration file.
2. The container application deployment method according to claim 1, It is characterized in that The deploying of the container application according to the static configuration information and the script includes: Determine the deployment status of the target container application; If the target container application has been deployed, the deployment of the target container application is skipped.
3. The container application deployment method according to claim 2, It is characterized in that Determining the deployment status of the target container application includes: Access the network address of the target container application to obtain the status code of the target container application; The deployment status of the target container application is determined according to the status code.
4. The container application deployment method according to claim 1, It is characterized in that The container application deployment method further includes: Providing a script template, wherein the script template includes at least one role template; The script generated according to the script template is saved in the file system.
5. The container application deployment method according to claim 1, It is characterized in that The container application includes a container orchestration management application, so that the deployed container application has a container orchestration management function.
6. A container application deployment device, It is characterized in that The container application deployment device is used to implement any one of the methods of claims 1 to 5.
7. An electronic device, include: processor; as well as A memory arranged to store computer executable instructions, which when executed cause the processor to perform the method of any one of claims 1 to 5.
8. A computer-readable storage medium storing one or more programs, which, when executed by an electronic device including a plurality of application programs, causes the electronic device to execute any one of the methods of claims 1 to 5.
