Signal sending method and related device

By mounting signal sending scripts in Kubernetes cluster and custom sending SIGTERM signals using life cycle hooks, the problem of forced termination in the container is solved, and the elegant shutdown and business consistency of multi-process containers are achieved, which improves startup efficiency and video effects.

CN119440779BActive Publication Date: 2025-08-22LINKAGE TECHNOLOGY (NANJING) CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202510048975.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-01-13
Publication Date
2025-08-22
Estimated Expiration
2045-01-13

AI Technical Summary

Technical Problem

In the prior art, when the first process started by the container is not a professional init process, the business signal will not be passed to the child process after the main process receives the stop signal and is terminated, resulting in the child process being forced to terminate, affecting business consistency.

Method used

By mounting the preset signal sending script to the target container, obtaining the signal sending parameters, and upon receiving the delete instruction of the target container, SIGTERM signals are sent to each process according to the rules indicated by the signal sending tag, and a pre-stop hook is added to the resource declaration file using the life cycle hook to realize the custom transmission of the signal.

Benefits of technology

It realizes the elegant termination of processes in multi-process containers, ensures business consistency, does not need to transform images or deploy files, and flexibly configures process shutdown sequence, which improves client startup efficiency and the effectiveness of open-screen videos.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119440779B_ABST
    Figure CN119440779B_ABST
Patent Text Reader

Abstract

The present application discloses a signal sending method and related devices, which relate to the field of containerization technology, obtain the signal sending parameters of the target container, 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 SIGTERM signals to each process of the target container according to the signal sending rules indicated by the signal sending labels. It can be seen that this method executes the pre-mounted signal sending script based on the signal sending parameters of the target container to be deleted, thereby sending SIGTERM signals to each process of the target container and achieving the business consistency corresponding to the target container.
Need to check novelty before this filing date? Find Prior Art

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 is an open-source platform for automating the deployment, scaling, and management of containerized applications. A Kubernetes (K8s) cluster consists of multiple nodes, divided into master nodes and worker nodes. The master node controls and manages the entire cluster, while the worker nodes run the actual containerized applications.

[0003] The init process is the first user-level process started by the kernel. It manages the system startup process and ensures the operation of other processes. In existing technologies, Kubernetes clusters use the dump-init system or the process manager tini to start a dedicated init process, enabling the start and stop of multiple processes in multi-process containers. dump-init is a lightweight process supervisor and initialization system designed specifically for container environments, while tini is an extremely small and secure Unix init system and process manager.

[0004] However, due to the limitations of the existing dump-init system or tini, when the first process started by the container is not a dedicated init process, after the main process receives a stop signal and is terminated, the business signal is not passed to the child process. Instead, a SIGKILL signal is automatically sent to the child process. The child process is forcibly terminated after receiving the SIGKILL signal, thus affecting business consistency. Summary of the Invention

[0005] In view of the above problems, this 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 solution is as follows:

[0006] A first aspect of the present application provides a signal transmission method, comprising:

[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 a SIGTERM signal according to the variable values ​​of the parameter variables;

[0008] In response to receiving a delete instruction for a target container, acquiring a signal sending parameter of the target container, the signal sending parameter including a signal sending tag;

[0009] After using 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, adding a pre-stop hook to the resource declaration file, and creating the target container group based on the resource declaration file;

[0014] The target container is run in the target container group, where the target container includes a plurality of threads.

[0015] In a possible implementation, obtaining the signal sending parameter of the target container includes:

[0016] Search the resource declaration file of the target container to determine whether the signal sending tag exists; if so, obtain the signal sending parameters from the resource declaration file of the target container.

[0017] In a possible implementation, the parameter variable further includes a waiting time variable, and the signal sending parameter further 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, executing the signal sending script includes:

[0018] The signal sending script is executed after 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, 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, configured 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 configured to execute sending of a SIGTERM signal according to the variable values ​​of the parameter variables;

[0022] a sending parameter acquiring 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] and a script execution unit, configured to execute the signal sending script using the signal sending parameter of the target container as a variable value of a 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 apparatus further includes a container creating unit, configured 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, comprising 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 configured 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] In a fifth aspect, 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 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 a plurality of 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 for indicating 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 labels. 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. BRIEF DESCRIPTION OF THE DRAWINGS

