Load balancing method, device and system for Pod
By allocating routing weights for virtual machines and distributing network traffic according to the routing weight, the problem of uneven distribution of POD resources in existing technology has been solved, the distribution efficiency is improved, and the reasonable use of the overall resources has been achieved.
Patent Information
- Application Number
- CN202411293200.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-14
- Publication Date
- 2025-01-21
AI Technical Summary
When allocating Pod resources in the prior art, some Pod resources occupancy rate is too high or too low, and the distribution efficiency is not high, so the overall resources cannot be rationally utilized.
By allocating routing weights for virtual machines, network traffic is distributed according to the routing weight of each virtual machine, and each virtual machine sends network traffic based on the IP of the POD of the POD to achieve load balance.
It achieves rational utilization of resources, improves distribution efficiency, avoids the process of changing designated Pods due to excessive resource occupancy, and ensures balanced utilization of overall resources.
Smart Images

Figure CN119336490A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of communication resource allocation, and in particular to a load balancing method, device and system for Pod. Background Art
[0002] A Pod is a group of (one or more) containers, and is the smallest deployable computing unit created and managed in Kubernetes. Several Pods will run on a virtual machine. The working process of a Pod includes: after receiving network traffic, the server distributes the network traffic to each Pod in sequence according to the pre-set distribution order and distribution rules. The distribution rule is: if the resource usage of a Pod exceeds the specified threshold, the network traffic will be distributed to the next Pod.
[0003] However, the above method has the following defects:
[0004] Distributing network traffic in sequence according to the resource occupancy rate of each Pod in the above manner will result in some Pods having too high resource occupancy rates and some Pods having too low resource occupancy rates, and the overall resources are not used properly. At the same time, the above manner belongs to a sequential distribution method, and there may be a process of changing the specified Pod due to excessive resource occupancy rates, which affects the distribution efficiency. Summary of the invention
[0005] In view of the defects existing in the prior art, the technical problem solved by the present invention is: how to distribute network traffic to Pods through load balancing on the basis of rationally utilizing resources and improving distribution efficiency.
[0006] To achieve the above objectives, in the first aspect, an embodiment of the present application provides a load balancing method for Pod, the method comprising the following steps: assigning routing weights to virtual machines according to the number of Pods of the virtual machines; distributing corresponding network traffic according to the routing weight of each virtual machine; and each virtual machine sending network traffic according to the IP of the Pod to which it belongs.
[0007] In combination with the first aspect, in one embodiment, the process of assigning routing weights to virtual machines based on the number of Pods of the virtual machines includes: obtaining the number of Pods of each virtual machine in use, and assigning corresponding routing weights based on the number of Pods of each virtual machine; when a change in the working status of the virtual machine and / or Pod is detected, updating the corresponding routing weight based on the changed working status.
[0008] In combination with the first aspect, in one implementation, when the virtual machine and / or Pod is monitored to change from a working state, the process of updating the corresponding routing weight according to the changed working state includes:
[0009] When a new virtual machine and / or Pod is detected, a corresponding routing weight is assigned to the virtual machine based on the number of Pods of the new virtual machine or the number of new Pods.
[0010] When a virtual machine is detected to be unavailable, the routing weight of the virtual machine is deleted;
[0011] When the Pod of the monitored virtual machine is unavailable, the corresponding routing weight is reassigned to the virtual machine according to the number of Pods in use by the virtual machine.
[0012] In combination with the first aspect, in one implementation, the IP of the Pod is obtained by replacing the destination IP of the network traffic with the actual IP of the Pod.
[0013] In combination with the first aspect, in one implementation, the Pod's IP is obtained by creating a virtual IP for the Pod and replacing the destination IP of the network traffic with the virtual IP of the Pod.
[0014] In combination with the first aspect, in one implementation, the process of creating a virtual IP for a Pod includes: determining a namespace where a running available Pod is located, and allocating a virtual IP for the Pod in a loopback network port of the namespace.
[0015] In combination with the first aspect, in one implementation, the process of sending network traffic according to the IP of the Pod to which it belongs includes: distributing the network traffic to the corresponding Pod according to an equal-cost routing rule.
[0016] In a second aspect, an embodiment of the present application provides a load balancing device for a Pod, characterized in that: the device is used to implement the method provided in the first aspect.
[0017] In conjunction with the second aspect, in one implementation, the device includes a container cluster control plane, a container cluster load balancing controller, a load balancing node control agent, and a virtual network controller;
[0018] The container cluster control plane is used to: determine the number of available Pods and transmit it to the container cluster load balancing controller;
[0019] The container cluster load balancing controller is used to: after receiving the number of available Pods, send work signals to the load balancing node control agent and the virtual network controller respectively;
[0020] The load balancing node control agent is used to: after receiving the working signal, configure the IP of the Pod and the equivalent routing rule;
[0021] The virtual network controller is used to: after receiving the work signal, assign routing weights to the virtual machines according to the number of Pods of the virtual machines.
[0022] In a third aspect, an embodiment of the present application provides a load balancing system for a Pod, the system comprising a virtual network router and a virtual machine communicating therewith; characterized in that: the system also includes the device provided in the second aspect.
[0023] Compared with the prior art, the advantages of the present invention are:
[0024] Compared with the prior art that distributes network traffic in sequence according to the order of Pods, the present invention can allocate corresponding network traffic to each virtual machine through the routing weight obtained according to the number of Pods, and realizes the load balancing of the Pods to which each virtual machine belongs by taking each virtual machine as a unit, thereby reasonably utilizing resources. At the same time, there is no need to change the specified Pod due to excessive resource occupancy in the prior art, thereby improving the distribution efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0025] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0026] Figure 1 A schematic diagram of the principle of allocating routing weights in an embodiment of the present invention;
[0027] Figure 2 This is a schematic diagram of the working process of the load balancing system for Pod in an embodiment of the present invention;
[0028] Figure 3 This is a schematic diagram of the hardware structure of the load balancing device for Pod involved in the embodiment of the present application. DETAILED DESCRIPTION
[0029] In order to make the purpose, technical solution and advantages of the embodiments of the present application clearer, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of this application.
[0030] The flowcharts shown in the accompanying drawings are only examples and do not necessarily include all the contents and operations / steps, nor must they be executed in the order described. For example, some operations / steps may also be decomposed, combined or partially merged, so the actual execution order may change according to actual conditions.
[0031] In order to make the objectives, technical solutions and advantages of the present application clearer, the implementation methods of the present application will be further described in detail below with reference to the accompanying drawings.
[0032] In a first aspect, an embodiment of the present application provides a load balancing method for Pods, the steps of the method comprising: assigning a routing weight to each virtual machine according to the number of available Pods of each virtual machine in use; Figure 1 As shown in the figure, for example, if the number of Pods of two virtual machines (nodes in the figure) is 1 and 2 respectively, the corresponding routing weight is 1:2. According to the routing weight of each virtual machine, the corresponding network traffic is distributed to each virtual machine; after each virtual machine receives the network traffic, it sends the network traffic according to the IP of the Pod to which it belongs.
[0033] It can be seen that compared with the prior art that distributes network traffic in sequence according to the order of Pods, the present invention can distribute the corresponding network traffic to each virtual machine through the routing weight obtained according to the number of Pods, and realizes the load balancing of the Pods to which each virtual machine belongs by taking each virtual machine as a unit, thereby reasonably utilizing resources. At the same time, there is no need to change the specified Pod due to excessive resource occupancy in the prior art, thereby improving the distribution efficiency.
[0034] In one embodiment, the process of allocating routing weights to each virtual machine according to the number of Pods of each virtual machine in use in the above method includes: obtaining the number of Pods of each virtual machine in use, and allocating corresponding routing weights according to the number of Pods of each virtual machine; when it is monitored that the working status of the virtual machine and / or Pod has changed, updating the corresponding routing weight according to the changed working status.
[0035] Specifically, when it is detected that the working state of the virtual machine and / or Pod has changed, the process of updating the corresponding routing weight according to the changed working state includes:
[0036] (1) When a new virtual machine is detected, a corresponding routing weight is allocated (added) to the virtual machine based on the number of Pods of the new virtual machine;
[0037] (2) When a new Pod is detected for a virtual machine, the routing weight of the virtual machine is modified according to the number of new Pods;
[0038] (3) When a virtual machine is detected to be unavailable (abnormal or changed from being in use to not being in use), the routing weight of the virtual machine is deleted;
[0039] (4) When a Pod of a monitored virtual machine is unavailable (abnormal or changes from being in use to not being in use), the corresponding routing weight is reassigned (modified) for the virtual machine based on the number of Pods in use of the virtual machine.
[0040] In one embodiment, the method for obtaining the IP address of the Pod in the above method is:
[0041] 1. Replace the destination IP of the network traffic with the actual IP of the Pod;
[0042] or:
[0043] 2. Create a virtual IP for the Pod and replace the destination IP of the network traffic with the virtual IP of the Pod.
[0044] The difference between method 1 and 2 is:
[0045] Method 1 can directly use the original IP of the Pod without going through the virtual IP allocation process of method 2, but the original IP cannot be changed, and the flexibility is low;
[0046] Method 2 can create a custom virtual IP according to needs, which is more flexible, but it requires a virtual IP allocation process.
[0047] Therefore, in actual use, method 1 or 2 can be selected according to different needs.
[0048] Specifically, the process of creating a virtual IP for a Pod includes: determining a namespace where a running available Pod is located, and allocating a virtual IP for the Pod in a loopback network port of the namespace.
[0049] First, in the embodiment, the process of sending network traffic according to the IP of the Pod to which it belongs in the above method includes: distributing the network traffic to the corresponding Pod according to the equal-cost routing rule. The equal-cost routing rule realizes the average distribution of network traffic of all Pods under each virtual machine, and the routing weight in the above method realizes the on-demand distribution of network traffic of all virtual machines; therefore, by coordinating in this way, there will be no situation where the resource occupancy rate of any virtual machine or Pod is too high or too low, thereby achieving overall load balancing.
[0050] In a second aspect, an embodiment of the present invention provides a load balancing device for Pod, which is used to implement the method mentioned in the first aspect.
[0051] In one embodiment, see Figure 2 As shown, the above-mentioned device specifically includes a container cluster control plane, a container cluster load balancing controller, a load balancing node control agent and a virtual network controller.
[0052] The container cluster control plane is used to: determine the number of available Pods described in the first aspect and transmit it to the container cluster load balancing controller;
[0053] The container cluster load balancing controller is used to: after receiving the number of available Pods, send work signals to the load balancing node control agent and the virtual network controller respectively;
[0054] The load balancing node control agent is used to: after receiving the work signal, configure the IP and equivalent routing rules of the Pod mentioned in the first aspect;
[0055] The virtual network controller is used to: after receiving the working signal, execute the process mentioned in the first aspect of allocating routing weights to each virtual machine according to the number of available Pods of each virtual machine in use.
[0056] Among them, the functional implementation of each module in the above-mentioned load balancing device for Pod corresponds to the steps in the above-mentioned load balancing method embodiment for Pod, and its functions and implementation processes are no longer repeated here one by one.
[0057] In a third aspect, an embodiment of the present invention provides a load balancing system for Pod, see Figure 2 As shown, the system includes a virtual network router and several virtual machines ( Figure 2 The middle node represents a virtual machine), and each virtual machine is provided with a number of Pods; the system also includes the load balancing device for Pods mentioned in the second aspect.
[0058] See below Figure 2 As shown, taking a newly added Pod as an example, the workflow of the above system is explained for the virtual machine of the newly added Pod.
[0059] (1) After workload expansion triggers Pod creation, the container cluster control plane receives the Pod creation event.
[0060] (2) The container cluster control plane informs the container cluster load balancing controller of the number of newly added Pods.
[0061] (3) The container cluster load balancing controller sends a work signal to the load balancing node control agent.
[0062] (4) The load balancing node control agent configures a virtual IP for the newly added Pod.
[0063] (5) The load balancing node control agent adds a routing entry pointing to the newly added Pod in the virtual machine's equal-cost routing rules.
[0064] (6) The container cluster load balancing controller sends the number of Pods of the virtual machine to the virtual network controller.
[0065] (7) The virtual network controller assigns corresponding routing weights to the virtual machines based on the number of Pods, and sends the routing weights of all virtual machines to the virtual network router.
[0066] (8) After the virtual network router receives the network traffic, it distributes it to the corresponding virtual machine according to the routing weight; the virtual machine distributes the network traffic to the Pod to which it belongs according to the equal-cost routing rule.
[0067] In a fourth aspect, an embodiment of the present application provides a load balancing device for a Pod. The load balancing device for a Pod may be a device with data processing functions, such as a personal computer (PC), a laptop computer, or a server.
[0068] Reference Figure 3 , Figure 3 The hardware structure diagram of the load balancing device for Pod involved in the embodiment of the present application is shown in FIG. In the embodiment of the present application, the load balancing device for Pod may include a processor, a memory, a communication interface, and a communication bus.
[0069] The communication bus may be of any type and is used to interconnect the processor, the memory, and the communication interface.
[0070] The communication interface includes input / output (I / O) interfaces, physical interfaces, and logical interfaces, which are used to interconnect the components inside the load balancing device for the Pod, and interfaces used to interconnect the load balancing device for the Pod with other devices (such as other computing devices or user devices). The physical interface can be an Ethernet interface, a fiber optic interface, an ATM interface, etc.; the user device can be a display, a keyboard, etc.
[0071] The memory can be various types of storage media, such as random access memory (RAM), read-only memory (ROM), non-volatile RAM (NVRAM), flash memory, optical storage, hard disk, programmable ROM (PROM), erasable PROM (EPROM), electrically erasable PROM (EEPROM), etc.
[0072] The processor may be a general-purpose processor, which may call the load balancing program for the Pod stored in the memory and execute the load balancing method for the Pod provided in the embodiment of the present application. For example, the general-purpose processor may be a central processing unit (CPU). The method executed when the load balancing program for the Pod is called may refer to the various embodiments of the load balancing method for the Pod in the present application, which will not be repeated here.
[0073] Those skilled in the art will understand that Figure 3 The hardware structure shown in the figure does not constitute a limitation on the present application, and may include more or less components than shown in the figure, or combine certain components, or arrange the components differently.
[0074] In a fifth aspect, an embodiment of the present application also provides a computer-readable storage medium.
[0075] The computer-readable storage medium of the present application stores a load balancing program for a Pod, wherein when the load balancing program for a Pod is executed by a processor, the steps of the load balancing method for a Pod as described above are implemented.
[0076] Among them, the method implemented when the load balancing program for Pod is executed can refer to the various embodiments of the load balancing method for Pod in this application, and will not be repeated here.
[0077] It should be noted that the serial numbers of the above-mentioned embodiments of the present application are only for description and do not represent the advantages or disadvantages of the embodiments.
[0078] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present application is essentially or the part that contributes to the prior art can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, disk, CD) as described above, and includes a number of instructions for a terminal device to execute the methods described in each embodiment of the present application.
[0079] The terms "including" and "having" and any variations thereof in the specification and claims of this application and the above-mentioned drawings are intended to cover non-exclusive inclusions. For example, a process, method, system, product or device that includes a series of steps or units is not limited to the listed steps or units, but optionally includes steps or units that are not listed, or optionally includes other steps or units inherent to these processes, methods, products or devices. The terms "first", "second" and "third" are used to distinguish different objects, etc., and do not represent a sequence, nor do they limit "first", "second" and "third" to different types.
[0080] In the description of the embodiments of the present application, "exemplary", "for example" or "for example" are used to indicate examples, illustrations or descriptions. Any embodiment or design described as "exemplary", "for example" or "for example" in the embodiments of the present application should not be interpreted as being more preferred or more advantageous than other embodiments or designs. Specifically, the use of words such as "exemplary", "for example" or "for example" is intended to present related concepts in a specific way.
[0081] In the description of the embodiments of the present application, unless otherwise specified, “ / ” means or, for example, A / B can mean A or B; the “and / or” in the text is merely a description of the association relationship of associated objects, indicating that three relationships may exist, for example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone. In addition, in the description of the embodiments of the present application, “multiple” refers to two or more than two.
[0082] In some processes described in the embodiments of the present application, multiple operations or steps that appear in a specific order are included, but it should be understood that these operations or steps may not be executed in the order in which they appear in the embodiments of the present application or in parallel, and the sequence number of the operation is only used to distinguish the different operations, and the sequence number itself does not represent any execution order. In addition, these processes may include more or fewer operations, and these operations or steps may be executed in sequence or in parallel, and these operations or steps may be combined.
[0083] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present application is essentially or the part that contributes to the prior art can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, disk, CD) as described above, and includes a number of instructions for a terminal device to execute the methods described in each embodiment of the present application.
[0084] The above are only specific implementations of the embodiments of the present invention, but the protection scope of the embodiments of the present invention is not limited thereto. Any technician familiar with the technical field can easily think of various equivalent modifications or replacements within the technical scope disclosed in the embodiments of the present invention, and these modifications or replacements should be included in the protection scope of the embodiments of the present invention. Therefore, the protection scope of the embodiments of the present invention shall be based on the protection scope of the claims.
Claims
1. A load balancing method for Pod, characterized in that: The method includes the following steps: assigning routing weights to virtual machines according to the number of Pods of the virtual machines; distributing corresponding network traffic according to the routing weight of each virtual machine; and each virtual machine sending network traffic according to the IP of the Pod to which it belongs.
2. The load balancing method for Pod according to claim 1, characterized in that: The process of allocating routing weights to virtual machines based on the number of Pods of the virtual machines includes: obtaining the number of Pods of each virtual machine in use, and allocating corresponding routing weights according to the number of Pods of each virtual machine; when it is monitored that the working status of the virtual machine and / or Pod has changed, updating the corresponding routing weight according to the changed working status.
3. The load balancing method for Pod according to claim 2, characterized in that: When the virtual machine and / or Pod is monitored to have changed its working state, the process of updating the corresponding routing weight according to the changed working state includes: When a new virtual machine and / or Pod is detected, a corresponding routing weight is assigned to the virtual machine based on the number of Pods of the new virtual machine or the number of new Pods. When a virtual machine is detected to be unavailable, the routing weight of the virtual machine is deleted; When the Pod of the monitored virtual machine is unavailable, the corresponding routing weight is reassigned to the virtual machine according to the number of Pods in use by the virtual machine.
4. The load balancing method for Pod according to claim 1, characterized in that: The Pod's IP is obtained by replacing the destination IP of the network traffic with the actual IP of the Pod.
5. The load balancing method for Pod according to claim 1, characterized in that: The Pod's IP is obtained by creating a virtual IP for the Pod and replacing the destination IP of the network traffic with the Pod's virtual IP.
6. The load balancing method for Pod according to claim 5, characterized in that: The process of creating a virtual IP for a Pod includes: determining a namespace where an available running Pod is located, and allocating a virtual IP for the Pod in a loopback network port of the namespace.
7. The load balancing method for Pod according to any one of claims 1 to 6, characterized in that: The process of sending network traffic according to the IP of the Pod to which it belongs includes: distributing the network traffic to the corresponding Pod according to the equal-cost routing rule.
8. A load balancing device for Pod, characterized in that: The device is used to implement the method described in any one of claims 1 to 7.
9. The load balancing device for Pod according to claim 8, characterized in that: The device includes a container cluster control plane, a container cluster load balancing controller, a load balancing node control agent and a virtual network controller; The container cluster control plane is used to: determine the number of available Pods and transmit it to the container cluster load balancing controller; The container cluster load balancing controller is used to: after receiving the number of available Pods, send work signals to the load balancing node control agent and the virtual network controller respectively; The load balancing node control agent is used to: after receiving the working signal, configure the IP of the Pod and the equivalent routing rule; The virtual network controller is used to: after receiving the work signal, assign routing weights to the virtual machines according to the number of Pods of the virtual machines.
10. A load balancing system for Pod, the system comprising a virtual network router and a virtual machine communicating with the virtual network router; characterized in that: The system also includes the device of claim 9.