A load distribution method, configuration method and hardware of a Kubernetes backend service
By setting up shared memory and importing load balancing parameters in Kubernetes' nginx, the problem of Ingress-nginx's inability to control nginx load was solved, achieving dynamic load balancing and reducing the probability of blocking caused by high concurrency.
Patent Information
- Application Number
- CN202111565594.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-20
- Publication Date
- 2026-01-02
- Estimated Expiration
- 2041-12-20
AI Technical Summary
Ingress-nginx cannot effectively control nginx load balancing in Kubernetes, leading to unbalanced load on backend services under high concurrency, and the problem of unbalanced load cannot be solved.
By setting up a target shared memory in Kubernetes' nginx to store load balancing execution files and importing the target load balancing parameters using Ingress-nginx, nginx runs these files to achieve dynamic load balancing, avoiding the need to restart nginx.
It enables dynamic adjustment of load balancing without restarting nginx, reducing the probability of blocking caused by high concurrency and improving the flexibility and efficiency of load distribution.
Smart Images

Figure CN114490024B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present document relates to the technical field of Internet application, and particularly relates to a Kubernetes backend service load distribution method, a configuration method and hardware. BACKGROUND
[0002] Kubernetes is an orchestration tool for managing containerization on multiple hosts in a cloud platform, which provides containerized deployment for services and supports container planning, updating and maintenance. Containers occupy less resources and are deployed quickly, and each application can be packaged into a container image without being combined with the rest of the application stack, which provides a consistent running environment from research and development testing to production.
[0003] In Kubernetes, the IP addresses of services and Pods can only be used within the cluster network and are invisible to applications outside the cluster. In order to enable external applications to access services within the cluster, Kubernetes currently provides the following schemes for exposing services within the cluster: LoadBlancer Service, NodePort Service and Ingress.
[0004] For the above Ingress scheme, Kubernetes sets Ingress-nginx (a component for managing nginx) to be responsible for implementing external exposure for the backend service of nginx. The related exposure process involves the load distribution of nginx to the backend service, and currently Ingress-nginx does not have the ability to control nginx for load regulation. When the backend service is high in concurrency, the problem of uneven load cannot be solved. SUMMARY
[0005] Embodiments of the present application aim to provide a Kubernetes backend service load distribution method, a configuration method and hardware, which can enable Ingress-nginx to implement load balancing regulation for the backend service of Kubernetes.
[0006] To solve the above technical problems, the embodiments of the present application are implemented as follows:
[0007] In a first aspect, a Kubernetes backend service load distribution method is provided, and Kubernetes includes Ingress-nginx and nginx. The method comprises the following steps:
[0008] The Ingress-nginx imports the target load distribution parameters for load balancing adjustment of the backend service of the Kubernetes into the target shared memory of the nginx configured for load distribution of the backend service, and the target shared memory stores a load distribution execution file for the backend service;
[0009] The nginx runs the load distribution execution file in the target shared memory to load distribute the backend service according to the target load distribution parameters imported in the target shared memory.
[0010] In a second aspect, a configuration method for implementing load control of a Kubernetes backend service is provided, the Kubernetes including an Ingress-nginx and a nginx corresponding to the Ingress-nginx, and the method includes:
[0011] configuring the nginx with a target shared memory for load distribution of the backend service of the Kubernetes, and adding a load distribution execution file for the backend service into the target shared memory;
[0012] configuring the nginx with a communication interface of the target shared memory, the communication interface having a communication protocol for receiving load distribution parameters imported into the target shared memory;
[0013] configuring the Ingress-nginx with a load adjustment execution component for receiving target load distribution parameters for load balancing adjustment of the backend service of the Kubernetes, and importing the target load distribution parameters into the target shared memory of the nginx through the communication interface according to the communication protocol, wherein the nginx runs a load distribution execution file in the target shared memory to load distribute the backend service according to the target load distribution parameters imported in the target shared memory.
[0014] In a third aspect, a Kubernetes system is provided, including an Ingress-nginx and a nginx; wherein:
[0015] The Ingress-nginx imports the target load distribution parameters for load balancing adjustment of the backend service of the Kubernetes into the target shared memory of the nginx configured for load distribution of the backend service, and the target shared memory stores a load distribution execution file for the backend service;
[0016] The nginx runs a load distribution execution file in the target shared memory, and performs load distribution for the backend service according to the target load distribution parameter imported into the target shared memory.
[0017] In a fourth aspect, an electronic device is provided, which includes a memory, a processor, and a computer program stored in the memory and executable on the processor, and the computer program is executed by the processor to perform the following steps:
[0018] The target shared memory for load distribution of the backend service of the Kubernetes is set for the nginx, and a load distribution execution file for the backend service is added into the target shared memory;
[0019] A communication interface of the target shared memory is set for the nginx, and the communication interface has a communication protocol for receiving a load distribution parameter imported into the target shared memory;
[0020] A load adjustment execution component is set for the Ingress-nginx, and the load adjustment execution component is used to receive a target load distribution parameter for load balancing adjustment of the backend service of the Kubernetes, and import the target load distribution parameter into the target shared memory of the nginx according to the communication protocol, wherein the nginx runs a load distribution execution file in the target shared memory, and performs load distribution for the backend service according to the target load distribution parameter imported into the target shared memory.
[0021] In a fifth aspect, a computer readable storage medium is provided, and the computer readable storage medium stores a computer program, and the computer program is executed by a processor to implement the following steps:
[0022] The target shared memory for load distribution of the backend service of the Kubernetes is set for the nginx, and a load distribution execution file for the backend service is added into the target shared memory;
[0023] A communication interface of the target shared memory is set for the nginx, and the communication interface has a communication protocol for receiving a load distribution parameter imported into the target shared memory;
[0024] A load adjustment execution component is set for the Ingress-nginx, which is used to receive target load allocation parameters for load balancing adjustment of the backend service of the Kubernetes, and according to the communication protocol, the target load allocation parameters are imported into the target shared memory of the nginx through the communication interface, wherein the nginx runs the load allocation execution file in the target shared memory, and performs load allocation for the backend service according to the target load allocation parameters imported in the target shared memory.
[0025] The device of the embodiment of the application sets a target shared memory for load allocation of a backend service in the nginx of the Kubernetes, and the target shared memory stores a load allocation execution file for the backend service, so that based on the Ingress-nginx of the Kubernetes, target load allocation parameters for load balancing adjustment of the backend service can be imported into the target shared memory, so that the nginx runs the load allocation execution file in the target shared memory to perform load allocation for the backend service according to the target load allocation parameters in the target shared memory. Based on the load adjustment mode of the load allocation parameter import, the backend service can realize dynamic load balancing without the need to restart the nginx, and the probability of congestion caused by high concurrency of the backend service can be reduced. BRIEF DESCRIPTION OF DRAWINGS
[0026] In order to more clearly illustrate the technical solutions in the embodiments of the application or the prior art, the following will briefly introduce the drawings needed to be used in the embodiments or prior art description. Obviously, the drawings in the following description are only some embodiments of the application, and other drawings can be obtained by those skilled in the art without creative labor.
[0027] Figure 1 The flowchart of the load allocation method of the backend service of the Kubernetes provided by the embodiment of the application.
[0028] Figure 2 The flowchart of the configuration method for realizing load control of the backend service of the Kubernetes provided by the embodiment of the application.
[0029] Figure 3 The logic diagram of the configuration method for realizing load control of the backend service of the Kubernetes provided by the embodiment of the application.
[0030] Figure 4 The structural diagram of the Kubernetes provided by the embodiment of the application.
[0031] Figure 5 The structural schematic diagram of the electronic device provided by the embodiment of the present application is shown. DETAILED DESCRIPTION
[0032] In order for those skilled in the art to better understand the technical solutions in the specification, the technical solutions in the embodiments of the present application will be described clearly and completely in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only some of the embodiments of the specification, not all. Based on the embodiments in the specification, all other embodiments obtained by those of ordinary skill in the art without creative labor should be within the scope of protection of the specification.
[0033] As described above, the Kubernetes currently using the Ingress scheme is responsible for exposing the backend service of nginx by Ingress-nginx. The related exposure process involves the load distribution of nginx to the backend service, and the Ingress-nginx currently does not have the ability to control nginx to perform load regulation. When the backend service is high in concurrency, the problem of uneven load cannot be solved. Therefore, the embodiment of the present application aims to propose a technical solution capable of realizing load balancing adjustment of the backend service of Kubernetes.
[0034] Figure 1 is the flowchart of the load distribution method of the backend service of Kubernetes according to the embodiment of the present application, wherein the Kubernetes includes Ingress-nginx and nginx, and the specific steps are as follows:
[0035] S102, the Ingress-nginx imports the target load distribution parameter for load balancing adjustment of the backend service of Kubernetes into the target shared memory set by nginx for load distribution of the backend service, and the target shared memory stores the load distribution execution file for the backend service.
[0036] Among them, the load distribution parameter includes the load weight corresponding to each port of the backend service, and the load of each port of the backend service is distributed based on the load proportion corresponding to the load weight of each port of the backend service.
[0037] For example, a backend service A is configured with three ports, i.e., port 1, port 2 and port 3. Assuming that the load weight ratio between port 1, port 2 and port 3 is 2:5:3, and the request of the backend service A is taken as a load statistic unit, then 2:5:3 means that in every 10 requests of the backend service A, 2 requests are allocated to port 1, 5 requests are allocated to port 2, and 3 requests are allocated to port 3. It should be understood that the load statistic unit can also be the traffic of the backend service A, which is not limited herein.
[0038] As can be seen, the load distribution parameters can be used to allocate corresponding loads to the ports of the backend service. Therefore, in actual application, the load distribution parameters can be dynamically determined according to the load state of the Kubernetes backend service in real time.
[0039] Here, the embodiment of the application can set a load control component for Kubernetes to monitor the load state of the backend service of Kubernetes, determine the load distribution parameters according to the load state of the backend service, and then submit the load distribution parameters to Ingress-nginx. In addition, the technical personnel can also submit the load distribution parameters to Ingress-nginx through the external interface of Kubernetes, which will not be repeated here.
[0040] On the other hand, nginx is configured with a communication interface for external communication for the target shared memory, and Ingress-nginx can send the target load distribution parameters to the communication interface of the target shared memory according to the communication protocol of the communication interface after obtaining the target load distribution parameters, so as to import the target load distribution parameters into the target shared memory. If the load distribution parameters already exist in the target shared memory, the target load distribution parameters can overwrite the existing load distribution parameters.
[0041] As an exemplary introduction, the communication protocol of the communication interface can include, but is not limited to, the hypertext transfer protocol (HTTP). Ingress-nginx can specify the latest load distribution parameters uploaded to the target shared memory (i.e., sent to the communication interface) through the communication interface of the target shared memory based on the post method of the hypertext transfer protocol; and / or, nginx can also request the latest load distribution parameters from Ingress-nginx through the communication interface of the target shared memory based on the get method of the hypertext transfer protocol.
[0042] S104, nginx runs the load distribution execution file in the target shared memory to perform load distribution for the backend service according to the target load distribution parameters in the target shared memory.
[0043] Specifically, the embodiment of the present application can use Lua code language to write a load distribution execution file, which mainly includes:
[0044] a loop function for looping to extract load distribution parameters in the target shared memory; and
[0045] a cjson.safe function library for parsing the load distribution parameters extracted by the loop function in Lua code language.
[0046] Based on the above load distribution execution file, after the process of Nginx accesses the target shared memory, the load distribution parameters of the target shared memory can be repeatedly accessed and obtained in a loop, and the load distribution of the backend service is provided according to the load distribution parameters.
[0047] The method of the embodiment of the present application sets a target shared memory for load distribution of a backend service in the nginx of Kubernetes, and the target shared memory stores a load distribution execution file for the backend service, so that based on the Ingress-nginx of Kubernetes, the target load distribution parameters for load balancing adjustment of the backend service can be imported into the target shared memory, so that the nginx runs the load distribution execution file in the target shared memory to perform load distribution for the backend service according to the target load distribution parameters in the target shared memory. Based on the load adjustment mode of the load distribution parameter import, the backend service can realize dynamic load balancing without restarting the nginx, and the probability of congestion caused by high concurrency of the backend service can be reduced.
[0048] Figure 2 is a flowchart of the configuration method of the embodiment of the present application for load control of the backend service of Kubernetes, including the following steps:
[0049] S202, a target shared memory for load distribution of a backend service of Kubernetes is set for nginx, and a load distribution execution file for the backend service is added to the target shared memory.
[0050] S204, a communication interface of the target shared memory is set for the nginx, and the communication interface has a communication protocol for obtaining load distribution parameters provided by a load balancing adjustment component.
[0051] S206, setting a load adjustment execution component for Ingress-nginx, the load adjustment execution component is used to import target load distribution parameters for load balancing adjustment of the backend service into the target shared memory of nginx according to the communication protocol, wherein the nginx runs the load distribution execution file in the target shared memory, and distributes the load for the backend service according to the target load distribution parameters imported in the target shared memory.
[0052] The method for configuring the load control function of the backend service of kubernetes will be described in detail below.
[0053] The embodiments of the application are used to implement the load control capability for the backend service of Ingress-nginx. Specifically, it includes:
[0054] I. Target shared memory creation of nginx:
[0055] Here, a target shared memory written in Lua code language needs to be created on nginx to realize dynamic load balancing based on port load weight.
[0056] The target shared memory creation of nginx needs to configure a line of code for nginx-template ConfigMap. The file where the code is located is nginx.tmpl. The code content is: lua_shared_dict weight_data 20M (the size is only for example); this code indicates that a 20M shared memory needs to be created on nginx.
[0057] II. Dynamic load distribution parameter (load weight of each port) generation
[0058] A load adjustment execution component is set for Ingress-nginx to provide an HTTP API interface, expose 10500 communication ports to receive externally submitted dynamic load distribution parameters, and then access the URI of 10246 communication ports of nginx's POST request / configuration / weights to finally store the dynamic load distribution parameters in the weight_data of the target shared memory.
[0059] As an exemplary introduction, the code data of the HTTP POST to the dynamic load distribution parameter is: [{"address":"192.168.166.209","port":"8080","weight":"20"},{"address":"192.168.166.210","port":"8080","weight":"30"}], wherein the field value of the address field indicates the address of the backend service, the field value of the port field indicates the port of the backend service, and the field value of the weight field indicates the load weight of the port of the backend service, and the load weight value is greater than or equal to 0 and less than or equal to 100.
[0060] It should be noted here that the manner of obtaining the load distribution parameter is not specifically limited herein. In addition to obtaining the load distribution parameter from the outside through the 10500 communication interface, the load adjustment execution component can also monitor the load of each port of the backend service by itself and determine the corresponding load weight of each port for the purpose of load balancing.
[0061] III. Load distribution parameter receiving
[0062] The configuration.lua file (a file in the Ingress-nginx software source code) of the Ingress-nginx is modified, and the configuration.lua realizes the HTTP interface of storing the dynamic data of the nginx into the shared memory.
[0063] The nginx-ingress-controller can store and update the dynamic backend data in the configuration_data by initiating the HTTP POST request through the 10246 communication port opened by the nginx and requesting the address of / configuration / backends.
[0064] On the basis of the original HTTP interface, a new HTTP interface is needed to store, update, and obtain the dynamic load distribution parameter.
[0065] Under the function_M.call() method in the configuration.lua file, the interface processing of the URI of / configuration / weights is added, and this interface stores the load weight value carried in the POST request into the target shared memory weight_data of the nginx created in the previous step through the POST request. At the same time, the HTTP GET method is implemented, and the load weight data stored in the weight_data can be viewed through the GET method.
[0066] IV. Load balancing implementation based on load distribution parameters
[0067] Modify the util.lua file of Ingress-nginx, and add a get_weight function in the util.lua file. The function receives an IP address plus port string and returns the load weight corresponding to the backend service of the IP address plus port.
[0068] The get_weight function (written in Lua language) obtains the stored weight data from the weight_data nginx shared memory. The weight data is decoded using the cjson.safe function library, and after decoding, the weight data becomes a table data structure object in Lua language.
[0069] As an example, the load weight data object content is: [{"address":"192.168.166.209","port":"8080","weight":"20"},{"address":"192.168.166.210","port":"8080","weight":"30"}]
[0070] Loop the weight data object, get the IP address through the key value address, get the port through the key value port, and use ":" to concatenate the IP address and port. The obtained string is compared with the IP address plus port string passed through the function parameter of the get_weight function. If they are the same, get the weight value through the key value weight, judge whether the value is a number, and judge whether the weight value is in the range of 0 <= weight value <= 100.
[0071] If it is in the specified range, return the weight value. If it is not, return the weight value as 0.
[0072] When this function loops the backend node information data, it calls the get_weight function to pass the IP address plus port data, and returns the weight value corresponding to the backend node through the get_weight function, and assigns the weight value to the backend node object.
[0073] In this way, the backend node object is no longer the default load weight of 0, but the load weight according to the dynamic load distribution parameters.
[0074] Figure 4is a structural schematic diagram of a Kubernetes system 400 according to an embodiment of the present application, comprising: an Ingress-nginx 410 and a nginx 420 corresponding to the Ingress-nginx 410. Wherein:
[0075] The Ingress-nginx 410 imports target load distribution parameters for load balancing adjustment of a backend service of the Kubernetes 400 into a target shared memory 4201 set by the nginx 420 for load distribution of the backend service, and the target shared memory 4201 stores a load distribution execution file for the backend service.
[0076] The nginx 420 runs the load distribution execution file in the target shared memory 4201 to perform load distribution for the backend service according to the target load distribution parameters imported in the target shared memory 4201.
[0077] The Kubernetes according to the embodiment of the present application sets a target shared memory for load distribution of a backend service in a nginx, and the target shared memory stores a load distribution execution file for the backend service, so that target load distribution parameters for load balancing adjustment of the backend service can be imported into the target shared memory based on the Ingress-nginx of the Kubernetes, and the nginx runs the load distribution execution file in the target shared memory to perform load distribution for the backend service according to the target load distribution parameters in the target shared memory. Based on this load distribution parameter import-based load adjustment mode, the backend service can realize dynamic load balancing without the need to restart the nginx, and the probability of congestion caused by high concurrency of the backend service can be reduced.
[0078] Optionally, the nginx is provided with a communication interface of the target shared memory, and a communication protocol of the communication interface comprises a hypertext transfer protocol; wherein the target shared memory receives load distribution parameters provided by the Ingress-nginx and needing to be imported in a post mode and / or a get mode of the hypertext transfer protocol through the communication interface. Optionally, the load distribution parameters comprise load weights corresponding to each port of the backend service, and the nginx allocates load for each port of the backend service based on a load proportion corresponding to the load weight of each port of the backend service after running the load distribution execution file.
[0079] Optionally, the data of the load distribution parameter comprises an address field, a port field and a weight field, wherein a field value of the address field represents a backend service address, a field value of the port field represents a port of the backend service, and a field value of the weight field represents a load weight of the port of the backend service.
[0080] Optionally, the load distribution execution file is written based on a Lua code language, and is provided with a loop function for looping to extract the load distribution parameter in the target shared memory, and a cjson.safe function library for performing Lua code language analysis on the load distribution parameter extracted by the loop function.
[0081] Optionally, the Kubernetes further comprises a load control component; the load control component determines target load distribution parameters for load balancing adjustment of the backend service of the Kubernetes based on a load state of the backend service, and sends the target load distribution parameters to the Ingress-nginx.
[0082] Obviously, the Kubernetes system of the embodiments of the present specification can be used as Figure 1 the execution subject of the method shown in the Figure 1 steps and corresponding functions of the method shown in the
[0083] Figure 5 is a structural schematic diagram of an electronic device of an embodiment of the present specification. Please refer to Figure 5 At the hardware level, the electronic device comprises a processor, and optionally further comprises an internal bus, a network interface and a memory. The memory can contain a memory such as a high-speed random access memory (RAM), and can also include a non-volatile memory such as at least one disk memory. Of course, the electronic device can also include other hardware required by the business.
[0084] The processor, the network interface and the memory can be connected with each other through an internal bus, which can be an ISA (Industry Standard Architecture) bus, a PCI (Peripheral Component Interconnect) bus or an EISA (Extended Industry Standard Architecture) bus, etc. The bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 5 Only one bidirectional arrow is used to represent the bus, but it does not mean that there is only one bus or only one type of bus.
[0085] The memory is used to store programs. Specifically, the program can include program code including computer operation instructions. The memory can include internal memory and non-volatile memory, and provide instructions and data for the processor.
[0086] The processor reads the corresponding computer program from the non-volatile memory into the memory and then runs, and forms a configuration method of a Kubernetes backend service at a logical level. The processor executes the program stored in the memory, and is specifically used for executing the following operations:
[0087] The target shared memory for load distribution of the backend service of the Kubernetes is set for the nginx, and a load distribution execution file for the backend service is added to the target shared memory.
[0088] The communication interface of the target shared memory is set for the nginx, and the communication interface has a communication protocol for receiving load distribution parameters imported into the target shared memory.
[0089] The load adjustment execution component is set for the Ingress-nginx, and the load adjustment execution component is used to receive target load distribution parameters for load balancing adjustment of the backend service of the Kubernetes, and import the target load distribution parameters into the target shared memory of the nginx through the communication interface according to the communication protocol, wherein the nginx runs the load distribution execution file in the target shared memory, and performs load distribution for the backend service according to the target load distribution parameters imported into the target shared memory.
[0090] The electronic device of the embodiment of the present application sets a target shared memory for load distribution of a backend service in the nginx of Kubernetes, the target shared memory stores a load distribution execution file for the backend service, so that based on the Ingress-nginx of Kubernetes, the target load distribution parameter for load balancing adjustment of the backend service can be imported into the target shared memory, so that the nginx runs the load distribution execution file in the target shared memory to distribute the load of the backend service according to the target load distribution parameter in the target shared memory. Based on the load adjustment mode of the load distribution parameter import, the backend service can realize dynamic load balancing without restarting the nginx, and the probability of congestion caused by high concurrency of the backend service can be reduced.
[0091] The method disclosed in the embodiments shown in the specification Figure 1 The method disclosed in the embodiments shown in the specification The processor can be an integrated circuit chip having a processing capability of signals. In the implementation process, the steps of the above method can be completed by hardware integrated logic circuits in the processor or instructions in the form of software. The above processor can be a general processor, including a central processing unit (CPU), a network processor (NP), etc.; can also be a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components. The disclosed methods, steps and logic block diagrams in the embodiments of the present application can be implemented or executed. The general processor can be a microprocessor or the processor can also be any conventional processor. The steps of the method disclosed in combination with the embodiments of the present application can be directly embodied as a hardware code processor to execute, or be executed by a combination of hardware and software modules in the code processor. The software module can be located in a random access memory, a flash memory, a read-only memory, a programmable read-only memory or an electrically erasable programmable memory, a register, etc. The storage medium in the art. The storage medium is located in the memory, and the processor reads the information in the memory, and combines the hardware to complete the steps of the above method.
[0092] It should be understood that the electronic device of the embodiments of the present application can realize Figure 2 The functions of the embodiments shown in the specification. Since the principles are the same, this paper will not repeat.
[0093] Of course, in addition to the software implementation, the electronic device of the present specification does not exclude other implementation manners, such as a logic device or a combination of software and hardware, and the like, that is, the execution subject of the following processing flow is not limited to each logic unit, but can also be hardware or a logic device.
[0094] In addition, the embodiment of the present specification also proposes a computer readable storage medium, which stores one or more programs, the one or more programs include instructions.
[0095] The instructions described above, when executed by the portable electronic device including a plurality of application programs, can enable the portable electronic device to perform Figure 2 The method in the illustrated embodiment, and specifically for performing the steps implemented by the member object:
[0096] The target shared memory for load distribution of the backend service of the Kubernetes is set for the nginx, and the load distribution execution file for the backend service is added to the target shared memory.
[0097] The communication interface of the target shared memory is set for the nginx, and the communication interface has a communication protocol for receiving the load distribution parameters imported into the target shared memory.
[0098] The load adjustment execution component is set for the Ingress-nginx, and the load adjustment execution component is used to receive the target load distribution parameters for load balancing adjustment of the backend service of the Kubernetes, and according to the communication protocol, the target load distribution parameters are imported into the target shared memory of the nginx through the communication interface, wherein the nginx runs the load distribution execution file in the target shared memory, and performs load distribution for the backend service according to the target load distribution parameters imported into the target shared memory.
[0099] Those skilled in the art will appreciate that the embodiments of the present specification can be provided as a method, a system or a computer program product. Therefore, the present specification can take the form of a complete hardware embodiment, a complete software embodiment or an embodiment combining software and hardware aspects. Moreover, the present specification can take the form of a computer program product implemented on one or more computer usable storage media (including but not limited to magnetic disk storage, CD-ROM, optical storage, etc.) containing computer usable program code.
[0100] The above describes specific embodiments of the present specification. Other embodiments are within the scope of the appended claims. In some cases, the acts or steps recited in the claims can be performed in a different order than the order in which they are recited and still achieve desirable results. In addition, the processes depicted in the accompanying figures do not necessarily require the particular order shown, or sequential order, to achieve the desired results. In certain implementations, multitasking and parallel processing can be advantageous or necessary.
[0101] The above merely provides embodiments of the present specification and is not intended to limit the present specification. The present specification can have various modifications and changes for those skilled in the relevant art. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present specification shall be included in the scope of claims of the present specification. In addition, all other embodiments obtained by those skilled in the relevant art without creative labor shall belong to the protection scope of the present document.
Claims
1. A load distribution method for Kubernetes backend services, characterized in that, Kubernetes includes Ingress-nginx and nginx, and the method includes: The Ingress-nginx imports the target load balancing parameters for the Kubernetes backend services into the target shared memory set by nginx for load balancing of the backend services. The target shared memory stores the load balancing execution file for the backend services. The load balancing parameters for the Kubernetes backend services include the load weights corresponding to each port of the backend services. The nginx executes the load allocation executable file in the target shared memory and allocates load to each port of the backend service according to the load weight corresponding to the load ratio of each port of the backend service in the target load allocation parameters.
2. The method as described in claim 1, characterized in that, The nginx is configured with a communication interface for the target shared memory, and the communication protocol of the communication interface includes the Hypertext Transfer Protocol; wherein, the target shared memory receives the load distribution parameters to be imported provided by Ingress-nginx through the communication interface, according to the POST and / or GET methods of the Hypertext Transfer Protocol.
3. The method as described in claim 1, characterized in that, The load balancing parameters include the address, port, and weight fields. The address field represents the backend service address, the port of the backend service, and the weight field represents the load weight of the backend service port.
4. The method as described in claim 1, characterized in that, The load balancing execution file is written in Lua and includes the following settings: A loop function is used to repeatedly extract load allocation parameters from the target shared memory; and, The cjson.safe function library is used to parse the load distribution parameters extracted by the loop function using Lua code.
5. The method as described in claim 1, characterized in that, The Kubernetes system also includes a load control component; Before Ingress-nginx imports the target load balancing parameters used for load balancing adjustments of the backend services into the target shared memory set by nginx for load balancing of the backend services, the method further includes: The load control component determines the target load allocation parameters for load balancing adjustments of the backend services based on the load status of the Kubernetes backend services, and sends the target load allocation parameters to the Ingress-nginx.
6. A configuration method for load control in a Kubernetes backend service, characterized in that, Kubernetes includes Ingress-nginx and the corresponding nginx, and the method includes: Configure a target shared memory for nginx to perform load balancing on the Kubernetes backend services, and add the load balancing executable file for the backend services to the target shared memory; Configure a communication interface for the target shared memory in the nginx, the communication interface having a communication protocol for receiving load allocation parameters imported into the target shared memory; A load balancing execution component is configured for Ingress-nginx. This component receives target load allocation parameters for load balancing the Kubernetes backend services and imports these parameters into the target shared memory of nginx via the communication interface, according to the communication protocol. The load allocation parameters for load balancing the Kubernetes backend services include the load weights corresponding to each port of the backend services. nginx runs the load allocation execution file in the target shared memory and allocates load to each port of the backend services according to the load percentage corresponding to the load weights of each port in the target load allocation parameters.
7. A Kubernetes system, characterized in that, This includes Ingress-nginx and nginx; among which: The Ingress-nginx imports the target load balancing parameters for the Kubernetes backend services into the target shared memory set by nginx for load balancing of the backend services. The target shared memory stores the load balancing execution file for the backend services. The load balancing parameters for the Kubernetes backend services include the load weights corresponding to each port of the backend services. The nginx executes the load allocation executable file in the target shared memory and allocates load to each port of the backend service according to the load weight corresponding to the load ratio of each port of the backend service in the target load allocation parameters.
8. An electronic device comprising: A memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that the computer program is executed by the processor: Configure a target shared memory for the nginx corresponding to Ingress-nginx to perform load balancing on the Kubernetes backend services, and add the load balancing execution file for the backend services to the target shared memory; the Kubernetes includes Ingress-nginx and the corresponding nginx. Configure a communication interface for the target shared memory in the nginx, the communication interface having a communication protocol for receiving load allocation parameters imported into the target shared memory; A load balancing execution component is configured for Ingress-nginx. This component receives target load allocation parameters for load balancing the Kubernetes backend services and imports these parameters into the target shared memory of nginx via the communication interface, according to the communication protocol. The load allocation parameters for load balancing the Kubernetes backend services include the load weights corresponding to each port of the backend services. nginx runs the load allocation execution file in the target shared memory and allocates load to each port of the backend services according to the load percentage corresponding to the load weights of each port in the target load allocation parameters.
9. A computer-readable storage medium storing a computer program thereon, characterized in that, When the computer program is executed by the processor, it performs the following steps: Configure a target shared memory for the nginx corresponding to Ingress-nginx to perform load balancing on the Kubernetes backend services, and add the load balancing execution file for the backend services to the target shared memory; the Kubernetes includes Ingress-nginx and the corresponding nginx. Configure a communication interface for the target shared memory in the nginx, the communication interface having a communication protocol for receiving load allocation parameters imported into the target shared memory; A load balancing execution component is configured for Ingress-nginx. This component receives target load allocation parameters for load balancing the Kubernetes backend services and imports these parameters into the target shared memory of nginx via the communication interface, according to the communication protocol. The load allocation parameters for load balancing the Kubernetes backend services include the load weights corresponding to each port of the backend services. nginx runs the load allocation execution file in the target shared memory and allocates load to each port of the backend services according to the load percentage corresponding to the load weights of each port in the target load allocation parameters.
Citation Information
Patent Citations
Load balancing method, device and system
CN111367662A
Traffic shunting method and device, terminal and computer storage medium
CN114650293A