[0034] The above and other features, advantages, and aspects of the various embodiments of the present disclosure will become more apparent with reference to the following detailed description in conjunction with the accompanying drawings. Throughout the drawings, the same or similar reference numerals represent the same or similar elements. It should be understood that the drawings are schematic and that the originals and elements are not necessarily drawn to scale.

[0035] Figure 1 A schematic diagram of the system architecture provided for this application;

[0036] Figure 2 1 shows an optional hardware structure diagram of the terminal 100;

[0037] Figure 3 shows a schematic structural diagram of a server 200;

[0038] Figure 4 A schematic diagram of a flow chart of a signal transmission method provided in an embodiment of the present application;

[0039] Figure 5 A flowchart of a specific implementation of a signal transmission method provided in an embodiment of the present application;

[0040] Figure 6 A comparison diagram of signal transmission effects provided by an embodiment of the present application;

[0041] Figure 7 A schematic structural diagram 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 accompanying drawings. The terms used in the implementation methods 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 are not necessarily 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, and this is merely a way of distinguishing the objects of the same attributes when describing them 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 present application provides a signaling method and related apparatus that can be applied in the field of containerization technology, specifically in scenarios where a signal is sent when a multi-process container (or multi-threaded container) is shut down. When the first process started by a multi-process container is not a dedicated init process, signaling can be used to prevent child processes from being forcibly terminated, ensuring service consistency.

[0047] This application can be applied to, but is not limited to, applications with container management capabilities or cloud services provided by cloud-side servers. The following describes each of these:

