Load balancing method, device and equipment based on Kubernetes, medium and product
By obtaining the load and QPS of each node and Pod in the Kubernetes cluster, and dynamically adjusting the load balancing weight of Pods, the problem that the existing technology cannot adjust the load balancing rules according to the load is solved, and a more flexible and efficient load balancing configuration is achieved.
Patent Information
- Application Number
- CN202411812155.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-10
- Publication Date
- 2025-04-15
AI Technical Summary
The existing technology cannot detect the load conditions of Kubernetes cluster nodes and Pods, and cannot dynamically adjust the load balancing rules based on the load of the server and Pods.
By obtaining the load of each node in the Kubernetes cluster, the load and real-time QPS of each Pod, if the load of any Pod reaches the preset threshold or the real-time QPS reaches the preset value, the load balancing weight of each Pod is dynamically adjusted according to the load of each node and Pod.
It realizes a more flexible and real-time load balancing configuration, improves the forwarding efficiency of the load balancer, reduces the probability of oom exceptions and failure responses on the backend program, and maximizes the response capabilities of the system and each Pod.
Smart Images

Figure CN119829274A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of communication technology, and in particular to a load balancing method, device, equipment, medium and product based on Kubernetes. Background Art
[0002] Kubernetes (k8s for short) is the most widely used container orchestration and management system. Using k8s, containerized applications can be managed and maintained more efficiently. k8s uses components such as endpoint, service, and kube-proxy to complete service discovery and load balancing functions through simple configuration. And for applications, these functions can be used without any additional modifications. Developers only need to focus on the business functions of the application itself, which greatly improves development efficiency.
[0003] In the prior art, the LivenessProbe and ReadinessProbe probes of k8s can detect the liveness and readiness status of the pod, and then dynamically adjust the load balancer rules according to the health status of the pod, such as adding or deleting the IP corresponding to the pod in the load balancer. However, these two probes cannot detect the load of the k8s cluster nodes and pods, and cannot dynamically adjust the load balancing rules according to the load of the server and pod. Summary of the invention
[0004] The technical problem to be solved by the present invention is to provide a load balancing method, device, equipment, medium and product based on Kubernetes, which can dynamically adjust the load balancing weight of each Pod according to the load conditions of each node and Pod in the Kubernete cluster, thereby achieving a more flexible and real-time load balancing configuration, thereby maximizing the responsiveness of the backend service.
[0005] In order to achieve the above object, an embodiment of the present invention provides a load balancing method based on Kubernetes, including:
[0006] Get the load of each node in the Kubernetes cluster and the load and real-time QPS of each Pod;
[0007] If the load of any of the Pods reaches the first preset threshold or the real-time QPS reaches the second preset threshold, the load balancing weight of each Pod is dynamically adjusted according to the load of each node and the load of each Pod.
[0008] As an improvement of the above solution, the second preset threshold is the maximum QPS, and the maximum QPS is calculated as follows:
[0009] Get the memory upper limit and CPU upper limit preset by the Pod;
[0010] The maximum QPS of the Pod is calculated according to the memory upper limit value and the CPU upper limit value.
[0011] As an improvement to the above solution, the load balancing weight of each Pod is dynamically adjusted according to the load of each node and the load of each Pod, including:
[0012] Calculate the first influence coefficient of the memory and CPU of the server on the weight according to the memory upper limit value, the CPU upper limit value, the current memory usage value, and the CPU usage value of the server;
[0013] Calculate the second influence coefficient of the memory and CPU of the Pod on the weight according to the memory upper limit value, the CPU upper limit value, the current memory usage value, and the CPU usage value of the Pod;
[0014] Calculate the load balancing weight of each Pod according to the first influence coefficient and the second influence coefficient;
[0015] The load balancing weight of each Pod is dynamically adjusted according to the load balancing weight.
[0016] As an improvement of the above solution, calculating the load balancing weight of each Pod according to the first influence coefficient and the second influence coefficient includes:
[0017] Calculate the load balancing weight coefficient of each Pod according to the first influence coefficient and the second influence coefficient;
[0018] Calculate the load balancing weight of each Pod based on the load balancing weight coefficient of each Pod.
[0019] As an improvement of the above solution, the calculation formula of the load balancing weight is:
[0020]
[0021] In the formula, w1 represents the load balancing weight of the Pod; k represents the coefficient; η represents the load balancing weight coefficient of the Pod, and n represents the number of Pods. α represents the first impact coefficient, β represents the second impact coefficient, cur_qps represents the real-time QPS, and max_qps represents the maximum QPS; where,
[0022] α=(total_memory1-cur_memory1)*γ+(total_cpu1-cur_cpu1)*δ;
[0023] β=(total_memory2-cur_memory2)*ε+(total_cpu2-cur_cpu2)*θ;
[0024] In the formula, total_memory1 represents the memory upper limit of the server, total_cpu1 represents the CPU upper limit of the server, cur_memory1 represents the current memory usage of the server, and cur_cpu1 represents the current CPU usage of the server; total_memory2 represents the memory upper limit of the Pod, total_cpu2 represents the CPU upper limit of the Pod, cur_memory2 represents the current memory usage of the Pod, and cur_cpu2 represents the current CPU usage of the Pod; γ, δ, ε, and θ all represent coefficients.
[0025] As an improvement of the above solution, the method further includes:
[0026] If the load of any of the nodes reaches a third preset threshold, the load balancing weight of each Pod is dynamically adjusted according to the load of each node and the load of each Pod.
[0027] The embodiment of the present invention further provides a load balancing device based on Kubernetes, including:
[0028] The acquisition module is used to obtain the load of each node in the Kubernetes cluster and the load and real-time QPS of each Pod;
[0029] The adjustment module is used to dynamically adjust the load balancing weight of each Pod according to the load of each node and the load of each Pod if the load of any of the Pods reaches a first preset threshold or the real-time QPS reaches a second preset threshold.
[0030] An embodiment of the present invention also provides a terminal device, including a processor, a memory, and a computer program stored in the memory and configured to be executed by the processor, wherein the processor implements any of the above-mentioned Kubernetes-based load balancing methods when executing the computer program.
[0031] An embodiment of the present invention also provides a computer-readable storage medium, which includes a stored computer program, wherein when the computer program is running, the device where the computer-readable storage medium is located is controlled to execute any of the above-mentioned Kubernetes-based load balancing methods.
[0032] An embodiment of the present invention further provides a computer program product, which includes a computer program or a computer instruction. When the computer program or the computer instruction is executed by a processor, the load balancing method based on Kubernetes is implemented in any one of the above items.
[0033] Compared with the prior art, the beneficial effects of a load balancing method, device, equipment, medium and product based on Kubernetes provided by the embodiments of the present invention are: by obtaining the load of each node in the Kubernetes cluster and the load and real-time QPS of each Pod; if the load of any of the Pods reaches the first preset threshold or the real-time QPS reaches the second preset threshold, the load balancing weight of each Pod is dynamically adjusted according to the load of each node and the load of each Pod. The embodiments of the present invention calculate the load balancing weight in real time by comprehensively considering the resource configuration and usage of the server and the Pod, thereby achieving a more flexible and real-time load balancing configuration; by dynamically adjusting the load balancing rules, the forwarding efficiency of the load balancer is improved, while also reducing the probability of oom exceptions in the backend program and the possibility of failed responses, thereby maximizing the responsiveness of the system and each Pod. BRIEF DESCRIPTION OF THE DRAWINGS
[0034] Figure 1 It is a flow chart of a preferred embodiment of a load balancing method based on Kubernetes provided by the present invention;
[0035] Figure 2 It is a block diagram of a k8s cluster system in a load balancing method based on Kubernetes provided by the present invention;
[0036] Figure 3 It is a timing diagram of a load balancing method based on Kubernetes provided by the present invention;
[0037] Figure 4 It is a structural schematic diagram of a preferred embodiment of a load balancing device based on Kubernetes provided by the present invention;
[0038] Figure 5 It is a structural schematic diagram of a preferred embodiment of a terminal device provided by the present invention. DETAILED DESCRIPTION
[0039] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0040] See also Figure 1 , Figure 1 The present invention provides a flow chart of a preferred embodiment of a load balancing method based on Kubernetes. The load balancing method based on Kubernetes includes:
[0041] S1, obtain the load of each node in the Kubernetes cluster and the load and real-time QPS of each Pod;
[0042] S2: If the load of any of the Pods reaches a first preset threshold or the real-time QPS reaches a second preset threshold, the load balancing weight of each Pod is dynamically adjusted according to the load of each node and the load of each Pod.
[0043] It should be noted that in the k8s cluster system, kube-proxy is an important component responsible for implementing Service load balancing. Kube-proxy can work in multiple modes, including IPVS (IP Virtual Server) mode and iptable mode. The embodiments of the present invention are transparent to these two modes and do not affect the normal operation of kube-proxy. Kube-proxy monitors changes in Service and Endpoint resource objects on the k8s server through the Inform mechanism. Whenever a Service or Endpoint is created, updated or deleted, kube-proxy will receive a notification and update the load balancing rules (i.e., IPVS or iptable rules) accordingly. This monitoring mechanism ensures that when a Service or Endpoint changes, kube-proxy can respond quickly, ensuring the real-time nature of the load balancing rules. However, if the CPU or memory usage of a server node is already very high, the k8s load balancer will still distribute requests to the node. Then it is possible that the Pod on the server itself does not have high resource usage, but the response slows down or an oom exception occurs due to insufficient overall server resources, and then the container is restarted or the Pod is rescheduled, which ultimately leads to an abnormal response to the request, and ultimately reduces system stability. In addition, the resource usage of each Pod in a distributed service is not always consistent. Some Pods are busy due to scheduled tasks, while other Pods are idle because they do not have a distributed lock. However, the load balancer will still forward requests to all Pods according to a fixed strategy (polling, random, hash, etc.). Idle Pods respond normally, while busy Pods respond slowly, reducing system stability.
[0044] Based on this, the embodiment of the present invention provides a load balancing method that can automatically identify the operating load and response capacity of the application and the host, and adjust the load balancing configuration of the system in advance to adapt to the response capacity of the backend service in the current and future period. Specifically, the embodiment of the present invention can be applied to the k8s cluster system, please refer to Figure 2 , Figure 2 This is a block diagram of a k8s cluster system in a Kubernetes-based load balancing method provided by the present invention. The monitoring service in the system block diagram is a new module added to the embodiment of the present invention, and the remaining modules are standard components of the k8s system. Please refer to Figure 3 , Figure 3 It is a timing diagram of a load balancing method based on Kubernetes provided by the present invention. In an embodiment of the present invention, both the application and the monitoring service are deployed in the form of Pod. After the application is started, it will establish contact with the monitoring service and regularly report the load (i.e., CPU and memory) and real-time QPS of the Pod to the monitoring service. The monitoring service can also regularly query the load and real-time QPS of each node and each Pod. If the load of any Pod reaches the first preset threshold or the real-time QPS reaches the second preset threshold, the load balancing weight of each Pod is dynamically adjusted according to the load of each node and the load of each Pod to maximize the responsiveness of the Pod.
[0045] In another preferred embodiment, the second preset threshold is a maximum QPS, and the maximum QPS is calculated as follows:
[0046] Get the memory upper limit and CPU upper limit preset by the Pod;
[0047] The maximum QPS of the Pod is calculated according to the memory upper limit value and the CPU upper limit value.
[0048] Specifically, when an application is deployed as a Pod, the upper limit of the CPU and memory occupied by the Pod will be specified to prevent the Pod from occupying too many resources without limit, thereby affecting the normal operation of other Pods on the cluster node. When the memory requested by the Pod exceeds the set upper limit, the program will have an OOM error, and the containers and Pods in the Pod will also be stopped and rescheduled. The resource settings of the Pod are as follows:
[0049]
[0050]
[0051] How to set the memory and CPU limits.
[0052] The embodiment of the present invention performs a performance test on the service in advance, calculates the impact of the CPU and memory size on the service QPS, and obtains the following conclusions:
[0053] QPS = x*memory+y*cpu;
[0054] Among them, x and y both represent coefficients, which can be the influence coefficients of memory and CPU on QPS calculated through tests. Memory and CPU are actual configuration values, and QPS is the number of requests that the system can process per second under the current configuration.
[0055] When the application in the Pod is started, the memory upper limit and CPU upper limit set by the Pod are read first, and then the maximum QPS under the current configuration is calculated using the above formula based on the memory upper limit and CPU upper limit, recorded as max-qps.
[0056] When the Pod is running normally, each time a request is received, a record is made in the memory, including the interface response time, etc., and the real-time QPS is calculated, recorded as current-qps.
[0057] In another preferred embodiment, dynamically adjusting the load balancing weight of each Pod according to the load of each node and the load of each Pod includes:
[0058] Calculate the first influence coefficient of the memory and CPU of the server on the weight according to the memory upper limit value, the CPU upper limit value, the current memory usage value, and the CPU usage value of the server;
[0059] Calculate the second influence coefficient of the memory and CPU of the Pod on the weight according to the memory upper limit value, the CPU upper limit value, the current memory usage value, and the CPU usage value of the Pod;
[0060] Calculate the load balancing weight of each Pod according to the first influence coefficient and the second influence coefficient;
[0061] The load balancing weight of each Pod is dynamically adjusted according to the load balancing weight.
[0062] In another preferred embodiment, calculating the load balancing weight of each Pod according to the first influence coefficient and the second influence coefficient includes:
[0063] Calculate the load balancing weight coefficient of each Pod according to the first influence coefficient and the second influence coefficient;
[0064] Calculate the load balancing weight of each Pod based on the load balancing weight coefficient of each Pod.
[0065] In another preferred embodiment, the calculation formula of the load balancing weight is:
[0066]
[0067] In the formula, w1 represents the load balancing weight of the Pod; k represents the coefficient; η represents the load balancing weight coefficient of the Pod, and n represents the number of Pods. α represents the first impact coefficient, β represents the second impact coefficient, cur_qps represents the real-time QPS, and max_qps represents the maximum QPS; where,
[0068] α=(total_memory1-cur_memory1)*γ+(total_cpu1-cur_cpu1)*δ;
[0069] β=(total_memory2-cur_memory2)*ε+(total_cpu2-cur_cpu2)*θ;
[0070] In the formula, total_memory1 represents the memory upper limit of the server, total_cpu1 represents the CPU upper limit of the server, cur_memory1 represents the current memory usage of the server, and cur_cpu1 represents the current CPU usage of the server; total_memory2 represents the memory upper limit of the Pod, total_cpu2 represents the CPU upper limit of the Pod, cur_memory2 represents the current memory usage of the Pod, and cur_cpu2 represents the current CPU usage of the Pod; γ, δ, ε, and θ all represent coefficients.
[0071] Specifically, when dynamically adjusting the load balancing weight of each Pod according to the load of each node and the load of each Pod, the embodiment of the present invention first calculates the first influence coefficient α of the server's memory and CPU on the weight according to the server's memory upper limit value, CPU upper limit value, current memory usage value, and CPU usage value. The calculation formula is as follows:
[0072] α=(total_memory1-cur_memory1)*γ+(total_cpu1-cur_cpu1)*δ;
[0073] In the formula, total_memory1 represents the memory upper limit of the server, total_cpu1 represents the CPU upper limit of the server, cur_memory1 represents the current memory usage value of the server, and cur_cpu1 represents the current CPU usage value of the server; γ and δ both represent coefficients, which can be influence coefficients calculated through tests.
[0074] Then, based on the Pod's memory upper limit, CPU upper limit, current memory usage, and CPU usage, calculate the second impact coefficient β of the Pod's memory and CPU on the weight. The calculation formula is as follows:
[0075] β=(total_memory2-cur_memory2)*ε+(total_cpu2-cur_cpu2)*θ;
[0076] In the formula, total_memory2 represents the memory upper limit of the Pod, total_cpu2 represents the CPU upper limit of the Pod, cur_memory2 represents the current memory usage of the Pod, and cur_cpu2 represents the current CPU usage of the Pod. ε and θ both represent coefficients, which can be influence coefficients calculated through tests.
[0077] Secondly, according to the first influence coefficient α and the second influence coefficient β, the unnormalized load balancing weight coefficient η of each Pod is calculated. The calculation formula is as follows:
[0078]
[0079] Where cur_qps represents the real-time QPS, and max_qps represents the maximum QPS.
[0080] Then, according to the load balancing weight coefficient η of each Pod, the normalized load balancing weight w1 of each Pod is calculated. The calculation formula is as follows:
[0081]
[0082] In the formula, k represents the coefficient, which can be a coefficient calculated through testing; n represents the number of Pods.
[0083] Finally, dynamically adjust the load balancing weight of each Pod according to the load balancing weight. For example, the way to modify the k8s service load balancing is as follows: 1) Query the host node list of the cluster; 2) Connect to each host through ssh, and then use the ipvsadm or iptable command to modify the routing rules of the host.
[0084] Exemplarily, the load balancing method provided in the embodiment of the present invention can be applied to the scenario where the application actively reports an alarm. The application actively reports an alarm in the following categories:
[0085] 1) When counting the real-time QPS inside the Pod, the real-time QPS for a period of time in the future is estimated in advance by calculating the rate of change of the real-time QPS. When the Pod finds that the real-time QPS (current-qps) is approaching the max-qps (such as reaching 90%), and the real-time QPS growth rate is positive, it will immediately report an alarm to the monitoring service. Or when the real-time QPS has reached 95% of the max-qps, it will also report an alarm immediately.
[0086] 2) When the Pod detects that the response time of its interface has increased, for example, if the average time of normal response is 100ms and the current change is 1000ms, an alarm will be reported immediately.
[0087] After receiving the above alarm, the monitoring service will immediately query the resource consumption of all nodes and Pods in the cluster and the real-time QPS of all Pods. If the resource consumption and QPS of some nodes and Pods running on the nodes are low, it means that the load balancer can be adjusted, and the weight of each backend node on the load balancer will be modified immediately. For example, the proportion of the backend service that just reported the alarm will be lowered, and the proportion of idle backend services will be increased. The specific weight calculation method is shown in the above formula.
[0088] When the Pod finds that its current-qps drops below 70% of the maximum QPS, it reports to the monitoring service to cancel the alarm.
[0089] After the monitoring service receives the cancellation alarm, it immediately queries the resource consumption and real-time QPS of other Pods, and dynamically adjusts the weight of each Pod on the load balancer based on the actual situation and the above weight calculation formula.
[0090] In another preferred embodiment, the method further comprises:
[0091] If the load of any of the nodes reaches a third preset threshold, the load balancing weight of each Pod is dynamically adjusted according to the load of each node and the load of each Pod.
[0092] Specifically, the load balancing method provided in the embodiment of the present invention can also be applied to the scenario where the monitoring service regularly inspects the cluster node-server. If the monitoring service inspects that the load of any node reaches the third preset threshold, the load balancing weight of each Pod is dynamically adjusted according to the load of each node and the load of each Pod.
[0093] For example, when the monitoring service regularly inspects the resource usage of the cluster nodes, if it finds that the resource usage of a server is high, such as the memory usage is close to 90% or the CPU usage is close to 90%, the inspection frequency is immediately increased.
[0094] If the resources occupied by the server do not decrease within 3 consecutive seconds, the resource consumption and real-time QPS of other servers and Pods are immediately queried, and the load balancing weight is recalculated. The specific weight calculation method is shown in the above formula, and the configuration on the load balancer is modified.
[0095] When the monitoring service finds that the resource consumption of the aforementioned abnormal server has dropped below 70% of the server configuration during inspection, it immediately queries the resource consumption of other nodes and Pods, and then dynamically adjusts the weight of each Pod on the load balancer.
[0096] In the load balancing method provided by the embodiment of the present invention, the backend service can proactively issue an early warning based on its own operating load, and then dynamically adjust the weight of each backend service on the load balancer to maximize the responsiveness of the backend service. At the same time, it can also avoid continuing to forward requests to high-load programs, which may cause the interface to respond slowly or time out, or even abnormalities such as program OOM. The monitoring service can also regularly inspect the resource usage of the server. If it is found that the resource usage of the server is abnormal, the load balancing weight can be recalculated and modified immediately to avoid the situation where the Pod itself is running normally and resource consumption is not high, and the service cannot continue to be provided due to resource limitations of the server node.
[0097] The embodiment of the present invention directly detects the running status of cluster nodes and Pods through Pod active load reporting and monitoring services, so that the real-time resource usage of cluster nodes and Pods can be mastered, and the load balancing rule update is completed in advance (i.e. before the program response exception occurs). The embodiment of the present invention can be used as a supplementary component of the k8s cluster, and does not affect the normal operation of the cluster, ensuring the stability of the system and the success rate of client requests.
[0098] Correspondingly, the present invention also provides a load balancing device based on Kubernetes, which can implement all processes of the load balancing method based on Kubernetes in the above embodiment.
[0099] See also Figure 4 , Figure 4 The present invention provides a schematic diagram of a preferred embodiment of a load balancing device based on Kubernetes. The load balancing device based on Kubernetes includes:
[0100] The acquisition module 401 is used to obtain the load of each node in the Kubernetes cluster and the load and real-time QPS of each Pod;
[0101] The adjustment module 402 is used to dynamically adjust the load balancing weight of each Pod according to the load of each node and the load of each Pod if the load of any of the Pods reaches the first preset threshold or the real-time QPS reaches the second preset threshold.
[0102] Preferably, the second preset threshold is a maximum QPS, and the maximum QPS is calculated as follows:
[0103] Get the memory upper limit and CPU upper limit preset by the Pod;
[0104] The maximum QPS of the Pod is calculated according to the memory upper limit value and the CPU upper limit value.
[0105] Preferably, dynamically adjusting the load balancing weight of each Pod according to the load of each node and the load of each Pod includes:
[0106] Calculate the first influence coefficient of the memory and CPU of the server on the weight according to the memory upper limit value, the CPU upper limit value, the current memory usage value, and the CPU usage value of the server;
[0107] Calculate the second influence coefficient of the memory and CPU of the Pod on the weight according to the memory upper limit value, the CPU upper limit value, the current memory usage value, and the CPU usage value of the Pod;
[0108] Calculate the load balancing weight of each Pod according to the first influence coefficient and the second influence coefficient;
[0109] The load balancing weight of each Pod is dynamically adjusted according to the load balancing weight.
[0110] Preferably, calculating the load balancing weight of each Pod according to the first influence coefficient and the second influence coefficient includes:
[0111] Calculate the load balancing weight coefficient of each Pod according to the first influence coefficient and the second influence coefficient;
[0112] Calculate the load balancing weight of each Pod based on the load balancing weight coefficient of each Pod.
[0113] Preferably, the calculation formula of the load balancing weight is:
[0114]
[0115] In the formula, w1 represents the load balancing weight of the Pod; k represents the coefficient; η represents the load balancing weight coefficient of the Pod, and n represents the number of Pods. α represents the first impact coefficient, β represents the second impact coefficient, cur_qps represents the real-time QPS, and max_qps represents the maximum QPS; where,
[0116] α=(total_memory1-cur_memory1)*γ+(total_cpu1-cur_cpu1)*δ;
[0117] β=(total_memory2-cur_memory2)*ε+(total_cpu2-cur_cpu2)*θ;
[0118] In the formula, total_memory1 represents the memory upper limit of the server, total_cpu1 represents the CPU upper limit of the server, cur_memory1 represents the current memory usage of the server, and cur_cpu1 represents the current CPU usage of the server; total_memory2 represents the memory upper limit of the Pod, total_cpu2 represents the CPU upper limit of the Pod, cur_memory2 represents the current memory usage of the Pod, and cur_cpu2 represents the current CPU usage of the Pod; γ, δ, ε, and θ all represent coefficients.
[0119] Preferably, the adjustment module 402 is further used for:
[0120] If the load of any of the nodes reaches a third preset threshold, the load balancing weight of each Pod is dynamically adjusted according to the load of each node and the load of each Pod.
[0121] In the specific implementation, the working principle, control process and technical effect achieved by the Kubernetes-based load balancing device provided in the embodiment of the present invention are the same as those of the Kubernetes-based load balancing method in the above embodiment, and will not be repeated here.
[0122] See also Figure 5 , Figure 5 1 is a schematic diagram of a preferred embodiment of a terminal device provided by the present invention. The terminal device includes a processor 501, a memory 502, and a computer program stored in the memory 502 and configured to be executed by the processor 501. When the processor 501 executes the computer program, the load balancing method based on Kubernetes described in any of the above embodiments is implemented.
[0123] Preferably, the computer program can be divided into one or more modules / units (such as computer program 1, computer program 2, ...), and the one or more modules / units are stored in the memory 502 and executed by the processor 501 to complete the present invention. The one or more modules / units can be a series of computer program instruction segments that can complete specific functions, and the instruction segments are used to describe the execution process of the computer program in the terminal device.
[0124] The processor 501 can be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor can be a microprocessor, or the processor 501 can be any conventional processor. The processor 501 is the control center of the terminal device, and various parts of the terminal device are connected using various interfaces and lines.
[0125] The memory 502 mainly includes a program storage area and a data storage area, wherein the program storage area can store an operating system, an application required for at least one function, etc., and the data storage area can store related data, etc. In addition, the memory 502 can be a high-speed random access memory, or a non-volatile memory, such as a plug-in hard disk, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, and a flash card (Flash Card), etc., or the memory 502 can also be other volatile solid-state storage devices.
[0126] It should be noted that the above terminal device may include, but is not limited to, a processor and a memory. Those skilled in the art will understand that Figure 5 The structural diagram is only an example of the above-mentioned terminal device and does not constitute a limitation of the above-mentioned terminal device. It may include more or less components than shown in the figure, or combine certain components, or different components.
[0127] An embodiment of the present invention also provides a computer-readable storage medium, which includes a stored computer program, wherein when the computer program is running, the device where the computer-readable storage medium is located is controlled to execute the Kubernetes-based load balancing method described in any of the above embodiments.
[0128] An embodiment of the present invention further provides a computer program product, which includes a computer program or computer instructions. When the computer program or the computer instructions are executed by a processor, the load balancing method based on Kubernetes described in any of the above embodiments is implemented.
[0129] The embodiment of the present invention provides a load balancing method, device, equipment, medium and product based on Kubernetes, which obtains the load of each node in the Kubernetes cluster and the load and real-time QPS of each Pod; if the load of any of the Pods reaches the first preset threshold or the real-time QPS reaches the second preset threshold, the load balancing weight of each Pod is dynamically adjusted according to the load of each node and the load of each Pod. The embodiment of the present invention calculates the load balancing weight in real time by comprehensively considering the resource configuration and usage of the server and the Pod, thereby achieving a more flexible and real-time load balancing configuration; by dynamically adjusting the load balancing rules, the forwarding efficiency of the load balancer is improved, while also reducing the probability of OOM exceptions in the backend program and the possibility of failed responses, thereby maximizing the responsiveness of the system and each Pod.
[0130] It should be noted that the system embodiment described above is merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. In addition, in the drawings of the system embodiment provided by the present invention, the connection relationship between the modules indicates that there is a communication connection between them, which may be specifically implemented as one or more communication buses or signal lines. A person of ordinary skill in the art may understand and implement it without paying any creative effort.
[0131] The above is a preferred embodiment of the present invention. It should be pointed out that a person skilled in the art can make several improvements and modifications without departing from the principle of the present invention. These improvements and modifications are also considered to be within the scope of protection of the present invention.
Claims
1. A load balancing method based on Kubernetes, characterized in that: include: Get the load of each node in the Kubernetes cluster and the load and real-time QPS of each Pod; If the load of any of the Pods reaches the first preset threshold or the real-time QPS reaches the second preset threshold, the load balancing weight of each Pod is dynamically adjusted according to the load of each node and the load of each Pod.
2. The load balancing method based on Kubernetes as claimed in claim 1, characterized in that: The second preset threshold is the maximum QPS, and the maximum QPS is calculated as follows: Get the memory upper limit and CPU upper limit preset by the Pod; The maximum QPS of the Pod is calculated according to the memory upper limit value and the CPU upper limit value.
3. The load balancing method based on Kubernetes as claimed in claim 1, characterized in that: The load balancing weight of each Pod is dynamically adjusted according to the load of each node and the load of each Pod, including: Calculate the first influence coefficient of the memory and CPU of the server on the weight according to the memory upper limit value, the CPU upper limit value, the current memory usage value, and the CPU usage value of the server; Calculate the second influence coefficient of the memory and CPU of the Pod on the weight according to the memory upper limit value, the CPU upper limit value, the current memory usage value, and the CPU usage value of the Pod; Calculate the load balancing weight of each Pod according to the first influence coefficient and the second influence coefficient; The load balancing weight of each Pod is dynamically adjusted according to the load balancing weight.
4. The load balancing method based on Kubernetes as claimed in claim 3, characterized in that: The calculating the load balancing weight of each Pod according to the first influence coefficient and the second influence coefficient includes: Calculate the load balancing weight coefficient of each Pod according to the first influence coefficient and the second influence coefficient; Calculate the load balancing weight of each Pod based on the load balancing weight coefficient of each Pod.
5. The load balancing method based on Kubernetes as described in claim 4, characterized in that: The calculation formula of the load balancing weight is: In the formula, w1 represents the load balancing weight of the Pod; k represents the coefficient; η represents the load balancing weight coefficient of the Pod, and n represents the number of Pods. α represents the first impact coefficient, β represents the second impact coefficient, cur_qps represents the real-time QPS, and max_qps represents the maximum QPS; where, α=(total_memory1-cur_memory1)*γ+(total_cpu1-cur_cpu1)*δ; β=(total_memory2-cur_memory2)*ε+(total_cpu2-cur_cpu2)*θ; In the formula, total_memory1 represents the memory upper limit of the server, total_cpu1 represents the CPU upper limit of the server, cur_memory1 represents the current memory usage of the server, and cur_cpu1 represents the current CPU usage of the server; total_memory2 represents the memory upper limit of the Pod, total_cpu2 represents the CPU upper limit of the Pod, cur_memory2 represents the current memory usage of the Pod, and cur_cpu2 represents the current CPU usage of the Pod; γ, δ, ε, and θ all represent coefficients.
6. The load balancing method based on Kubernetes as claimed in claim 5, characterized in that: The method further comprises: If the load of any of the nodes reaches a third preset threshold, the load balancing weight of each Pod is dynamically adjusted according to the load of each node and the load of each Pod.
7. A load balancing device based on Kubernetes, characterized in that: include: The acquisition module is used to obtain the load of each node in the Kubernetes cluster and the load and real-time QPS of each Pod; The adjustment module is used to dynamically adjust the load balancing weight of each Pod according to the load of each node and the load of each Pod if the load of any of the Pods reaches a first preset threshold or the real-time QPS reaches a second preset threshold.
8. A terminal device, characterized in that: It includes a processor and a memory, wherein a computer program is stored in the memory, and the computer program is configured to be executed by the processor, and when the processor executes the computer program, the load balancing method based on Kubernetes as described in any one of claims 1 to 6 is implemented.
9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, wherein when the device where the computer-readable storage medium is located executes the computer program, the load balancing method based on Kubernetes as described in any one of claims 1 to 6 is implemented.
10. A computer program product, characterized in that The computer program product includes a computer program or a computer instruction, and when the computer program or the computer instruction is executed by a processor, the Kubernetes-based load balancing method is implemented.