Service containerization deployment method and device, computer equipment and storage medium
By storing service deployment requests and generating task queues, service configuration files are automatically generated and deployed to the cluster, which solves the problem of low container deployment efficiency in the existing technology and improves deployment efficiency.
Patent Information
- Application Number
- CN202410668294.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-27
- Publication Date
- 2024-09-17
AI Technical Summary
In the existing technology, container deployment relies on human-written script files, which is prone to errors, resulting in low container deployment efficiency and lack of effective solutions.
By obtaining the user's service deployment request, storing the deployment information in the database, generating tasks and adding them to the task queue, automatically generating a service configuration file that conforms to the current environment based on changes in the task queue, and deploying the service to the cluster.
It realizes the automatic generation of service configuration files without manual intervention, improves the efficiency of container deployment, and solves the problem of deployment failure caused by script file errors.
Smart Images

Figure CN118656084A
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a method, apparatus, computer device, and storage medium for deploying service containerization. Background Art
[0002] Container technology is a technical solution for application deployment and the cornerstone of the cloud native technology stack. New software applications are basically deployed in containers and distributed on different servers. The scheduling, allocation, and management of containers are called container orchestration technology. Current container orchestration engines (software) include Docker and Kubernetes (k8s for short).
[0003] At present, the realization of service containerization mainly relies on manually written script files for building application containers; for example: in the docker environment, the realization of service containerization relies on manually written docker-compose.yml script files, and then deploys and maintains through docker API or docker commands, and determines whether the service deployment is successful by constantly querying the service deployment and running status. In the k8s environment, it also relies on manually written configuration files such as deployment.yml, service.yaml, and pvc.yaml, and calls the k8s apiserver for deployment and maintenance by executing the kubectl command. However, script files not only have high format requirements, but also involve the understanding and application of multiple commands, which makes manually written script files prone to errors, resulting in low container deployment efficiency.
[0004] There are errors in script files in related technologies that cause container deployment failure, resulting in low container deployment efficiency. Currently, no effective solution has been proposed. Summary of the invention
[0005] In this embodiment, a service containerized deployment method, apparatus, computer device, and storage medium are provided to solve the problem in the related art that errors in script files cause container deployment failure, resulting in low container deployment efficiency.
[0006] In a first aspect, a service container deployment method is provided in this embodiment, including:
[0007] Obtaining a deployment request initiated by a user for service deployment, and storing the service deployment information in the deployment request in a database;
[0008] Based on the deployment request, a corresponding task is generated, and the task is added to a task queue; each task in the task queue corresponds to a key-value pair;
[0009] When the task queue changes, the corresponding service deployment information is obtained from the database based on the task; a service configuration file that conforms to the current environment is generated according to the service deployment information and a preset configuration template;
[0010] Based on the service configuration file, the service is deployed to the cluster of the current environment.
[0011] In some embodiments, the method further comprises:
[0012] In a K8s environment, a host in the cluster of the K8s environment is selected to listen to the pushed task queue, and when the task in the task queue is added or changed, it is determined that the task queue has changed;
[0013] Or, in a Docker environment, all hosts in the cluster of the Docker environment simultaneously monitor the pushed task queue, and when the task in the task queue is added or changed, it is determined that the task queue has changed.
[0014] In some embodiments, the method further comprises:
[0015] In a K8s environment, a host in the cluster of the K8s environment is selected, and a key value of a key-value pair in the task queue is periodically queried, and when the key value changes, it is determined that the task queue has changed;
[0016] Or, in a Docker environment, all hosts in the cluster of the Docker environment are used to query the key value of the key-value pair in the task queue at the same time, and when the key value changes, it is determined that the task queue has changed.
[0017] In some embodiments, generating a corresponding task based on the deployment request and adding the task to a task queue includes:
[0018] Based on the deployment request, generate a corresponding task;
[0019] Based on the Key Watch mechanism of the etcd service, the task is added to the task queue.
[0020] In some of the embodiments, generating a service configuration file that conforms to the current environment according to the service deployment information and the preset configuration template includes:
[0021] In a K8s environment or a Docker environment, the service deployment information is filled into the preset configuration template according to a preset format to generate a service configuration file that conforms to the current environment.
[0022] In some embodiments, the method further comprises:
[0023] Query the service status of the service operation according to the preset time and preset query number;
[0024] Determining whether the version of the service is consistent according to the service status and the service deployment information in the database;
[0025] If they are consistent, check the health status of the service and obtain the health status information;
[0026] If not consistent, the service is redeployed or upgraded.
[0027] In some embodiments, the method further comprises:
[0028] Receiving the reported health status information;
[0029] The health status information is stored in the database, and the health status information in the database is managed according to the time of receipt.
[0030] In a second aspect, a service container deployment device is provided in this embodiment, including:
[0031] An acquisition module is used to acquire a deployment request initiated by a user for service deployment, and store the service deployment information in the deployment request in a database;
[0032] A processing module, used for generating a corresponding task based on the deployment request, and adding the task to a task queue; each task in the task queue corresponds to a key-value pair;
[0033] A configuration module, configured to obtain the corresponding service deployment information from the database based on the task when the task queue changes; and generate a service configuration file that conforms to the current environment according to the service deployment information and a preset configuration template;
[0034] A management module is used to deploy the service to the cluster of the current environment based on the service configuration file.
[0035] In a third aspect, a computer device is provided in this embodiment, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, the service containerization deployment method described in the first aspect is implemented.
[0036] In a fourth aspect, a storage medium is provided in this embodiment, on which a computer program is stored, and when the program is executed by a processor, the service containerization deployment method described in the first aspect is implemented.
[0037] Compared with the related art, the service containerized deployment method, apparatus, computer equipment and storage medium provided in this embodiment obtain a deployment request for service deployment initiated by a user, and store the service deployment information in the deployment request in a database; based on the deployment request, generate a corresponding task, and add the task to a task queue; each task in the task queue corresponds to a pair of key-value pairs; when the task queue changes, obtain the corresponding service deployment information from the database based on the task; generate a service configuration file that conforms to the current environment according to the service deployment information and a preset configuration template; based on the service configuration file, deploy the service to the cluster of the current environment, thereby solving the problem in the related art that errors in script files cause container deployment to fail, resulting in low container deployment efficiency, and realizes automatic generation of service configuration files that conform to the current environment, and completes the deployment of service containers to the cluster of the current environment, thereby improving deployment efficiency.
[0038] Details of one or more embodiments of the present application are set forth in the following drawings and description to make other features, objects, and advantages of the present application more readily apparent. BRIEF DESCRIPTION OF THE DRAWINGS
[0039] 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:
[0040] Figure 1 It is a hardware structure block diagram of a terminal device of a service container deployment method provided in an embodiment of the present application;
[0041] Figure 2 It is a flowchart of a method for deploying service containerization provided by an embodiment of the present application;
[0042] Figure 3 is a flowchart of step S220;
[0043] Figure 4 It is a flowchart of a method for deploying service containerization provided by a preferred embodiment of the present application;
[0044] Figure 5 It is a structural block diagram of a service containerized deployment device provided in an embodiment of the present application.
[0045] In the figure: 102, processor; 104, memory; 106, transmission device; 108, input and output device; 210, acquisition module; 220, processing module; 230, configuration module; 240, management module. DETAILED DESCRIPTION
[0046] In order to more clearly understand the purpose, technical solutions and advantages of the present application, the present application is described and illustrated below in conjunction with the accompanying drawings and embodiments.
[0047] Unless otherwise defined, the technical terms or scientific terms involved in this application shall have the general meaning understood by people with ordinary skills in the technical field to which this application belongs. The words "one", "a", "a", "the", "these" and the like in this application do not represent quantitative restrictions, and they can be singular or plural. The terms "include", "comprise", "have" and any variants thereof involved in this application are intended to cover non-exclusive inclusions; for example, a process, method and system, product or device comprising a series of steps or modules (units) is not limited to the listed steps or modules (units), but may include unlisted steps or modules (units), or may include other steps or modules (units) inherent to these processes, methods, products or devices. The words "connect", "connected", "coupled" and the like involved in this application are not limited to physical or mechanical connections, but may include electrical connections, whether directly or indirectly. The "multiple" involved in this application refers to two or more. "And / or" describes the association relationship of associated objects, indicating that there can be three relationships. For example, "A and / or B" can mean: A exists alone, A and B exist at the same time, and B exists alone. Usually, the character " / " indicates that the objects associated with each other are in an "or" relationship. The terms "first", "second", "third", etc. involved in this application are only used to distinguish similar objects and do not represent a specific ordering of the objects.
[0048] The method embodiment provided in this embodiment can be executed in a terminal, a computer or a similar computing device. For example, running on a terminal, Figure 1 is a hardware structure block diagram of a terminal of the service container deployment method of this embodiment. Figure 1 As shown, the terminal may include one or more ( Figure 1 Only one is shown in the figure) processor 102 and memory 104 for storing data, wherein processor 102 may include but is not limited to a processing device such as a microprocessor MCU or a programmable logic device FPGA. The above terminal may also include a transmission device 106 and an input and output device 108 for communication functions. It can be understood by those skilled in the art that Figure 1 The structure shown is only for illustration and does not limit the structure of the above terminal. Figure 1 More or fewer components as shown, or with Figure 1 Different configurations shown.
[0049] The memory 104 can be used to store computer programs, for example, software programs and modules of application software, such as the computer program corresponding to the service container deployment method in this embodiment. The processor 102 executes various functional applications and data processing by running the computer program stored in the memory 104, that is, to implement the above method. The memory 104 may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory 104 may further include a memory remotely arranged relative to the processor 102, and these remote memories may be connected to the terminal via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0050] The transmission device 106 is used to receive or send data via a network. The above network includes a wireless network provided by the communication provider of the terminal. In one example, the transmission device 106 includes a network adapter (Network Interface Controller, referred to as NIC), which can be connected to other network devices through a base station so as to communicate with the Internet. In one example, the transmission device 106 can be a radio frequency (Radio Frequency, referred to as RF) module, which is used to communicate with the Internet wirelessly.
[0051] In this embodiment, a service container deployment method is provided. Figure 2 is a flow chart of the service container deployment method of this embodiment. Figure 2 As shown, the process includes the following steps:
[0052] Step S210, obtaining a deployment request initiated by a user for service deployment, and storing the service deployment information in the deployment request in a database;
[0053] Step S220, based on the deployment request, generate a corresponding task and add the task to a task queue; each task in the task queue corresponds to a key-value pair;
[0054] Step S230, when the task queue changes, the corresponding service deployment information is obtained from the database based on the task; according to the service deployment information and the preset configuration template, a service configuration file that conforms to the current environment is generated;
[0055] Step S240: deploy the service to the cluster of the current environment based on the service configuration file.
[0056] It should be noted that the deployment method of service containerization can be applied to the management system of the K8s environment or the management system of the Docker environment. The management system of the Docker environment includes a platform and a cluster in the Docker environment; the platform is connected to the cluster. Among them, the platform is equipped with a database; the cluster includes at least two hosts, each of which can be considered as a node. The node is the smallest computing hardware unit, which is the representation of a single machine in the cluster. The node is likely to be a physical machine or a virtual machine, and there is no restriction on this. The program (corresponding to the service) is packaged into a container and deployed to the host of the cluster of the current environment, which is service containerization. One or more containers are encapsulated into a high-level structure called Pod, and any container in the same Pod will share the same namespace and local network. Containers can easily communicate with other containers in the same container, similar to maintaining a certain degree of isolation on the same machine at the same time. The main purpose of deployment is to declare how many copies of a Pod should run simultaneously. The management system for the K8s environment is also a similar structure, including the platform and the cluster in the K8s environment, which will not be repeated. Among them, the database can be a Mysql database.
[0057] The deployment request is initiated by the user in the client; for example, the user fills in the service deployment information in the client, and the client generates a deployment request with the service deployment information and transmits it to the platform; the platform obtains the deployment request and stores the service deployment information in the deployment request in the database. The client includes but is not limited to mobile terminals, laptops, and tablets, etc., and there is no restriction on this.
[0058] After receiving the deployment request, the corresponding task will be generated based on the deployment request and added to the task queue. For example: compare the service deployment information in the deployment request with the service deployment information stored in the database, convert the service deployment information in the deployment request into the task message that needs to be deployed, generate the corresponding task according to the task message, and add the task to the task queue. And each task in the task queue is configured with a unique key-value pair, which can be expressed as: Key-Value; Key represents each task, and Value represents the key value corresponding to each task. For another example: take the deployment request as the trigger condition, and directly generate the corresponding task according to the service deployment information in the deployment request.
[0059] Generally speaking, as long as a task is added to the task queue, the task queue will definitely change; at this time, the corresponding service deployment information is obtained from the database based on the task; based on the service deployment information and the preset configuration template, a service configuration file that conforms to the current environment is automatically generated, and no manually written script files are required. Finally, by calling the relevant interface to execute the service configuration file, the service is deployed to the cluster of the current environment to improve the efficiency of container deployment.
[0060] In related technologies, service containerization mainly relies on manually written script files for building application containers; for example, in a docker environment, service containerization relies on manually written docker-compose.yml script files, and then deployment and operation are performed through docker API or docker commands. In a k8s environment, it also relies on manually written configuration files such as deployment.yml, service.yaml, and pvc.yaml, and deployment and operation are performed by executing kubectl commands to call k8sapiserver. However, script files not only have high format requirements, but also involve the understanding and application of multiple commands, which makes manually written script files prone to errors, resulting in low container deployment efficiency; in this embodiment, by obtaining a deployment request for service deployment initiated by a user, the service deployment information in the deployment request is stored in a database; based on the deployment request, a corresponding task is generated, and the task is added to a task queue; each task in the task queue corresponds to a pair of key-value pairs; when the task queue changes, the corresponding service deployment information is obtained from the database based on the task; without the need for manual intervention, a service configuration file that conforms to the current environment is automatically generated according to the service deployment information and a preset configuration template; based on the service configuration file, the service is deployed to the cluster of the current environment, which solves the problem in the related technology that errors in script files cause container deployment to fail, resulting in low container deployment efficiency, and realizes automatic generation of service configuration files that conform to the current environment, and completes the containerized deployment of the service to the cluster of the current environment, thereby improving deployment efficiency.
[0061] Since the service will be deployed to all hosts in the cluster and there are at least two hosts in the cluster, high availability can be achieved by selecting the hosts; users do not need to worry about the underlying container implementation details, and it is convenient for users to update the service deployment version.
[0062] The following is a detailed description of the above steps:
[0063] It should be noted that before obtaining the corresponding service deployment information, it is possible to determine whether the task queue has changed by monitoring or periodic query.
[0064] In some of the embodiments, the service container deployment method further includes the following steps:
[0065] In the K8s environment, select a host in the K8s environment cluster, listen to the pushed task queue, and determine whether the task queue has changed when a task is added or changed in the task queue;
[0066] Or, in a Docker environment, all hosts in the Docker environment cluster simultaneously monitor the pushed task queues, and when tasks are added or changed in the task queues, it is determined that the task queues have changed.
[0067] Specifically, the above process is to determine whether the task queue has changed by monitoring in different current environments.
[0068] The platform's Core service automatically pushes the task queue. When the current environment is a K8s environment, it randomly or specifically selects a container service of a host in the K8s environment cluster, uses the host as a proxy, monitors the task queue, and determines whether the task queue has changed when a task is added or changed in the task queue. If the host acting as a proxy determines that the task queue has changed, the host shares the message with other hosts, so that all hosts can determine whether the task queue has changed.
[0069] The platform's Core service will automatically push the task queue. When the current environment is a docker environment, the container services of all hosts in the docker environment cluster will monitor the task queue at the same time. When tasks are added or changed in the task queue, the task queue is determined to have changed, allowing all hosts to determine whether the task queue has changed.
[0070] Through this embodiment, in different environments, it is possible to determine whether the task queue has changed by monitoring, thereby improving the stability of deployment and operation.
[0071] In some of the embodiments, the service container deployment method further includes the following steps:
[0072] In the K8s environment, select a host in the K8s environment cluster, periodically query the key value of the key-value pair in the task queue, and when the key value changes, it is determined that the task queue has changed.
[0073] Or, in a Docker environment, all hosts in the Docker environment cluster are used to query the key value of the key-value pair in the task queue at the same time, and when the key value changes, it is determined that the task queue has changed.
[0074] Specifically, the above process is to determine whether the task queue has changed by means of timed query under different current environments. The timing can be set according to the usage scenario, such as: query once every 5 seconds, query 10 times, etc., and there is no restriction on this.
[0075] When the current environment is a K8s environment, a container service of a host in the K8s environment cluster is randomly or specifically selected, and the host is used as a proxy to periodically query the key value of the key-value pair in the task queue. Since each task has its corresponding key-value pair, a change in the key value indicates that there is a change in the task in the task queue, and the task queue can be determined to have changed. If the host acting as a proxy determines that the task queue has changed, the host shares the message with other hosts, so that all hosts can determine whether the task queue has changed.
[0076] When the current environment is a docker environment, the key values of the key-value pairs in the task queue are queried simultaneously through the container services of all hosts in the docker environment cluster. When the key values change, it is determined that the task queue has changed, so that all hosts can determine whether the task queue has changed.
[0077] Through this embodiment, in different environments, it is possible to determine whether the task queue has changed by querying, thereby improving the stability of deployment and operation.
[0078] In some of the embodiments, Figure 3 As shown, in step S220, generating a corresponding task based on the deployment request and adding the task to the task queue includes the following steps:
[0079] Step S221, generating corresponding tasks based on the deployment request;
[0080] Step S222: Based on the Key Watch mechanism of the ETCD service, the task is added to the task queue.
[0081] Specifically, the service deployment information in the deployment request includes, but is not limited to, the container image address, the service name, the internal listening port of the service container, and other configuration information required for starting the service container.
[0082] In this embodiment, the service deployment information in the deployment request is compared with the service deployment information stored in the database; if the database stores service deployment information consistent with the deployment request, it means that the service has been deployed, and the process ends directly; if the database does not store service deployment information consistent with the deployment request, it means that it is a new service deployment request, and the service deployment information in the deployment request is converted into a task message that needs to be deployed, and a corresponding task is generated according to the task message; then based on the Key Watch mechanism of the ETCD service, the task is added to the task queue.
[0083] Among them, the Key Watch mechanism means that each time a new task is issued, the key-value pair Key-Value will be changed; Watch monitors one or a group of key-value pairs, and any changes in the key-value pairs will send a message. Based on the Key Watch mechanism of the ETCD service, the process of adding a task to the task queue is as follows: the platform core service publishes the key-value pair Key-Value; each time the core service issues a new task, the key-value pair Key-Value needs to be changed. The agent service in ETCD monitors the changes in the key-value pair and adds the task to the task queue. Among them, Key represents each task, and Value represents the key value corresponding to each task. The information stored in the key includes but is not limited to: taskId: 1, # indicates the ID of the task issued by the user stored in the database (each user has his own ID); action: "deploy", # the action of the task, deploy: deployment, update: update, delete: delete; "replicate": 2, # the number of replicas started by the service container; version: 1 # indicates the last changed version of the task. Each time the service of this task is updated, the version field will be +1, and the version field will be used as the label of the container. The label version on the running container will be checked later to see if it is consistent with the expected version. If it is inconsistent, it will be automatically updated to the latest version; etc.
[0084] Through this embodiment, the Key Watch mechanism of the ETCD service is used to reliably and stably add tasks to the task queue.
[0085] In some embodiments, generating a service configuration file that meets the current environment according to the service deployment information and the preset configuration template in step S230 includes the following steps:
[0086] In a K8s environment or a Docker environment, fill in the service deployment information into the preset configuration template according to the preset format to generate a service configuration file that meets the current environment.
[0087] Specifically, the configuration template is a pre-selected setting related to the current environment. You can think of the configuration template for the K8s environment as the K8s configuration template, and the configuration template for the Docker environment as the Docker configuration template.
[0088] For the Docker environment, the service deployment information is mainly filled into the Docker configuration template according to the preset format to generate a service configuration file that conforms to the Docker environment.
[0089] For example, the service configuration file generated by the Docker configuration template that conforms to the Docker environment is as follows:
[0090]
[0091]
[0092] Through this embodiment, a service configuration file that meets the current environment can be automatically generated quickly and accurately without manual intervention.
[0093] In other embodiments, a similar principle may be adopted to fill the service deployment information into a service configuration file that conforms to the K8s environment and is generated by the K8s configuration template according to a preset format, which will not be repeated here.
[0094] In some of the embodiments, the service container deployment method further includes the following steps:
[0095] Query the service status of the service operation according to the preset time and preset query number;
[0096] Determine whether the service version is consistent based on the service status and service deployment information in the database;
[0097] If they are consistent, check the health status of the service and obtain the health status information;
[0098] If they are inconsistent, redeploy or upgrade the service.
[0099] Specifically, after the service is deployed, it will be checked regularly to see if the deployed service status is consistent with the user's expected status in the task queue. For example: when the service is started for the first time, wait 10 seconds before checking the service status to avoid false reports of unavailable services when the service status is not successfully started; then query the service status of the running service according to the preset time (interval: 10s) and the preset number of queries (retries: 5); compare the queried service status with the service status in the service deployment information in the database to determine whether the service version is consistent; if they are consistent, check the health status of the service to obtain health status information; if they are inconsistent, redeploy or upgrade the service.
[0100] The health status of the inspection service may be the "inspect" information of the inspection service, which has a Health.Status field. If Health exists, the health status information is healthy; otherwise, the health status information is unhealthy.
[0101] Through this embodiment, the consistency of service deployment versions is guaranteed, facilitating subsequent operation and maintenance.
[0102] In some of the embodiments, the service container deployment method further includes the following steps:
[0103] Receive reported health status information;
[0104] The health status information is stored in a database and managed according to the receiving time.
[0105] Specifically, the platform's Core service will receive reported health status information and then store the health status information in the database. In order to avoid too much data stored in the database, the health status information in the database is managed according to the receiving time. For example, only the health status information of the current service for the most recent period of time is stored.
[0106] The present embodiment is described and illustrated below through preferred embodiments.
[0107] like Figure 4 As shown, the preferred embodiment is in a Docker environment and specifically includes the following steps:
[0108] 1. The user performs update management of service deployment and initiates a deployment request. 2. The platform's Core service obtains the deployment request, stores the service deployment information in the deployment request into the Mysql database, and updates the configuration details in the Mysql database. 3. Based on the deployment request, the corresponding task is generated, the task is added to the task queue, and the task queue is issued. 4. All hosts listen to the pushed task queue at the same time. When a task is added or changed in the task queue, the task queue is determined to have changed. 5. Or, all hosts query the key value of the key-value pair in the task queue at the same time. When the key value changes, the task queue is determined to have changed. 6.1. Determine whether the service version is consistent based on the service status and the service deployment information in the Mysql database; 6.2. If inconsistent, deploy, update or delete the corresponding service; 6.3. If consistent, check the health status of the service and obtain health status information. 7.1. Report the service status of the service operation; 7.2. Store the health status information of the service status.
[0109] In this preferred embodiment, the management of tasks can be achieved by initiating a management request (deployment, update or deletion) in combination with the above process.
[0110] Through this preferred embodiment, users do not need to worry about the underlying containerization implementation details, and it is convenient for users to update the service deployment version, which lowers the user's usage threshold; because the service will be deployed to all hosts in the cluster, and there are at least two hosts in the cluster, high availability can be achieved through the selection of hosts, and high-availability deployment / update / deletion of services can be quickly achieved, and the default deployment service supports multi-copy high availability, eliminating the risk of single point failure of the service.
[0111] For the specific implementation in the K8s environment, please refer to the above process and will not be repeated here.
[0112] It should be noted that the steps shown in the above process or the flowchart in the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and although a logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.
[0113] In this embodiment, a service container deployment device is also provided, which is used to implement the above embodiments and preferred implementation modes, and will not be repeated here. The terms "module", "unit", "subunit", etc. used below can implement a combination of software and / or hardware for a predetermined function. Although the devices described in the following embodiments are preferably implemented in software, the implementation of hardware, or a combination of software and hardware, is also possible and conceivable.
[0114] Figure 5 is a structural block diagram of the service container deployment device of this embodiment, such as Figure 5 As shown, the device comprises:
[0115] The acquisition module 210 is used to acquire a deployment request initiated by a user for service deployment, and store the service deployment information in the deployment request into a database;
[0116] The processing module 220 is used to generate a corresponding task based on the deployment request and add the task to a task queue; each task in the task queue corresponds to a key-value pair;
[0117] Configuration module 230, used to obtain corresponding service deployment information from the database based on the task when the task queue changes; generate a service configuration file that meets the current environment according to the service deployment information and the preset configuration template;
[0118] The management module 240 is used to deploy the service to the cluster of the current environment based on the service configuration file.
[0119] Through the above-mentioned device, the problem in the related technology that errors in script files cause container deployment failure and lead to low container deployment efficiency is solved, and the service configuration file that conforms to the current environment is automatically generated, and the service container deployment is completed to the cluster of the current environment, thereby improving the deployment efficiency.
[0120] In some of the embodiments, the service containerized deployment device further includes:
[0121] The monitoring module is used to select a host in the K8s environment cluster in the K8s environment, monitor the pushed task queue, and determine the change of the task queue when a task is added or changed in the task queue;
[0122] Or, in a Docker environment, all hosts in the Docker environment cluster simultaneously monitor the pushed task queues, and when tasks are added or changed in the task queues, it is determined that the task queues have changed.
[0123] In some of the embodiments, the service containerized deployment device further includes:
[0124] The query module is used to select a host in the K8s environment cluster in the K8s environment, and periodically query the key value of the key-value pair in the task queue. When the key value changes, it is determined that the task queue has changed.
[0125] Or, in a Docker environment, all hosts in the Docker environment cluster are used to query the key value of the key-value pair in the task queue at the same time, and when the key value changes, it is determined that the task queue has changed.
[0126] In some of the embodiments, the processing module 220 is further used to generate a corresponding task based on the deployment request;
[0127] Based on the Key Watch mechanism of the etcd service, the task is added to the task queue.
[0128] In some of the embodiments, the configuration module 230 is also used to fill the service deployment information into a preset configuration template in a preset format in a K8s environment or a Docker environment to generate a service configuration file that conforms to the current environment.
[0129] In some of the embodiments, the service containerized deployment device further includes:
[0130] A determination module, used to query the service status of the service operation according to a preset time and a preset query number;
[0131] Determine whether the service version is consistent based on the service status and service deployment information in the database;
[0132] If they are consistent, check the health status of the service and obtain the health status information;
[0133] If they are inconsistent, redeploy or upgrade the service.
[0134] In some of the embodiments, the service containerized deployment device further includes:
[0135] A storage module, used for receiving reported health status information;
[0136] The health status information is stored in a database and managed according to the time of receipt.
[0137] It should be noted that the above modules can be functional modules or program modules, and can be implemented by software or hardware. For modules implemented by hardware, the above modules can be located in the same processor; or the above modules can be located in different processors in any combination.
[0138] In this embodiment, a computer device is further provided, including a memory and a processor, wherein a computer program is stored in the memory, and the processor is configured to run the computer program to execute the steps in any one of the above method embodiments.
[0139] Optionally, the computer device may further include a transmission device and an input / output device, wherein the transmission device is connected to the processor, and the input / output device is connected to the processor.
[0140] Optionally, in this embodiment, the processor may be configured to perform the following steps through a computer program:
[0141] S1, obtaining a deployment request initiated by a user for service deployment, and storing the service deployment information in the deployment request in a database;
[0142] S2, based on the deployment request, generates the corresponding task and adds the task to the task queue; each task in the task queue corresponds to a key-value pair;
[0143] S3, when the task queue changes, obtain the corresponding service deployment information from the database based on the task; generate a service configuration file that meets the current environment based on the service deployment information and the preset configuration template;
[0144] S4, based on the service configuration file, deploys the service to the cluster of the current environment.
[0145] It should be noted that the specific examples in this embodiment can refer to the examples described in the above embodiments and optional implementation modes, and will not be repeated in this embodiment.
[0146] In addition, in combination with the service container deployment method provided in the above embodiments, a storage medium may also be provided in this embodiment to implement the method. The storage medium stores a computer program; when the computer program is executed by a processor, any one of the service container deployment methods in the above embodiments is implemented.
[0147] It should be understood that the specific embodiments described herein are only used to explain the application, rather than to limit it. Based on the embodiments provided in this application, all other embodiments obtained by ordinary technicians in this field without creative work are within the protection scope of this application.
[0148] Obviously, the drawings are only some examples or embodiments of the present application. For ordinary technicians in the field, the present application can also be applied to other similar situations based on these drawings without creative work. In addition, it is understandable that although the work done in this development process may be complicated and lengthy, for ordinary technicians in the field, certain changes in design, manufacturing or production based on the technical content disclosed in this application are only conventional technical means and should not be regarded as insufficient content disclosed in this application.
[0149] The term "embodiment" in this application refers to a specific feature, structure or characteristic described in conjunction with the embodiment that can be included in at least one embodiment of the present application. The appearance of this phrase in various locations in the specification does not necessarily mean the same embodiment, nor does it mean that it is mutually exclusive with other embodiments and is independent or optional. It is clearly or implicitly understood by those of ordinary skill in the art that the embodiments described in this application can be combined with other embodiments without conflict.
[0150] The above-mentioned 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 patent protection. 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 scope of protection of the present application. Therefore, the scope of protection of the present application shall be subject to the attached claims.
Claims
1. A method for deploying service containerization, characterized in that: include: Obtaining a deployment request initiated by a user for service deployment, and storing the service deployment information in the deployment request in a database; Based on the deployment request, generate a corresponding task, and add the task to a task queue; Each of the tasks in the task queue corresponds to a key-value pair; When the task queue changes, acquiring the corresponding service deployment information from the database based on the task; Generate a service configuration file that meets the current environment based on the service deployment information and the preset configuration template; Based on the service configuration file, the service is deployed to the cluster of the current environment.
2. The method for deploying service containerization according to claim 1, characterized in that: The method further comprises: In a K8s environment, a host in the cluster of the K8s environment is selected to listen to the pushed task queue, and when the task in the task queue is added or changed, it is determined that the task queue has changed; Or, in a Docker environment, all hosts in the cluster of the Docker environment simultaneously monitor the pushed task queue, and when the task in the task queue is added or changed, it is determined that the task queue has changed.
3. The method for deploying service containerization according to claim 1, characterized in that: The method further comprises: In a K8s environment, a host in the cluster of the K8s environment is selected, and a key value of a key-value pair in the task queue is periodically queried, and when the key value changes, it is determined that the task queue has changed; Or, in a Docker environment, all hosts in the cluster of the Docker environment are used to query the key value of the key-value pair in the task queue at the same time, and when the key value changes, it is determined that the task queue has changed.
4. The method for deploying service containerization according to claim 1, characterized in that: Based on the deployment request, a corresponding task is generated and the task is added to a task queue, including: Based on the deployment request, generate a corresponding task; Based on the Key Watch mechanism of the etcd service, the task is added to the task queue.
5. The method for deploying service containerization according to claim 1, characterized in that: Generate a service configuration file that meets the current environment based on the service deployment information and the preset configuration template, including: In a K8s environment or a Docker environment, the service deployment information is filled into the preset configuration template according to a preset format to generate a service configuration file that conforms to the current environment.
6. The method for deploying service containerization according to claim 1, characterized in that: The method further comprises: Query the service status of the service operation according to the preset time and preset query number; Determining whether the version of the service is consistent according to the service status and the service deployment information in the database; If they are consistent, check the health status of the service and obtain the health status information; If not consistent, the service is redeployed or upgraded.
7. The method for deploying service containerization according to claim 6, characterized in that: The method further comprises: Receiving the reported health status information; The health status information is stored in the database, and the health status information in the database is managed according to the time of receipt.
8. A service container deployment device, characterized in that: include: An acquisition module is used to acquire a deployment request initiated by a user for service deployment, and store the service deployment information in the deployment request in a database; A processing module, used to generate a corresponding task based on the deployment request and add the task to a task queue; Each of the tasks in the task queue corresponds to a key-value pair; A configuration module, configured to obtain the corresponding service deployment information from the database based on the task when the task queue changes; Generate a service configuration file that meets the current environment based on the service deployment information and the preset configuration template; A management module is used to deploy the service to the cluster of the current environment based on the service configuration file.
9. A computer device comprising a memory and a processor, characterized in that: A computer program is stored in the memory, and the processor is configured to run the computer program to execute the steps of the service containerization deployment method according to any one of claims 1 to 7.
10. 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 service containerization deployment method described in any one of claims 1 to 7 are implemented.