[0048] See also Figure 1 , Figure 1 Schematic diagram of a system architecture is shown. The system may include a terminal 100 and a server 200. The server 200 may include one or more servers ( Figure 1 In the example, a server is included, 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. 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 need for 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, an in-vehicle 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 restrictions on this.

[0053] Figure 2 A schematic diagram of an optional hardware structure 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 understand that Figure 2 These are merely examples of terminals or multi-function devices and do not limit the terminal or multi-function device. The terminal or multi-function device may include more or fewer components than shown in the figure, or may combine certain components or different components.

[0055] The input unit 130 is used to receive input digital or character information and generate key signal input related to user settings and function control of the portable multifunction device. Specifically, the input unit 130 may include a touch screen 131 (optional) and / or other input devices 132. The touch screen 131 can detect user touch operations on or near it (for example, operations performed on or near the touch screen using a finger, joint, stylus, or any other suitable object) and activate corresponding connected devices according to pre-set programs. The touch screen can detect user touch actions on the touch screen, convert these touch actions into touch signals, and transmit them to the processor 170. It can also receive and execute commands sent by the processor 170; these touch signals include at least touch point coordinate information. The touch screen 131 provides both input and output interfaces between the terminal 100 and the user. Touch screens can be implemented using various types, including resistive, capacitive, infrared, and surface acoustic wave. In addition to the touch screen 131, the input unit 130 may also include other input devices. Specifically, the 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 an interface for signal transmission, processing results, etc.

[0058] Memory 120 can be used to store instructions and data. It primarily includes an instruction storage area and a data storage area. The data storage area can store various data, such as multimedia files and text. The instruction storage area can store software units such as the operating system, applications, and instructions required for at least one function, or subsets or extensions thereof. It may also include non-volatile random access memory (RAM). It provides processor 170 with management functions for the hardware, software, and data resources within the computing and processing device, supporting control software and applications. It is also used to store multimedia files and running programs and applications.

[0059] The processor 170 is the control center of the terminal 100. It connects all components of the terminal 100 using various interfaces and circuits. By executing instructions stored in the memory 120 and accessing data stored therein, it executes various functions of the terminal 100 and processes data, thereby providing overall control of the terminal device. Optionally, the processor 170 may include one or more processing units. Preferably, the processor 170 may integrate an application processor and a modem processor, with the application processor primarily processing the operating system, user interface, and application programs, while the modem processor primarily handles wireless communications. It is understood that the modem processor may not be integrated into the processor 170. In some embodiments, the processor and memory may be implemented on a single chip; in other embodiments, they may be implemented on separate chips. The processor 170 may also generate corresponding operational control signals and send them to the corresponding components of the computing and processing device. It may also read and process data in the software, particularly the data and programs in the memory 120, to enable the various functional modules therein to perform their corresponding functions, thereby controlling the corresponding components to operate as instructed.

[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 implement corresponding functions.

[0061] The RF unit 110 (optional) can be used to send and receive information or receive and send signals during calls. For example, it receives downlink information from the base station and passes it to the processor 170 for processing; in addition, it sends uplink data to the base station. Typically, the RF circuit includes, but is not limited to, an antenna, at least one amplifier, a transceiver, a coupler, a low-noise amplifier (LNA), a duplexer, etc. Furthermore, the RF unit 110 can communicate with network devices and other devices via wireless communication. This wireless communication can use any communication standard or protocol, including but not limited to Global System of Mobile Communications (GSM), General Packet Radio Service (GPRS), Code Division Multiple Access (CDMA), Wideband Code Division Multiple Access (WCDMA), Long Term Evolution (LTE), email, Short Messaging Service (SMS), etc.

[0062] In this embodiment of the present application, the radio frequency 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, and power consumption.

[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 other devices for communication, 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 will not be described in detail here. Some or all of the methods described below can be applied to 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 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 volatile memory, such as random access memory (RAM). The memory 204 may also include non-volatile memory, such as read-only memory (ROM), flash memory, hard drive (HDD), or 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 shown 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 the sending of SIGTERM signal according to the variable values ​​of the parameter variables, that is, to send 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 parameters include a signal transmission tag, and the signal transmission tag includes a signal transmission rule.

[0080] In an optional embodiment, during the creation phase of the target container, the signaling parameters of the target container are stored in a resource declaration file of the target container. The signaling 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 a SIGTERM signal to each process of the target container.

[0083] It can be seen from the above technical solution that an embodiment of the present application provides a signal sending method, in which a 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 SIGTERM signals to each process of the target container according to the signal sending rules indicated by the signal sending labels. 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 ConfigMap stores configuration data, including a preset signaling script. The signaling script is a script for sending a SIGTERM termination signal based on parameter variables. Specifically, the signaling script includes multiple parameter variables, including a signaling label variable and a wait time variable.

[0087] It should be noted that ConfigMap is a resource object in Kubernetes. Through this resource object, configuration data can be stored in the Kubernetes cluster and injected into containers when needed. By using ConfigMap, configuration information is separated from program code, 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 (i.e., 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 a pod, as the smallest deployable computing unit, contains multiple containers and provides them with a unified operating environment and management capabilities. A multi-threaded container is an instance running within 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 signaling parameters are projected into the resource declaration file via a webhook, and a pre-stop hook is configured within the container lifecycle. The signaling parameters are projected into the container group definition via a webhook, and a pre-Stop hook is added to the container definition to configure the container lifecycle.

[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 rules. 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 order from small to large process numbers, and the second signal sending label is recorded as "sig:reorder", indicating that the SIGTERM signal is sent in order from large to small process numbers.

[0095] In the present embodiment, SIGTERM signal is the standard signal for requesting process termination in Linux. When using SIGTERM signal 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 lifecycle. 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 runs 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, responsible for managing the lifecycle of containers and container groups on each node.

[0100] It's also worth noting that the correspondence between resource declaration files and container group identifiers is stored in the distributed key-value storage system ETCD. ETCD is also used to store cluster state, 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, and nodes.

[0101] S505: The target container group runs multiple processes through a multi-threaded container.

[0102] In this embodiment, a multi-threaded container is used to run multiple processes of a business. Each process is identified by a number. 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 target container group creation request, a creation instruction is issued to create the target container group according to the resource declaration file. Furthermore, the signal sending parameters are projected into the resource declaration file through the lifecycle hook. After adding a pre-stop hook to the resource declaration file, the target container group is created based on the resource declaration file and a target container is run within the target container group, where the target container includes multiple threads. This method pre-customizes the signal sending script and modifies the target container group's resource declaration file, thereby enabling customized configuration of the target container's signal sending parameters.

[0104] S506: Receive a target container deletion request through the Kubernetes API server, and send the target container deletion request to the target container through the Kubelet component.

[0105] In this embodiment, the target container deletion request includes a SIGTERM signal and a target container identifier, and is used to delete the target container. The target container is any multi-threaded container in the target container group. The target container identifier is composed of the target container group identifier and the target container identifier, and is used to uniquely identify the target container.

[0106] S507: Determine whether there is a signal sending tag in the resource declaration file of the target container group to which the target container belongs.

[0107] In this embodiment, the resource declaration file of the target container group contains a signal sending tag, indicating that the target container group is easy to 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 the resource declaration file of the target container group contains a signal sending tag, S508 is executed.

[0109] If the target container is a single-threaded container or the signal sending tag is not present in the resource declaration file, a 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 terminates. If the target container is a multi-threaded container, the parent thread receives the SIGTERM signal and terminates, and then forwards a SIGKILL signal to the child process.

[0110] S508: If the target container is a multi-threaded container and the resource declaration file of the target container group contains a signal sending tag, 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 execute the 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 expected time for deleting the iptables rule. Therefore, when the signal sending script and the iptables rule are executed synchronously, the iptables rule is deleted when the waiting time is reached.

[0116] It can be seen from the above technical solution that the signal sending method provided by the embodiment of the present application automatically deploys a configMap resource object for storing signal sending scripts by developing a custom extension component in the Kubernetes cluster, 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, set the waiting time parameter in the signal sending script to take into account graceful shutdown, wait for the iptables rules to be deleted, or the direct connection type LB to be unbound, to avoid requests being sent to containers in the stopped container group.

[0118] Figure 6 A schematic diagram of a signal transmission process comparison provided in an embodiment of the present application is shown in FIG. Figure 6As shown in the figure, taking container A as the first target container, processes C1-P1, C1-P2, and C1-P3 are running within container A. Furthermore, process C1-P1 is not a dedicated init process. In the prior art, after the Kubelet component sends a target container deletion request to the target container, process C1-P1 receives a SIGTERM signal. However, the stop signal that process C1-P1 forwards to processes C1-P2 and C1-P3 is a SIGKILL signal. In this case, processes C1-P2 and C1-P3 are forcibly terminated, resulting in service inconsistencies.

[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 rules. Process C2-P1, process C2-P2, and process C2-P3 receive the SIGTERM signal and start and stop gracefully 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 the preset waiting time, thereby realizing process termination, thereby further improving business consistency.

[0121] In summary, compared with the existing process management tools, they all 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 process shutdown 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 shutdown order can be flexibly configured according to business characteristics.

[0122] Furthermore, through platform-level solutions, all replica sets can implement the function with just one deployment, and whether to use the function can also be customized by configuring the signal sending tag.

[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 rules 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] The above describes a signal sending method provided in an embodiment of the present application. The following describes an apparatus for executing the above signal sending method.

[0125] See also Figure 7 , Figure 7 This is a schematic diagram of the structure of a signal sending device provided in an embodiment of the present application. The signal sending device is configured in the client, such as Figure 7 As shown, the signal sending device 700 includes:

[0126] A script mounting unit 701 is configured 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 configured to execute sending of a SIGTERM signal according to the variable values ​​of the parameter variables;

[0127] A sending parameter acquiring unit 702 is configured to acquire, in response to receiving a delete instruction for a target container, a signal sending parameter 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 using 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, configured 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 tag exists; 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 signal sending script so as to send a 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] An electronic device is also provided in an embodiment of the present application. Figure 8 , which shows a schematic diagram of the structure of an electronic device suitable for implementing the embodiments of the present application. The electronic device in the embodiments 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 limit 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 based on programs stored in a read-only memory (ROM) 802 or programs loaded from a storage device 808 into a random access memory (RAM) 803. When the electronic device is powered on, the RAM 803 also stores various programs and data required for the operation of the electronic device. The processing device 801, ROM 802, and RAM 803 are interconnected 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: an input device 806 including, for example, a touch screen, a touchpad, a keyboard, a mouse, a camera, a microphone, an accelerometer, a gyroscope, etc.; an output device 807 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; a storage device 808 including, for example, a memory card, a hard disk, etc.; and a communication device 809. The communication device 809 may allow the electronic device to communicate with other devices wirelessly or by wire to exchange data. Figure 8 The electronic device is shown with various devices, but it should be understood that it is not required to implement or possess all of 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 illustrative, wherein the units described as separate components may or may not be physically separate, 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 across multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the present embodiment. In addition, in the drawings of the device embodiments provided in this application, the connection relationship between the modules indicates that there is a communication connection between them, which can be specifically implemented as one or more communication buses or signal lines.

[0142] Through the description of the above embodiments, those skilled in the art can clearly understand that the present application can be implemented by means of software plus necessary general hardware, and of course can also be implemented by special hardware including application-specific integrated circuits, special CPUs, special memories, special components, etc. In general, all functions performed by computer programs can be easily implemented with corresponding hardware, and the specific hardware structures used to implement the same function can also be diverse, such as analog circuits, digital circuits or special circuits, etc. However, for the present application, software program implementation is a better implementation method in most cases. Based on this 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's floppy disk, USB flash drive, mobile hard disk, ROM, RAM, magnetic disk or optical disk, etc., and includes a number of instructions to enable a computer device (which can be a personal computer, training equipment, or network equipment, 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 can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can 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 can be transmitted from a website, computer, training equipment or data center to another website, computer, training equipment or data center via a wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) method. The computer-readable storage medium can be any available medium that a computer can store or a data storage device such as a training device or data center that includes one or more available media integrations. The available medium can 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)).

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 a SIGTERM signal according to the variable values ​​of the parameter variables; In response to receiving a delete instruction for a target container, acquiring a signal sending parameter of the target container, the signal sending parameter including a signal sending tag; After using 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; 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, adding a pre-stop hook to the resource declaration file, and creating the target container group based on the resource declaration file; Running the target container in the target container group, where the target container includes multiple threads; Acquiring the signal sending parameters of the target container includes: Search the resource declaration file of the target container to determine whether the signal sending tag exists; if so, obtain the signal sending parameters from the resource declaration file of the target container.

2. The signal transmission method according to claim 1, wherein: The parameter variable further includes a waiting time variable, and the signal sending parameter further 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 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, so as to send a SIGTERM signal to each process of the target container according to the signal sending rule after the waiting time.

3. The signal transmission method according to claim 2, wherein: The signal sending tag is one of a first signal sending tag and a second signal sending tag, wherein the first signal sending tag indicates that the SIGTERM signal is sent in ascending order of process numbers, and the second signal sending tag indicates that the SIGTERM signal is sent in descending order of process numbers.

4. A signal sending device, characterized in that: include: A script mounting unit, configured 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 configured to execute sending of a SIGTERM signal according to the variable values ​​of the parameter variables; a sending parameter acquiring 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, configured to execute the signal sending script using the signal sending parameter of the target container as a variable value of a 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; The signal sending device further includes a container creation unit, configured 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; Projecting the signal sending parameter into a resource declaration file through the lifecycle hook, adding a pre-stop hook to the resource declaration file, and then creating the target container group based on the resource declaration file; running the target container in the target container group, wherein the target container includes multiple threads; The sending parameter acquiring unit acquires the signal sending parameter of the target container, including: Search the resource declaration file of the target container to determine whether the signal sending tag exists; if so, obtain the signal sending parameters from the resource declaration file of the target container.

5. A computer program product, characterized in that The method comprises computer-readable instructions, which, when executed on an electronic device, enable the electronic device to implement the signal sending method according to any one of claims 1 to 3.

6. An electronic device, characterized in that: comprising at least one processor and a memory connected to the processor, wherein: The memory is used to store computer programs; The processor is configured to execute the computer program so that the electronic device can implement the signal sending method according to any one of claims 1 to 3.

7. 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 according to any one of claims 1 to 3.

Citation Information

Patent Citations

  • Container reconstruction method and device

    CN116545985A