Signal sending method and related device
By mounting a signal sending script in a Kubernetes cluster and executing a signal sending rule based on the signal sending parameters, the problem of processes in the container failing to terminate gracefully is solved, and business consistency is achieved.
Patent Information
- Application Number
- CN202510048975.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-13
- Publication Date
- 2025-02-14
- Estimated Expiration
- 2045-01-13
AI Technical Summary
In Kubernetes cluster, when the first process started by the container is not a professional init process, after the main process receives the stop signal and is terminated, the business signal will not be passed to the child process, but will automatically send SIGKILL signal to the child process , resulting in the child process being forcibly terminated, affecting business consistency.
Provide a signal transmission method, by mounting a preset signal transmission script to the target container, obtaining the signal transmission parameters of the target container in response to receiving the delete instruction of the target container, and using these parameters as corresponding in the signal transmission script After the variable value of the parameter variable, a signal transmission script is executed to send a SIGTERM signal to each process of the target container according to the signal transmission rule indicated by the signal transmission label.
Through this method, the process is terminated gracefully in a multi-process container, avoiding the situation where the child process is forcibly terminated, thereby ensuring business consistency.
Smart Images

Figure CN119440779A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of containerization technology, and in particular to a signal sending method and related devices. Background Art
[0002] Kubernetes cluster is an open source platform for automating the deployment, expansion and management of containerized applications. Kubernetes (K8s for short) cluster consists of multiple nodes, which are divided into Master nodes and Worker nodes. The Master node is responsible for controlling and managing the entire cluster, while the Worker node is responsible for running the actual containerized application.
[0003] The init process is the first user-level process started by the kernel. It is responsible for managing the system startup process and ensuring the operation of other processes. In the prior art, the Kubernetes cluster starts a professional init process through the dump-init system or the process manager tini to start and stop multiple processes in a multi-process container. Among them, dump-init is a lightweight process supervisor and initialization system designed specifically for container environments, and Tini is an extremely small and secure Unix initialization system and process manager.
[0004] However, due to the application limitations of the existing dump-init system or tini, when the first process started by the container is not a professional init process, after the main process receives a stop signal and is terminated, the business signal will not be passed to the child process, but a SIGKILL signal will be automatically sent to the child process. The child process will be forcibly terminated after receiving the SIGKILL signal, thus affecting business consistency. Summary of the invention
[0005] In view of the above problems, the present application provides a signal sending method and related devices to achieve the purpose of improving the client startup efficiency and the effectiveness of the opening screen video. The specific scheme is as follows:
[0006] The first aspect of the present application provides a signal sending method, including:
[0007] Mount a preset signal sending script to the target container, wherein the signal sending script includes a plurality of preset parameter variables, the parameter variables include signal sending rules, and the signal sending script is used to execute sending of a SIGTERM signal according to the variable values of the parameter variables;
[0008] In response to receiving a delete instruction of a target container, acquiring a signal sending parameter of the target container, wherein the signal sending parameter includes a signal sending tag;
[0009] After taking the signal sending parameter of the target container as the variable value of the corresponding parameter variable in the signal sending script, the signal sending script is executed to send a SIGTERM signal to each process of the target container according to the signal sending rule indicated by the signal sending label.
[0010] In a possible implementation, the signal sending method further includes:
[0011] Deploy the resource object that configures the signal sending script in the Kubernetes cluster and add a lifecycle hook;
[0012] receiving a target container group creation request, the target container group creation request including a creation instruction and a resource declaration file, the creation instruction instructing to create the target container group according to the resource declaration file;
[0013] Projecting the signal sending parameters into a resource declaration file through the lifecycle hook, and after adding a pre-stop hook in the resource declaration file, creating the target container group based on the resource declaration file;
[0014] The target container is run in the target container group, and the target container includes a plurality of threads.
[0015] In a possible implementation, obtaining the signal sending parameter of the target container includes:
[0016] The resource declaration file of the target container is searched to determine whether the signal sending tag exists, and if so, the signal sending parameter is obtained from the resource declaration file of the target container.
[0017] In a possible implementation, the parameter variable further includes a waiting time variable, the signal sending parameter further includes a preset waiting time, and after the signal sending parameter of the target container is used as the variable value of the corresponding parameter variable in the signal sending script, the signal sending script is executed, including:
[0018] The signal sending script is executed after taking the waiting time in the signal sending parameter as the variable value of the waiting time variable and taking the signal sending label in the signal sending parameter as the variable value of the signal sending rule, so as to send a SIGTERM signal to each process of the target container according to the signal sending rule after the waiting time.
[0019] In a possible implementation, the signal sending label is one of a first signal sending label and a second signal sending label, wherein the first signal sending label indicates that the SIGTERM signal is sent in ascending order of process numbers, and the second signal sending label indicates that the SIGTERM signal is sent in descending order of process numbers.
[0020] A second aspect of the present application provides a signal sending device, including:
[0021] A script mounting unit, used to mount a preset signal sending script to a target container, wherein the signal sending script includes a plurality of preset parameter variables, the parameter variables include signal sending rules, and the signal sending script is used to execute sending of a SIGTERM signal according to variable values of the parameter variables;
[0022] a sending parameter acquisition unit, configured to acquire, in response to receiving a delete instruction of a target container, a signal sending parameter of the target container, wherein the signal sending parameter includes a signal sending tag;
[0023] A script execution unit is used to execute the signal sending script after taking the signal sending parameter of the target container as the variable value of the corresponding parameter variable in the signal sending script, so as to send a SIGTERM signal to each process of the target container according to the signal sending rule indicated by the signal sending label.
[0024] In a possible implementation, the signal sending device further includes a container creating unit, which is used to:
[0025] Deploy the resource object that configures the signal sending script in the Kubernetes cluster and add a lifecycle hook;
[0026] receiving a target container group creation request, the target container group creation request including a creation instruction and a resource declaration file, the creation instruction instructing to create the target container group according to the resource declaration file;
[0027] The signal sending parameters are projected into a resource declaration file through the lifecycle hook, and after a pre-stop hook is added to the resource declaration file, the target container group is created based on the resource declaration file.
[0028] A third aspect of the present application provides a computer program product, including computer-readable instructions. When the computer-readable instructions are executed on an electronic device, the electronic device implements the signal sending method of the first aspect or any implementation of the first aspect.
[0029] A fourth aspect of the present application provides an electronic device, comprising at least one processor and a memory connected to the processor, wherein:
[0030] The memory is used to store computer programs;
[0031] The processor is used to execute the computer program so that the electronic device can implement the signal sending method of the first aspect or any implementation manner of the first aspect.
[0032] A fifth aspect of the present application provides a computer storage medium, which carries one or more computer programs. When the one or more computer programs are executed by an electronic device, the electronic device can implement the signal sending method of the first aspect or any implementation method of the first aspect.
[0033] By means of the above technical solution, the present application provides a signal sending method and related devices, which mount a preset signal sending script to the target container, and obtain the signal sending parameters of the target container in response to receiving the deletion instruction of the target container. Since the signal sending script includes multiple preset parameter variables, the parameter variables include signal sending rules, the signal sending script is used to execute the sending of SIGTERM signals according to the variable values of the parameter variables, and the signal sending parameters include signal sending labels, which are used to indicate the signal sending rules, therefore, after using the signal sending parameters of the target container as the variable values of the corresponding parameter variables in the signal sending script, the signal sending script is executed to send the SIGTERM signal to each process of the target container according to the signal sending rules indicated by the signal sending label. It can be seen that the present method realizes the sending of SIGTERM signals to each process of the target container by executing the pre-mounted signal sending script based on the signal sending parameters of the target container to be deleted, thereby achieving the business consistency corresponding to the target container. BRIEF DESCRIPTION OF THE DRAWINGS
[0034] The above and other features, advantages and aspects of the embodiments of the present disclosure will become more apparent with reference to the following detailed description in conjunction with the accompanying drawings. Throughout the accompanying drawings, the same or similar reference numerals represent the same or similar elements. It should be understood that the drawings are schematic and the originals and elements are not necessarily drawn to scale.
[0035] Figure 1 A schematic diagram of a system architecture provided for this application;
[0036] Figure 2 An optional hardware structure diagram of the terminal 100 is shown;
[0037] Figure 3 A schematic diagram of the structure of a server 200 is shown;
[0038] Figure 4 A schematic diagram of a flow chart of a signal sending method provided in an embodiment of the present application;
[0039] Figure 5 A specific implementation flow chart of a signal sending method provided in an embodiment of the present application;
[0040] Figure 6 A comparison diagram of signal transmission effects provided in an embodiment of the present application;
[0041] Figure 7 A schematic diagram of the structure of a signal sending device provided in an embodiment of the present application;
[0042] Figure 8 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0043] The following describes the embodiments of the present application in conjunction with the drawings in the embodiments of the present application. The terms used in the implementation method section of the present application are only used to explain the specific embodiments of the present application, and are not intended to limit the present application.
[0044] The embodiments of the present application are described below in conjunction with the accompanying drawings. Those skilled in the art will appreciate that, with the development of technology and the emergence of new scenarios, the technical solutions provided in the embodiments of the present application are also applicable to similar technical problems.
[0045] The terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and need not be used to describe a specific order or sequential order. It should be understood that the terms used in this way can be interchangeable under appropriate circumstances, which is only to describe the distinction mode adopted by the objects of the same attributes when describing in the embodiments of the present application. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, so that the process, method, system, product or equipment comprising a series of units need not be limited to those units, but may include other units that are not clearly listed or inherent to these processes, methods, products or equipment.
[0046] The embodiment of the present application provides a signal sending method and related device, which can be applied in the field of containerization technology, and can be specifically applied to the scenario of sending signals when a multi-process container (multi-threaded container) is closed. When the first process started by the multi-process container is not a professional init process, the child process is prevented from being forcibly terminated by sending signals to ensure business consistency.
[0047] This application can be applied to, but is not limited to, applications with container management functions or cloud services provided by cloud-side servers, etc., which are introduced below:
[0048] See also Figure 1 , Figure 1 1 shows a schematic diagram of a system architecture. The system may include a terminal 100 and a server 200. The server 200 may include one or more servers ( Figure 1 In the description, a server is included as an example), and the server 200 can provide the method provided in the embodiment of the present application for one or more terminals.
[0049] Among them, a signal sending application can be installed on the terminal 100, and the above application and web page can provide an interface. The terminal 100 can receive relevant parameters entered by the user on the signal sending interface and send the above parameters to the server 200. The server 200 can obtain processing results based on the received parameters and return the processing results to the terminal 100.
[0050] It should be understood that in some optional implementations, the terminal 100 can also complete the action of obtaining the processing result based on the received parameters by itself without the cooperation of the server, and the embodiments of the present application are not limited to this.
[0051] Next describe Figure 1 The product form of the mid-terminal 100;
[0052] The terminal 100 in the embodiment of the present application can be a mobile phone, a tablet computer, a wearable device, a vehicle-mounted device, an augmented reality (AR) / virtual reality (VR) device, a laptop computer, an ultra-mobile personal computer (UMPC), a netbook, a personal digital assistant (PDA), etc., and the embodiment of the present application does not impose any limitation on this.
[0053] Figure 2 An optional hardware structure diagram of the terminal 100 is shown.
[0054] refer to Figure 2 As shown, the terminal 100 may include a radio frequency unit 110, a memory 120, an input unit 130, a display unit 140, a camera 150 (optional), an audio circuit 160 (optional), a speaker 161 (optional), a microphone 162 (optional), an earphone jack 163 (optional), a processor 170, an external interface 180, a power supply 190 and other components. Those skilled in the art will appreciate that Figure 2 These are merely examples of terminals or multi-function devices and do not constitute limitations on the terminals or multi-function devices, which may include more or fewer components than those shown in the figures, or combinations of certain components, or different components.
[0055] The input unit 130 can be used to receive input digital or character information, and generate key signal input related to the user settings and function control of the portable multifunctional device. Specifically, the input unit 130 may include a touch screen 131 (optional) and / or other input devices 132. The touch screen 131 can collect user touch operations on or near it (such as operations performed by the user using any suitable object such as fingers, joints, stylus, etc. on or near the touch screen), and drive the corresponding connection device according to a pre-set program. The touch screen can detect the user's touch action on the touch screen, convert the touch action into a touch signal and send it to the processor 170, and can receive and execute commands sent by the processor 170; the touch signal at least includes contact point coordinate information. The touch screen 131 can provide an input interface and an output interface between the terminal 100 and the user. In addition, the touch screen can be implemented using multiple types such as resistive, capacitive, infrared, and surface acoustic wave. In addition to the touch screen 131, the input unit 130 can also include other input devices. Specifically, other input devices 132 may include, but are not limited to, one or more of a physical keyboard, function keys (such as a volume control key, a switch key, etc.), a trackball, a mouse, a joystick, and the like.
[0056] Among them, the input device 132 can receive input data and the like.
[0057] The display unit 140 may be used to display information input by the user or provided to the user, various menus of the terminal 100, interactive interfaces, file display and / or playback of any multimedia file. In the embodiment of the present application, the display unit 140 may be used to display the interface of signal transmission, processing results, etc.
[0058] The memory 120 can be used to store instructions and data. The memory 120 can mainly include an instruction storage area and a data storage area. The data storage area can store various data, such as multimedia files, texts, etc.; the instruction storage area can store software units such as operating systems, applications, instructions required for at least one function, or their subsets and extensions. It can also include a non-volatile random access memory; provide the processor 170 with hardware, software and data resources including management of computing and processing equipment, and support control software and applications. It is also used for the storage of multimedia files, and the storage of running programs and applications.
[0059] The processor 170 is the control center of the terminal 100. It uses various interfaces and lines to connect various parts of the entire terminal 100. By running or executing instructions stored in the memory 120 and calling data stored in the memory 120, it executes various functions of the terminal 100 and processes data, thereby controlling the terminal device as a whole. Optionally, the processor 170 may include one or more processing units; preferably, the processor 170 may integrate an application processor and a modem processor, wherein the application processor mainly processes the operating system, user interface and application program, and the modem processor mainly processes wireless communication. It is understandable that the above-mentioned modem processor may not be integrated into the processor 170. In some embodiments, the processor and the memory may be implemented on a single chip, and in some embodiments, they may also be implemented separately on separate chips. The processor 170 may also be used to generate corresponding operation control signals, send them to corresponding components of the computing and processing device, read and process data in the software, especially read and process data and programs in the memory 120, so that each functional module therein performs corresponding functions, thereby controlling the corresponding components to act according to the requirements of the instructions.
[0060] Among them, the memory 120 can be used to store software codes related to the signal sending method, the processor 170 can execute the steps of the signal sending method, and can also schedule other units (such as the above-mentioned input unit 130 and display unit 140) to achieve corresponding functions.
[0061] The radio frequency unit 110 (optional) can be used for receiving and sending information or receiving and sending signals during a call, for example, after receiving the downlink information of the base station, it is sent to the processor 170 for processing; in addition, the designed uplink data is sent to the base station. Generally, the RF circuit includes but is not limited to an antenna, at least one amplifier, a transceiver, a coupler, a low noise amplifier (Low Noise Amplifier, LNA), a duplexer, etc. In addition, the radio frequency unit 110 can also communicate with network devices and other devices through wireless communication. The wireless communication can use any communication standard or protocol, including but not limited to Global System of Mobile communication (Global System of Mobile communication, GSM), General Packet Radio Service (General Packet Radio Service, GPRS), Code Division Multiple Access (Code Division Multiple Access, CDMA), Wideband Code Division Multiple Access (Wideband Code Division Multiple Access, WCDMA), Long Term Evolution (Long Term Evolution, LTE), email, Short Messaging Service (SMS), etc.
[0062] In this embodiment of the present application, the RF unit 110 can send data to the server 200 and receive processing results sent by the server 200.
[0063] It should be understood that the radio frequency unit 110 is optional and can be replaced by other communication interfaces, such as a network port.
[0064] The terminal 100 also includes a power supply 190 (such as a battery) for supplying power to various components. Preferably, the power supply can be logically connected to the processor 170 through a power management system, so that the power management system can manage charging, discharging, power consumption and other functions.
[0065] The terminal 100 further includes an external interface 180 , which may be a standard Micro USB interface or a multi-pin connector, and may be used to connect the terminal 100 to communicate with other devices, or to connect a charger to charge the terminal 100 .
[0066] Although not shown, the terminal 100 may also include a flashlight, a wireless fidelity (WiFi) module, a Bluetooth module, sensors with different functions, etc., which are not described in detail here. Some or all of the methods described below may be applied in the following embodiments. Figure 2 In the terminal 100 shown.
[0067] Next describe Figure 1 The product form of the server 200;
[0068] Figure 3 A schematic diagram of the structure of a server 200 is shown. Figure 3 As shown, the server 200 includes a bus 201, a processor 202, a communication interface 203, and a memory 204. The processor 202, the memory 204, and the communication interface 203 communicate with each other via the bus 201.
[0069] The bus 201 may be a peripheral component interconnect (PCI) bus or an extended industry standard architecture (EISA) bus. The bus may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 3 Only one thick line is used in the diagram, but this does not mean that there is only one bus or only one type of bus.
[0070] The processor 202 may be any one or more of a central processing unit (CPU), a graphics processing unit (GPU), a microprocessor (MP), or a digital signal processor (DSP).
[0071] The memory 204 may include a volatile memory, such as a random access memory (RAM). The memory 204 may also include a non-volatile memory, such as a read-only memory (ROM), a flash memory, a hard drive (HDD), or a solid state drive (SSD).
[0072] The memory 204 may be used to store software codes related to the signal sending method, and the processor 202 may execute the steps of the signal sending method of the chip, and may also schedule other units to implement corresponding functions.
[0073] It should be understood that the above-mentioned terminal 100 and server 200 can be centralized or distributed devices, and the processors in the above-mentioned terminal 100 and server 200 (such as processor 170 and processor 202) can be hardware circuits (such as application specific integrated circuit (ASIC), field-programmable gate array (FPGA), general-purpose processor, digital signal processor (DSP), microprocessor or microcontroller, etc.), or a combination of these hardware circuits. For example, the processor can be a hardware system with an instruction execution function, such as a CPU, DSP, etc., or a hardware system without an instruction execution function, such as an ASIC, FPGA, etc., or a combination of the above-mentioned hardware systems without an instruction execution function and hardware systems with an instruction execution function.
[0074] The embodiment of the present application provides a signal transmission method. The signal transmission method of the embodiment of the present application is described in detail below with reference to the accompanying drawings.
[0075] Reference Figure 4 , Figure 4 A flow chart of a signal sending method provided in an embodiment of the present application is as follows: Figure 4 As shown, a data processing method provided in an embodiment of the present application may include steps S401 to S403, and these steps are described in detail below.
[0076] S401: Mount a preset signal sending script to a target container.
[0077] In this embodiment, the signal sending script includes multiple preset parameter variables, the parameter variables include signal sending rules, and the signal sending script is used to execute sending of the SIGTERM signal according to the variable values of the parameter variables, that is, sending the SIGTERM signal according to the variable values of the signal sending rules.
[0078] S402: In response to receiving a delete instruction of a target container, obtain a signal sending parameter of the target container.
[0079] In this embodiment, the signal transmission parameter includes a signal transmission tag. The signal transmission tag includes a signal transmission rule.
[0080] In an optional embodiment, during the creation phase of the target container, the signal sending parameters of the target container are stored in a resource declaration file of the target container. The signal sending parameters of the target container are obtained by querying the resource declaration file of the target container.
[0081] S403: After using the signal sending parameter of the target container as the variable value of the corresponding parameter variable in the signal sending script, execute the signal sending script to send a SIGTERM signal to each process of the target container according to the signal sending rule indicated by the signal sending label.
[0082] In this embodiment, after the signal sending label in the signal sending parameter is used as the variable value of the signal sending rule, the signal sending script is executed. At this time, the signal sending script executes the signal sending rule indicated by the signal sending label in the signal sending parameter to send the SIGTERM signal to each process of the target container.
[0083] It can be seen from the above technical solution that the embodiment of the present application provides a signal sending method, the signal sending script includes multiple preset parameter variables, the parameter variables include signal sending rules, the signal sending script is used to execute the sending of SIGTERM signals according to the variable values of the parameter variables, and the signal sending parameters include signal sending labels, which are used to indicate the signal sending rules. Therefore, after the signal sending parameters of the target container are used as the variable values of the corresponding parameter variables in the signal sending script, the signal sending script is executed to send SIGTERM signals to each process of the target container according to the signal sending rules indicated by the signal sending label. It can be seen that this method realizes the sending of SIGTERM signals to each process of the target container by executing the pre-mounted signal sending script based on the signal sending parameters of the target container to be deleted, thereby achieving the business consistency corresponding to the target container.
[0084] See also Figure 5 , Figure 5 This is a specific implementation flow chart of a signal sending method provided in an embodiment of the present application, and this method is specifically applied to the client. Figure 5 As shown, this method specifically includes S501 to S509, as follows:
[0085] S501. Deploy the resource object ConfigMap in the Kubernetes cluster and add the lifecycle hook Webhook.
[0086] In this embodiment, the configuration data is stored in ConfigMap, and the configuration data includes a preset signal sending script, and the signal sending script is a script for sending a SIGTERM termination signal according to a parameter variable. Specifically, the signal sending script includes multiple parameter variables, and the parameter variables include a signal sending label variable and a waiting time variable.
[0087] It should be noted that ConfigMap is a resource object in Kubernetes. Through the resource object in Kubernetes, configuration data can be stored in the Kubernetes cluster and injected into the container when needed. By using ConfigMap, the configuration information is separated from the program code, thus simplifying the configuration change and management process.
[0088] S502: Receive a request to create a target container group through the Kubernetes API server.
[0089] In this embodiment, the target container group is used to run multiple multi-threaded containers (ie, fat containers). The creation request of the target container group includes a creation instruction and a resource declaration file. The creation instruction is used to instruct to create the target container group according to the resource declaration file.
[0090] In this embodiment, the resource declaration file includes a container group definition and a container definition.
[0091] It should be noted that the container group pod, as the smallest deployable computing unit, contains multiple containers and provides them with a unified operating environment and management functions. A multi-threaded container is an instance running inside a pod and is responsible for running multi-process applications or services.
[0092] S503 . Project the signal sending parameters into the resource declaration file through Webhook, and add a preStop hook in the resource declaration file.
[0093] In this embodiment, the signal sending parameters are projected into the resource declaration file through Webhook, and the pre-stop preStop hook is configured in the container life cycle. The signal sending parameters are projected into the container group definition through Webhook, and the preStop hook configured in the container life cycle is added to the container definition.
[0094] In this embodiment, the signal sending parameters include a signal sending label and a waiting time. The signal sending label carried by the creation request is one of the preset forwarding labels, which is used to indicate that the process end SIGTERM signal is sent according to the preset signal sending rule. For example, the preset forwarding label includes one of the first signal sending label and the second signal sending label, wherein the first signal sending label is recorded as "sig:order", indicating that the SIGTERM termination signal is sent in the order of process numbers from small to large, and the second signal sending label is recorded as "sig:reorder", indicating that the SIGTERM signal is sent in the order of process numbers from large to small.
[0095] In this embodiment, the SIGTERM signal is a standard signal in Linux for requesting process termination. When the SIGTERM signal is used to request a process to terminate its execution, the program is allowed to perform necessary cleanup work before exiting, such as closing files, releasing resources, etc.
[0096] It should be noted that in Kubernetes, the preStop hook is an important hook in the container life cycle. It is executed before the container is terminated, allowing users to perform some cleanup or preparation operations before the container is stopped, thereby helping the application to shut down gracefully, release resources, or complete any necessary cleanup work.
[0097] S504. Create a target container group based on the resource declaration file through the Kubelet component.
[0098] In this embodiment, after the target container group is created, at least one multi-process container is run in the target container group, and each multi-process container runs multiple processes to implement the service.
[0099] It should be noted that Kubelet is a key component in the Kubernetes cluster and is responsible for managing the life cycle of containers and container groups on each node.
[0100] It is further noted that the correspondence between resource declaration files and container group identifiers is stored through the distributed key-value storage system ETCD, and ETCD is also used to store cluster status, configuration, and metadata. The Kubernetes API server interacts with ETCD to store and retrieve information about various resources in the cluster (such as Pods, services, nodes, etc.).
[0101] S505: The target container group runs multiple processes through a multi-threaded container.
[0102] In this embodiment, the multi-threaded container is used to run multiple processes of a business, each process is identified by a number, and the unique identifier of the target process run by the target multi-threaded container in the target container group is composed of the target container group, the target multi-threaded container and the process number.
[0103] It should be noted that, through S501~S505, a resource object for configuring a signal sending script is deployed in the Kubernetes cluster, and a lifecycle hook is added; after receiving a creation request of a target container group, a creation instruction is created to indicate the creation of a target container group according to a resource declaration file; further, the signal sending parameters are projected into the resource declaration file through a lifecycle hook, and after adding a pre-stop hook in the resource declaration file, a target container group is created based on the resource declaration file, and a target container is run in the target container group, and the target container includes multiple threads. It can be seen that this method pre-customizes the signal sending script and modifies the resource declaration file of the target container group to realize the customized configuration of the signal sending parameters of the target container.
[0104] S506. Receive a deletion request for the target container through the Kubernetes API server, and send the deletion request for the target container to the target container through the Kubelet component.
[0105] In this embodiment, the target container deletion request includes a SIGTERM signal and an identifier of the target container, which is used to delete the target container. The target container is any multi-threaded container in the target container group. The identifier of the target container is composed of an identifier of the target container group and an identifier of the target container, and is used to uniquely indicate the target container.
[0106] S507: Determine whether there is a signal sending label in the resource declaration file of the target container group to which the target container belongs.
[0107] In this embodiment, there is a signal sending tag in the resource declaration file of the target container group, indicating that the target container group can easily enable the graceful start and stop function for multi-threading.
[0108] It should be noted that whether the target container is a multi-threaded container is determined in advance based on the identifier of the target container. If the target container is a multi-threaded container and there is a signal sending tag in the resource declaration file of the target container group, S508 is executed.
[0109] If the target container is a single-threaded container or there is no signal sending tag in the resource declaration file, the SIGTERM signal is sent directly to the target container. If the target container is a single-threaded container, the only thread in the single-threaded container receives the SIGTERM signal and executes the termination operation. If the target container is a multi-threaded container, after the parent thread receives the SIGTERM signal and executes the termination operation, it forwards the forced termination SIGKILL signal to the child process.
[0110] S508: If the target container is a multi-threaded container and there is a signal sending label in the resource declaration file of the target container group, the signal sending script in the ConfigMap is mounted to the target container through the preStop hook.
[0111] S509: Execute the signal sending script based on the signal sending parameters through the preStop hook.
[0112] In this embodiment, the signal sending parameter corresponding to the target container is used as the variable value of the signal sending parameter in the signal sending script to obtain the target signal sending script of the target container. The target signal sending script is executed through the preStop hook.
[0113] In this embodiment, executing the target signal sending script includes: after receiving the SIGTERM signal and reaching the waiting time, sending the SIGTERM signal to each thread in the target container according to the signal sending rule indicated by the signal sending label, so that each thread can be started and stopped gracefully.
[0114] Specifically, the waiting time in the signal sending parameter is used as the variable value of the waiting time variable, and the signal sending label in the signal sending parameter is used as the variable value of the signal sending rule. Then, the signal sending script is executed to send a SIGTERM signal to each process of the target container according to the signal sending rule after the waiting time.
[0115] It should be noted that the waiting time can be pre-configured to a time value that is not less than the estimated time for deleting the iptables rules. Therefore, when the signal sending script and the iptables rules are executed synchronously, when the waiting time is reached, the iptables rules have been deleted.
[0116] It can be seen from the above technical solution that a signal sending method provided by an embodiment of the present application develops a custom extension component in the Kubernetes cluster, automatically deploys a configMap resource object for storing signal sending scripts, and adds custom content to the user-defined resource declaration file, where the custom content includes the signal sending parameters of the signal sending script. Through the Webhook function, the signal sending script in the ConfigMap is automatically mounted to the container group. When the deletion instruction of the target container is received, the pre-stop hook in the life cycle is used to execute the signal sending script, and the SIGTERM signal is sent to each thread according to the custom signal sending rules, thereby realizing the elegant start and stop of multi-threading. Ensure the consistency of business when the multi-threaded container is deleted.
[0117] Furthermore, the waiting time parameter is set in the signal sending script to take into account the graceful shutdown, waiting for the iptables rules to be deleted, or the direct connection type LB to be unbound, to prevent the request from being sent to the container in the stopped container group.
[0118] Figure 6 A schematic diagram for comparing signal transmission processes provided in an embodiment of the present application is shown in FIG. Figure 6As shown, taking container A as the first target container, processes C1-P1, C1-P2, and C1-P3 are running in container A, and process C1-P1 is not a professional init process. In the prior art, after the Kubelet component sends a deletion request for the target container to the target container, process C1-P1 receives a SIGTERM signal, but the stop signal forwarded by process C1-P1 to process C1-P2 and process C1-P3 is a SIGKILL signal. At this time, process C1-P2 and process C1-P3 will be forced to stop, resulting in business inconsistency.
[0119] Taking the second target container as container B as an example, process C2-P1, process C2-P2, and process C2-P3 are running in container B, and process C2-P1 is not a professional init process. Based on a signal sending method provided in an embodiment of the present application, after sending a deletion request of the target container to the target container through the Kubelet component, the signal sending script pre-mounted to the target container will be automatically executed. After the signal sending script is executed, the SIGTERM signal is sent to process C2-P1, process C2-P2, and process C2-P3 in accordance with the signal sending order specified by the preset signal sending rule. Process C2-P1, process C2-P2, and process C2-P3 receive the SIGTERM signal for graceful start and stop to achieve business consistency.
[0120] It can be seen that in this application, not only the signal received by all processes in the target container is still the SIGTERM signal, but also each process receives the SIGTERM signal in a preset order after a preset waiting time, thereby realizing process termination, thereby further improving business consistency.
[0121] In summary, compared with the existing process management tools, all of them need to modify the old image, and the modified image can only be processed individually, and there is no way to modify the application in batches. For example, when using dump-init, the parameter ENTRYPOINT [" / docker-entrypoint.sh"] needs to be modified to the parameter ENTRYPOINT [" / usr / local / bin / tini", "--", " / docker-entrypoint.sh"]. The signal forwarding method provided in this application does not require image modification or change of deployment files. It can implement custom configuration of process closing rules without user perception, and close each process in order from large to small or from small to large according to the process number. Therefore, the process closing order can be flexibly configured according to business characteristics.
[0122] Furthermore, through platform-level solutions, all replica sets can implement the function with only one deployment, and whether to use the function can also be customized by configuring the signal sending label.
[0123] Furthermore, taking into account other factors of graceful shutdown, when the signal sending script is triggered, time is reserved to wait for the iptables rule to be deleted or the direct connection type LB to be unbound before sending a SIGTERM signal to all processes, thereby preventing requests from being sent to the stopped container group.
[0124] A signal sending method provided in an embodiment of the present application is introduced above, and a device for executing the above signal sending method will be introduced below.
[0125] See also Figure 7 , Figure 7 The structure diagram of a signal sending device provided in an embodiment of the present application is shown in FIG. The signal sending device is configured in a client, such as Figure 7 As shown, the signal sending device 700 includes:
[0126] A script mounting unit 701 is used to mount a preset signal sending script to a target container, wherein the signal sending script includes a plurality of preset parameter variables, the parameter variables include signal sending rules, and the signal sending script is used to execute sending of a SIGTERM signal according to variable values of the parameter variables;
[0127] A sending parameter acquisition unit 702, configured to acquire a signal sending parameter of the target container in response to receiving a delete instruction of the target container, wherein the signal sending parameter includes a signal sending tag;
[0128] The script execution unit 703 is configured to execute the signal sending script after taking the signal sending parameter of the target container as the variable value of the corresponding parameter variable in the signal sending script, so as to send a SIGTERM signal to each process of the target container according to the signal sending rule indicated by the signal sending label.
[0129] In an optional implementation, the signal sending device further includes a container creating unit, which is used to:
[0130] Deploy the resource object that configures the signal sending script in the Kubernetes cluster and add a lifecycle hook;
[0131] receiving a target container group creation request, the target container group creation request including a creation instruction and a resource declaration file, the creation instruction instructing to create the target container group according to the resource declaration file;
[0132] The signal sending parameters are projected into a resource declaration file through the lifecycle hook, and after a pre-stop hook is added to the resource declaration file, the target container group is created based on the resource declaration file.
[0133] In an optional implementation, when the sending parameter acquisition unit is used to acquire the signal sending parameters of the target container, it is specifically used to: search the resource declaration file of the target container to determine whether the signal sending label exists, and if so, acquire the signal sending parameters from the resource declaration file of the target container.
[0134] In an optional implementation, the parameter variable also includes a waiting time variable, and the signal sending parameter also includes a preset waiting time. The script execution unit is used to use the signal sending parameter of the target container as the variable value of the corresponding parameter variable in the signal sending script, and then execute the signal sending script. Specifically, it is used to: use the waiting time in the signal sending parameter as the variable value of the waiting time variable, and use the signal sending label in the signal sending parameter as the variable value of the signal sending rule, and then execute the signal sending script to execute the SIGTERM signal to each process of the target container according to the signal sending rule after the waiting time.
[0135] In an optional implementation, the signal sending label is one of a first signal sending label and a second signal sending label, wherein the first signal sending label indicates that the SIGTERM signal is sent in ascending order of process numbers, and the second signal sending label indicates that the SIGTERM signal is sent in descending order of process numbers.
[0136] The present application also provides an electronic device in an embodiment. Figure 8 As shown, it shows a schematic diagram of the structure of an electronic device suitable for implementing the embodiment of the present application. The electronic device in the embodiment of the present application may include but is not limited to fixed terminals such as mobile phones, laptops, PDAs (personal digital assistants), PADs (tablet computers), desktop computers, etc. Figure 8 The electronic device shown is merely an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.
[0137] like Figure 8As shown, the electronic device may include a processing device (e.g., a central processing unit, a graphics processing unit, etc.) 801, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 802 or a program loaded from a storage device 808 to a random access memory (RAM) 803. When the electronic device is powered on, various programs and data required for the operation of the electronic device are also stored in the RAM 803. The processing device 801, the ROM 802, and the RAM 803 are connected to each other via a bus 804. An input / output (I / O) interface 805 is also connected to the bus 804.
[0138] Typically, the following devices may be connected to the I / O interface 805: input devices 806 including, for example, a touch screen, a touch pad, a keyboard, a mouse, a camera, a microphone, an accelerometer, a gyroscope, etc.; output devices 807 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; storage devices 808 including, for example, a memory card, a hard disk, etc.; and communication devices 809. The communication device 809 may allow the electronic device to communicate with other devices wirelessly or by wire to exchange data. Although Figure 8 An electronic device having various devices is shown, but it should be understood that it is not required to implement or possess all the devices shown. More or fewer devices may be implemented or possessed instead.
[0139] An embodiment of the present application also provides a computer program product including computer-readable instructions. When the computer-readable instructions are executed on an electronic device, the electronic device implements any one of the signal sending methods provided in the embodiments of the present application.
[0140] A computer-readable storage medium is also provided in an embodiment of the present application. The storage medium carries one or more computer programs. When the one or more computer programs are executed by an electronic device, the electronic device can implement any signal sending method provided in the embodiment of the present application.
[0141] It should also be noted that the device embodiments described above are merely schematic, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed over multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. In addition, in the drawings of the device embodiments provided by the present application, the connection relationship between the modules indicates that there is a communication connection between them, which may be specifically implemented as one or more communication buses or signal lines.
[0142] Through the description of the above implementation mode, the technicians in the field can clearly understand that the present application can be implemented by means of software plus necessary general hardware, and of course, it can also be implemented by special hardware including special integrated circuits, special CPUs, special memories, special components, etc. In general, all functions completed by computer programs can be easily implemented by corresponding hardware, and the specific hardware structure used to implement the same function can also be various, such as analog circuits, digital circuits or special circuits. However, for the present application, software program implementation is a better implementation mode in more cases. Based on such an understanding, the technical solution of the present application is essentially or the part that contributes to the prior art can be embodied in the form of a software product, which is stored in a readable storage medium, such as a computer floppy disk, a U disk, a mobile hard disk, a ROM, a RAM, a disk or an optical disk, etc., including a number of instructions to enable a computer device (which can be a personal computer, a training device, or a network device, etc.) to execute the methods described in each embodiment of the present application.
[0143] In the above embodiments, all or part of the embodiments may be implemented by software, hardware, firmware or any combination thereof. When implemented by software, all or part of the embodiments may be implemented in the form of a computer program product.
[0144] The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the embodiment of the present application is generated in whole or in part. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices. The computer instructions may be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions may be transmitted from a website site, a computer, a training device, or a data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) mode to another website site, computer, training device, or data center. The computer-readable storage medium may be any available medium that a computer can store or a data storage device such as a training device, a data center, etc. that includes one or more available media integrations. The available medium may be a magnetic medium, (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state drive (SSD)), etc.
Claims
1. A signal sending method, characterized in that: include: Mount a preset signal sending script to the target container, wherein the signal sending script includes a plurality of preset parameter variables, the parameter variables include signal sending rules, and the signal sending script is used to execute sending of a SIGTERM signal according to the variable values of the parameter variables; In response to receiving a delete instruction of a target container, acquiring a signal sending parameter of the target container, wherein the signal sending parameter includes a signal sending tag; After taking the signal sending parameter of the target container as the variable value of the corresponding parameter variable in the signal sending script, the signal sending script is executed to send a SIGTERM signal to each process of the target container according to the signal sending rule indicated by the signal sending label.
2. The signal sending method according to claim 1, characterized in that: The signal sending method further includes: Deploy the resource object that configures the signal sending script in the Kubernetes cluster and add a lifecycle hook; receiving a target container group creation request, the target container group creation request including a creation instruction and a resource declaration file, the creation instruction instructing to create the target container group according to the resource declaration file; Projecting the signal sending parameters into a resource declaration file through the lifecycle hook, and after adding a pre-stop hook in the resource declaration file, creating the target container group based on the resource declaration file; The target container is run in the target container group, and the target container includes a plurality of threads.
3. The signal sending method according to claim 2, characterized in that: Acquiring the signal sending parameters of the target container includes: The resource declaration file of the target container is searched to determine whether the signal sending tag exists, and if so, the signal sending parameter is obtained from the resource declaration file of the target container.
4. The signal sending method according to claim 2, characterized in that: The parameter variable also includes a waiting time variable, and the signal sending parameter also includes a preset waiting time. After the signal sending parameter of the target container is used as the variable value of the corresponding parameter variable in the signal sending script, the signal sending script is executed, including: The signal sending script is executed after taking the waiting time in the signal sending parameter as the variable value of the waiting time variable and taking the signal sending label in the signal sending parameter as the variable value of the signal sending rule, so as to send a SIGTERM signal to each process of the target container according to the signal sending rule after the waiting time.
5. The signal sending method according to claim 4, characterized in that: The signal sending label is one of a first signal sending label and a second signal sending label, wherein the first signal sending label indicates that the SIGTERM signal is sent in the order of process numbers from small to large, and the second signal sending label indicates that the SIGTERM signal is sent in the order of process numbers from large to small.
6. A signal sending device, characterized in that: include: A script mounting unit, used to mount a preset signal sending script to a target container, wherein the signal sending script includes a plurality of preset parameter variables, the parameter variables include signal sending rules, and the signal sending script is used to execute sending of a SIGTERM signal according to variable values of the parameter variables; a sending parameter acquisition unit, configured to acquire, in response to receiving a delete instruction of a target container, a signal sending parameter of the target container, wherein the signal sending parameter includes a signal sending tag; A script execution unit is used to execute the signal sending script after taking the signal sending parameter of the target container as the variable value of the corresponding parameter variable in the signal sending script, so as to send a SIGTERM signal to each process of the target container according to the signal sending rule indicated by the signal sending label.
7. The signal sending device according to claim 6, characterized in that: The signal sending device further includes a container creating unit, which is used to: Deploy the resource object that configures the signal sending script in the Kubernetes cluster and add a lifecycle hook; receiving a target container group creation request, the target container group creation request including a creation instruction and a resource declaration file, the creation instruction instructing to create the target container group according to the resource declaration file; The signal sending parameters are projected into a resource declaration file through the lifecycle hook, and after a pre-stop hook is added to the resource declaration file, the target container group is created based on the resource declaration file.
8. A computer program product, characterized in that It comprises computer-readable instructions, and when the computer-readable instructions are executed on an electronic device, the electronic device implements the signal sending method as claimed in any one of claims 1 to 5.
9. An electronic device, characterized in that: The method comprises at least one processor and a memory connected to the processor, wherein: The memory is used to store computer programs; The processor is used to execute the computer program so that the electronic device can implement the signal sending method as described in any one of claims 1 to 5.
10. A computer storage medium, characterized in that: The storage medium carries one or more computer programs, and when the one or more computer programs are executed by an electronic device, the electronic device can implement the signal sending method as described in any one of claims 1 to 5.
Citation Information
Patent Citations
Container resource processing method, apparatus and device
CN108958930A
Software and hardware hybrid deployment MySQL cluster scheduling method and device
CN112905337A
Routing information processing method and device, computer equipment and storage medium
CN114567584A
Service resource monitoring method and device, electronic equipment and storage medium
CN115391000A
Method for realizing normal sequential starting between container services by monitoring mechanism
CN115981837A