Load balancing method, product, equipment and storage medium
By reading the load balancing rule files and generating rules based on container group weights, complex load balancing requirements in custom private clouds are solved, flexible load balancing and high availability of container clusters are achieved, and resource utilization and system performance are improved.
Patent Information
- Application Number
- CN202411865253.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-17
- Publication Date
- 2025-01-17
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
When using Kubernetes services for traffic load balancing in custom private cloud mode, the existing technology cannot meet the complex load balancing needs and the network address cannot be changed, limiting flexibility and management capabilities.
By reading pre-created load balancing rules files, traffic load balancing rules are generated based on the weights of the container group, and traffic is dynamically allocated, supporting custom private cloud name, virtual address, session retention policy, namespace and selector configurations. Achieve flexible load balancing of container clusters.
It realizes a flexible load balancing strategy for container clusters, improves resource utilization and system performance, supports dynamic traffic allocation and abnormal switching of container groups, and ensures high availability and business continuity of services.
Smart Images

Figure CN119324923A_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present application relate to the field of cloud service technology, and more specifically, to a load balancing method, product, device, and storage medium. Background Art
[0002] Kubernetes (k8s) is an open source container orchestration platform that is widely used to automate the deployment, expansion, and management of applications. When using k8s services for traffic load balancing in a custom private cloud (VPC, Virtual Private Cloud) mode, it generally relies on the load balancer of the cloud service provider.
[0003] In the related art, all customized private clouds share the same network address range, and the network address cannot be changed. The load balancing strategy is also relatively simple and cannot meet some complex load balancing requirements. Summary of the invention
[0004] The embodiments of the present application provide a load balancing method, product, device, and storage medium, which are intended to flexibly set a load balancing strategy for a container cluster in a custom virtual private cloud.
[0005] A first aspect of an embodiment of the present application provides a load balancing method, the method comprising: Read a pre-created load balancing rule file, where the load balancing rule file includes traffic load balancing rule information of the container cluster; Generate a corresponding traffic load balancing rule for the container cluster in the target area corresponding to the load balancing rule file according to the weight corresponding to each container group included in the load balancing rule file; According to the traffic load balancing rule, corresponding traffic is allocated to each container group in the container cluster in the target area corresponding to the load balancing rule file.
[0006] Optionally, before reading the pre-created load balancing rule file, the method further includes: Setting the name, virtual address, session persistence policy, namespace and selector of the custom private cloud in the space part of the load balancing rule file; Setting the virtual address and weight corresponding to each area in the area part of the load balancing rule file; Set the corresponding target service and port list in the port part of the load balancing rule file; The backend network address corresponding to the container group is set in the terminal part in the load balancing rule file.
[0007] Optionally, before generating a corresponding traffic load balancing rule for the container cluster in the target area corresponding to the load balancing rule file according to the weight corresponding to each container group included in the load balancing rule file, the method further includes: Obtaining a virtual address of a target area from the load balancing rule file; A connection is established with the container cluster in the target area according to the virtual address.
[0008] Optionally, the method further comprises: Determine the subnet information corresponding to the target area according to the namespace in the load balancing rule; Determine whether the subnet corresponding to the subnet information exists; If the subnet exists, start monitoring the subnet.
[0009] Optionally, the method further comprises: If the subnet does not exist, creating a corresponding subnet according to the virtual address of the target area; Start monitoring of the subnet.
[0010] Optionally, generating a corresponding traffic load balancing rule for the container cluster in the target area corresponding to the load balancing rule file according to the weight corresponding to each container group included in the load balancing rule file includes: Determine the operating status of each container group in the target area; For each container group whose running status is normal operation, obtaining a weight corresponding to the container group in the load balancing rule file; The traffic load balancing rule is generated by taking the virtual address of the target area as the target virtual address and the backend network address corresponding to the container group as the real network address.
[0011] Optionally, determining the operating status of each container group in the target area includes: acquiring operating status information of each container group in the target area; When the running status information is normal, determining that the running status of the container group is a normal running status; When the running status information is abnormal, it is determined that the running status of the container group is an abnormal status.
[0012] Optionally, allocating corresponding traffic to each container group in the container cluster in the target area corresponding to the load balancing rule file according to the traffic load balancing rule includes: Determine the traffic load ratio corresponding to each of the container groups according to the traffic load balancing rule; When the flow data is received, the corresponding flow is allocated to the container group according to the flow load ratio corresponding to each container group.
[0013] Optionally, the method further comprises: When it is detected that the container group in the target area is in an abnormal state, the traffic corresponding to the target area is switched to the remaining areas in the load balancing rule file.
[0014] Optionally, switching the traffic corresponding to the target area to the remaining areas in the load balancing rule file includes: Cleaning up data traffic in the target area; Deleting the load balancing rule in the target area; The traffic corresponding to the target area is sent to the virtual addresses corresponding to the remaining areas.
[0015] Optionally, the method further comprises: When it is detected that any of the container groups in the target area is in an abnormal state, the flow corresponding to the container group is distributed to the remaining container groups in the target area.
[0016] Optionally, allocating the flow corresponding to the container group to the remaining container groups in the target area includes: Setting corresponding weights for the remaining container groups in the target area; According to the weights, corresponding flows are allocated to the remaining container groups in the target area.
[0017] A second aspect of an embodiment of the present application provides a computer program product, including a computer program / instruction, which, when executed by a processor, implements the steps in the method described in the first aspect of the present application.
[0018] A third aspect of an embodiment of the present application provides a load balancing device, the device comprising: A file reading module, used to read a pre-created load balancing rule file, wherein the load balancing rule file includes traffic load balancing rule information of the container cluster; A rule generation module, configured to generate a corresponding traffic load balancing rule for the container cluster in the target area corresponding to the load balancing rule file according to the weight corresponding to each container group included in the load balancing rule file; The traffic distribution module is used to distribute corresponding traffic to each container group in the container cluster in the target area corresponding to the load balancing rule file according to the traffic load balancing rule.
[0019] Optionally, the device further comprises: A first file setting module, used to set the name, virtual address, session persistence strategy, namespace and selector of the custom private cloud in the space part of the load balancing rule file; A second file setting module, used to set the virtual address and weight corresponding to each area in the area part of the load balancing rule file; A third file setting module, used to set the corresponding target service and port list in the port part of the load balancing rule file; The fourth file setting module is used to set the backend network address corresponding to the container group in the terminal part of the load balancing rule file.
[0020] Optionally, the device further comprises: A virtual address acquisition module, used to acquire the virtual address of the target area from the load balancing rule file; A connection establishing module is used to establish a connection with the container cluster in the target area according to the virtual address.
[0021] Optionally, the device further comprises: A subnet information acquisition module, used to determine the subnet information corresponding to the target area according to the namespace in the load balancing rule; A subnet determination module, used to determine whether a subnet corresponding to the subnet information exists; The first monitoring start module is used to start monitoring the subnet if the subnet exists.
[0022] Optionally, the device further comprises: A subnet creation submodule, used for creating a corresponding subnet according to the virtual address of the target area when the subnet does not exist; The second monitoring start module is used to start monitoring the subnet.
[0023] Optionally, the rule generation module includes: An operation status determination submodule, used to determine the operation status of each container group in the target area; A weight acquisition submodule, configured to acquire, for each container group whose operating state is normal operation, a weight corresponding to the container group in the load balancing rule file; The rule generation submodule is used to use the virtual address of the target area as the target virtual address and the backend network address corresponding to the container group as the real network address to generate the traffic load balancing rule.
[0024] Optionally, the operation status determination submodule includes: an operation status information acquisition submodule, configured to acquire operation status information of each of the container groups in the target area; A first operation status determination submodule, configured to determine, when the operation status information is normal, that the operation status of the container group is a normal operation status; The second operation status determination submodule is configured to determine that the operation status of the container group is an abnormal state when the operation status information is abnormal.
[0025] Optionally, the traffic distribution module includes: A traffic load ratio determination submodule, configured to determine the traffic load ratio corresponding to each of the container groups according to the traffic load balancing rule; The flow distribution submodule is used to distribute corresponding flow to the container group according to the flow load ratio corresponding to each container group when receiving the flow data.
[0026] Optionally, the device further comprises: The first traffic switching module is configured to switch the traffic corresponding to the target area to the remaining areas in the load balancing rule file when it is detected that the container group in the target area is in an abnormal state.
[0027] Optionally, the first flow switching module includes: A traffic cleaning submodule, used to clean up the data traffic in the target area; A rule deletion submodule, used to delete the load balancing rule in the target area; The first traffic sending submodule is used to send the traffic corresponding to the target area to the virtual addresses corresponding to the remaining areas.
[0028] Optionally, the device further comprises: The second flow switching module is used to distribute the flow corresponding to the container group to the remaining container groups in the target area when it is detected that any of the container groups in the target area is in an abnormal state.
[0029] Optionally, the second flow switching module includes: A weight setting submodule, used to set corresponding weights for the remaining container groups in the target area; The remaining container group flow distribution submodule is used to distribute corresponding flows to the remaining container groups in the target area according to the weights.
[0030] A fourth aspect of an embodiment of the present application provides a readable storage medium having a computer program stored thereon. When the computer program is executed by a processor, the steps in the method described in the first aspect of the present application are implemented.
[0031] A fifth aspect of an embodiment of the present application provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, the steps of the method described in the first aspect of the present application are implemented.
[0032] The load balancing method proposed in the present application is adopted to read a pre-created load balancing rule file, wherein the load balancing rule file includes traffic load balancing rule information of a container cluster; according to the weight corresponding to each container group contained in the load balancing rule file, a corresponding traffic load balancing rule is generated for the container cluster in the target area corresponding to the load balancing rule file; according to the traffic load balancing rule, corresponding traffic is allocated to each container group in the container cluster in the target area corresponding to the load balancing rule file.
[0033] In this application, by pre-creating a load balancing rule file, the load balancing rule information of the container cluster in the user's virtual private cloud is defined, wherein a corresponding weight is assigned to each container group in the container cluster of the target area. After obtaining the corresponding weight of each container group, a corresponding load balancing rule is generated for each container group, and then the corresponding traffic is assigned to each container group in the container cluster according to the traffic load balancing rule, thereby realizing flexible allocation of corresponding traffic to each container group in the container cluster, dynamically allocating traffic ratios to each container group, and improving resource utilization and system performance. BRIEF DESCRIPTION OF THE DRAWINGS
[0034] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the description of the embodiments of the present application will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0035] Figure 1 is a flow chart of a load balancing method proposed in an embodiment of the present application; Figure 2 This is a schematic diagram of a load balancing process proposed in an embodiment of the present application; Figure 3 It is a schematic diagram of the working principle of the controller proposed in one embodiment of the present application; Figure 4 is a schematic diagram of a load balancing device proposed in an embodiment of the present application; Figure 5 It is a schematic diagram of an electronic device proposed in an embodiment of the present application. DETAILED DESCRIPTION
[0036] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions 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 creative work are within the scope of protection of this application.
[0037] refer to Figure 1 , Figure 1 FIG. 1 is a flow chart of a load balancing method proposed in an embodiment of the present application. Figure 1 As shown, the method comprises the following steps: S11: Read a pre-created load balancing rule file, where the load balancing rule file includes traffic load balancing rule information of the container cluster.
[0038] In this embodiment, traffic load balancing is implemented based on Kubernetes (container orchestration tool) in VPC (virtual private cloud). VPC is a virtualized network environment that provides an isolated network resource for building and managing virtual networks. Kubernetes is an open source for managing containerized applications on multiple hosts in a cloud platform. The goal of Kubernetes is to make the deployment of containerized applications simple and efficient. Kubernetes provides a mechanism for application deployment, planning, updating, and maintenance. Each container is isolated from each other, each container has its own file system, and the processes between containers will not affect each other, and computing resources can be distinguished. Compared with virtual machines, containers can be deployed quickly. Since containers are decoupled from the underlying facilities and machine file systems, they can be migrated between different clouds and different versions of operating systems. Containers take up less resources and are deployed quickly. Each application can be packaged into a container image because each application does not need to be combined with the rest of the application stack and does not rely on the production environment infrastructure, which enables a consistent environment from R&D to testing and production. Similarly, containers are lighter and more "transparent" than virtual machines, which makes them easier to monitor and manage.
[0039] In this embodiment, the Kubernetes VPC mode is a method of integrating a Kubernetes cluster with a virtual private cloud (VPC) network environment, so that containers in the Kubernetes cluster can communicate efficiently and securely with other resources in the VPC (such as virtual machines, other containers, etc.). This mode is particularly suitable for enterprise environments that require high availability, security, and complex network topologies. Kubernetes is a container orchestration platform for automating the deployment, expansion, and management of applications. VPC is a virtualized network environment that provides an isolated network resource for building and managing virtual networks. In Kubernetes, Service is an important resource type that is used to define a logical collection of Pods (container groups) and provide load balancing and service discovery capabilities for these Pods. The IP address (network address) of the Service is unique within the Kubernetes cluster and is managed by the cluster's IP address range (CIDR).
[0040] In this embodiment, the load balancing rule file (LBrules) is a pre-created file in which the load balancing rule information of the container group in the container cluster in the custom private cloud is set. According to the load balancing rule information, corresponding traffic distribution rules can be formulated for the container group in the corresponding container cluster. The load balancing rule information includes the custom private cloud name, virtual address, session persistence policy, namespace name, selector, virtual addresses of different regions and weights of container groups, target services and port lists, and the real address of the backend container group.
[0041] In this embodiment, a controller is used to read a pre-created load balancing rule file. When accessing a custom private cloud, the controller reads the load balancing rule file pre-stored in a specified location, and then obtains the load balancing rule information included therein.
[0042] In another embodiment of the present application, before reading the pre-created load balancing rule file through the controller, the method further includes: S21: Setting the name, virtual address, session persistence strategy, namespace, and selector of the customized private cloud in the space part of the load balancing rule file.
[0043] In this embodiment, when creating a load balancing rule file, first set the name of the custom private cloud in the space (spec) part of the load balancing rule file, which name can be set by yourself, the virtual address of the custom private cloud, through which the custom private cloud can be accessed, and the session persistence strategy of the custom private cloud, through which the session between the external device and the subnet in the custom private cloud can be maintained. Namespace (namespace) is a method of separating cluster resources. Namespace provides a method of isolation, quota management, and resource management for different projects, customers, or teams. The selector (selector) is used to select the container group that needs to be monitored in the target area.
[0044] S22: Setting the virtual address and weight corresponding to each area in the area part of the load balancing rule file.
[0045] In this embodiment, the virtual address and weight corresponding to each region are set in the regions section of the load balancing rule file. The container cluster in each region can be accessed through the virtual address of each region, and the traffic proportion allocated to each region can be determined through the weight of each region.
[0046] S23: Setting the corresponding target service and port list in the port part of the load balancing rule file.
[0047] In this embodiment, the corresponding target service and port list are set in the port part of the load balancing rule file. The target service is the service type provided by the custom private cloud, and the port list includes the port number for data transmission between the custom private cloud and the outside world.
[0048] S24: Setting the backend network address corresponding to the container group in the terminal part of the load balancing rule file.
[0049] In this embodiment, the backend network address corresponding to the container group is set in the endpoints part of the load balancing rule file. The backend network address of the container group is the real address of each container group at the backend, and each container group can be accessed through this address.
[0050] For example, the data structure of the load balancing rule file is as follows: apiVersion: Vpc.io / v1 kind: LBRule metadata: name:lbrule spec: vpcName: customVpc vip: 1.1.1.1 / 24## Custom ip sessionAffinity: ClientIP ## Session persistence namespace: lbrule## k8s namespace selector: - app:Tomcat ## Standard Selector matching information regions: - vip:192.168.0.101 ## A area cluster vip weight: 2 name: A - vip:100.2.126.244 ## B area cluster vip weight: 1 name: B endpoints: - ip: 192.168.1.101 weight: 1 - 192.168.1.102 weight: 2 endpoints ports:## Port list - name: tomcat port: 8080 targetPort: 80 protocol: TCP Among them, apiVersion is the version number of the Kubernetes resource object, which is used to specify the version of the Kubernetes API used. It is usually expressed in the form of "group name / version number", such as "v1" or "apps / v1". Metadata, also known as intermediary data or relay data, is data about data, mainly information that describes data properties, used to support functions such as indicating storage location, historical data, resource search, and file records. Metadata is a kind of electronic directory. In order to achieve the purpose of cataloging, the content or characteristics of the data must be described and collected, thereby achieving the purpose of assisting data retrieval. vpcName is the name of the custom private cloud, which is customized. ClientIP is the client address. Tomcat is the selector tool, and other tools can also be selected. TCP (Transmission Control Protocol) is a connection-oriented, reliable, byte-stream-based transport layer communication protocol designed to adapt to a layered protocol hierarchy that supports multiple network applications. TCP provides reliable communication services between pairs of processes in host computers connected to different but interconnected computer communication networks.
[0051] S12: Generate a corresponding traffic load balancing rule for the container cluster in the target area corresponding to the load balancing rule file according to the weight corresponding to each container group included in the load balancing rule file.
[0052] In this embodiment, the load balancing rule file contains the weight corresponding to each container group. The weight refers to the importance of a factor or indicator relative to a certain thing. It is different from the general proportion. It reflects not only the percentage of a factor or indicator, but emphasizes the relative importance of the factor or indicator, tending to the contribution or importance. The weight is the basis for allocating traffic to the container group. The container group (pod) is the smallest unit of creation and management, and is the smallest resource object model created or deployed by the user in the resource object model. Pod is a resource object for running containerized applications on k8s, and other resource objects are used to support or extend the functions of Pod objects. For example, the controller object is used to control Pod objects, the Service or Ingress resource objects are used to expose Pod reference objects, and the PersistentVolume resource object provides storage for Pod. Kubernetes does not directly process containers, but manages containers through Pod. Each Pod can be composed of one or more containers, and each Pod is a single instance running an application. Generally, the weight of each container group can be set in the load balancing rule file according to specific needs. For example, the location of the physical device corresponding to the container group, the size of the database corresponding to the container group, the cluster scale, etc. can all be the basis for setting the weight.
[0053] In this embodiment, after the controller reads the load balancing rule file, the corresponding traffic load balancing rules are generated for the container cluster in the target area corresponding to the load balancing rule file based on the weight corresponding to each container contained in the load balancing rule file, and then based on the acquired area information and weight information.
[0054] In this embodiment, according to the weight corresponding to each container group included in the load balancing rule file, the specific steps of generating a corresponding traffic load balancing rule for the container cluster in the target area corresponding to the load balancing rule file include: S12-1: Determine the operating status of each container group in the target area.
[0055] In this embodiment, the running state of the container group may indicate whether each container group is in a normal running state or an abnormal state.
[0056] In this embodiment, the controller reads the virtual address of the target area, monitors each container group in the target area, obtains the operation status information of each container group in the target area, and determines the operation status of each container group in the target area.
[0057] In this embodiment, the specific steps of determining the operating status of each container group in the target area include: S12-1-1: obtaining operating status information of each container group in the target area.
[0058] In this embodiment, after starting monitoring of the container cluster in the target area, the controller monitors each container group in the container cluster respectively. A container cluster includes multiple container groups.
[0059] In this embodiment, the controller determines the container group to be monitored through the configuration information of the selector corresponding to each container group, and obtains the running status information of all container groups in the container cluster when the container cluster in the target area is running.
[0060] S12-1-2: When the operation status information is normal, determine that the operation status of the container group is a normal operation status.
[0061] In this embodiment, when the running status information is normal, it is determined that the running status of the container group is a normal running status. At this time, the container group can normally receive flow data.
[0062] For example, when the container group is in a normal operating state, the operating state information received by the controller is running.
[0063] S12-1-3: When the operation status information is abnormal, determine that the operation status of the container group is abnormal.
[0064] In this embodiment, when the operation status information is abnormal, it is determined that the operation status of the container group is abnormal. At this time, the container group cannot normally receive traffic data.
[0065] For example, when the container group is in an abnormal state, the running state information received by the controller is wrong.
[0066] S12-2: For each container group whose running status is normal operation, obtain a weight corresponding to the container group in the load balancing rule file.
[0067] In this embodiment, for each container group whose operating status is normal operation, a weight corresponding to the container group is obtained according to the load rule file. The weight corresponding to each container group is pre-set in the load rule file. The weight corresponding to each container group can be obtained by reading the relevant settings.
[0068] S12-3: Using the virtual address of the target area as the target virtual address and the backend network address corresponding to the container group as the real network address to generate the traffic load balancing rule.
[0069] In this embodiment, the target virtual address is the virtual address of the container cluster, and the real network address is the network address required to access the container group.
[0070] In this embodiment, the virtual address of the target area is used as the target virtual address, and the backend network address corresponding to the container group is used as the real network address to generate the corresponding traffic load balancing rule.
[0071] For example, the target virtual address is 1.1.1.1, the real network addresses of container group A and container group B in target area A are 192.168.1.101 and 192.168.1.102, respectively, and the weights are 1 and 2, respectively. The generated traffic load balancing rules are: 1.1.1.1 wlc ->192.168.0.101Masq1 ->192.168.0.102Masq2 WLC refers to the wireless LAN controller.
[0072] In another embodiment of the present application, before generating a corresponding traffic load balancing rule for the container cluster in the target area corresponding to the load balancing rule file according to the weight corresponding to each container group included in the load balancing rule file, the method further includes: S31: Obtain the virtual address of the target area from the load balancing rule file.
[0073] In this embodiment, after receiving the load balancing rule file, the controller first reads the virtual address corresponding to the target area set in the load balancing rule file.
[0074] S32: Establishing a connection with the container cluster in the target area according to the virtual address.
[0075] In this embodiment, after the virtual address is obtained, the virtual address is accessed to establish a connection with the container cluster in the target area.
[0076] In this embodiment, the method further includes: S33: Determine the subnet information corresponding to the target area according to the namespace in the load balancing rule.
[0077] In this embodiment, the subnet information is information corresponding to the subnet of the container cluster in the virtual private cloud, and the operating status of the subnet can be determined through the subnet information.
[0078] In this embodiment, there is a corresponding relationship between the namespace and the subnet, which is stored in the corresponding storage space, and the corresponding subnet can be found according to the namespace. After reading the namespace in the load balancing rule, the controller searches for the subnet information corresponding to the target area according to the namespace.
[0079] S34: Determine whether the subnet corresponding to the subnet information exists.
[0080] In this embodiment, after the corresponding subnet information is found through the namespace, the subnet information may indicate whether the subnet exists in the virtual private cloud.
[0081] S35: In the case where the subnet exists, start monitoring the subnet.
[0082] In this embodiment, when a subnet corresponding to the namespace exists, the controller starts monitoring the subnet, that is, monitors the running status of the container group in the corresponding area in the virtual private cloud.
[0083] In this embodiment, the method further includes: S36: If the subnet does not exist, create a corresponding subnet according to the virtual address of the target area.
[0084] In this embodiment, when the subnet does not exist, generally when the virtual private cloud is started for the first time, it is necessary to create a corresponding subnet in the virtual private cloud based on the virtual address of the target area. The container group in the subnet belongs to the subnet after the subnet is created. The container group in the subnet can be connected to the network of the virtual private cloud to transmit information.
[0085] S37: Start monitoring the subnet.
[0086] In this embodiment, after a subnet corresponding to a virtual address is created in a virtual private cloud, monitoring of the subnet is started, that is, monitoring the running status of the container group under the subnet in the virtual private cloud.
[0087] In this embodiment, the monitoring method is to obtain the running status information of the container group from each container group under the subnet every time period. If the container group replies normally, it means that the container group is in a normal running state. If the container group does not reply to the information or replies with abnormal information, it means that the container group is in an abnormal running state.
[0088] S13: Allocate corresponding traffic to each container group in the container cluster in the target area corresponding to the load balancing rule file according to the traffic load balancing rule.
[0089] In this embodiment, after determining the traffic load balancing rule of the container cluster in the target area, corresponding traffic is allocated to each container group in the container cluster in the target area corresponding to the load balancing rule file.
[0090] In this embodiment, the specific steps of allocating corresponding traffic to each container group in the container cluster in the target area corresponding to the load balancing rule file include: S13-1: Determine the traffic load ratio corresponding to each of the container groups according to the traffic load balancing rule.
[0091] In this embodiment, after the traffic load balancing rule is determined, the traffic load proportion borne by each container group in the target area can be determined according to the traffic load balancing rule, that is, the traffic load proportion corresponding to the container group is obtained according to the weight in the traffic load balancing rule.
[0092] For example, the weight of container group A in the target area is 1, and the weight of container group B is 2. Then, the traffic load ratio of container group A is 1 / 3, and the traffic load ratio of container group B is 2 / 3.
[0093] S13-2: when the flow data is received, allocating corresponding flow to the container group according to the flow load ratio corresponding to each container group.
[0094] In this embodiment, when the controller receives the flow data, it allocates a flow of a corresponding flow load ratio to each container group according to the flow load ratio corresponding to each container group.
[0095] For example, the weight of container group A in the target area is 1, and the weight of container group B is 2. Then the traffic load ratio of container group A is 1 / 3, and the traffic load ratio of container group B is 2 / 3. When receiving traffic, 1 / 3 of the traffic is allocated to container group A for processing, and 2 / 3 of the traffic is allocated to container group B for processing.
[0096] In this embodiment, users are allowed to customize the virtual network address of the internal load balancing, which avoids the problems of network address range sharing and non-overlapping in related technologies, improves the flexibility of network address management, and realizes dynamic management of container groups in clusters in different regions through the configuration of namespaces and selectors, thereby improving the isolation and security of resources.
[0097] In another embodiment of the present application, the method further includes: S41: When it is detected that the container group in the target area is in an abnormal state, the traffic corresponding to the target area is switched to the remaining areas in the load balancing rule file.
[0098] In this embodiment, several areas are listed in the load balancing rule file, and a corresponding container cluster is allocated to each area. When it is detected that the container group in the target area is in an abnormal state, the container cluster in the target area cannot process the traffic data. The traffic corresponding to the target area needs to be switched to the remaining areas defined in the load balancing rule file.
[0099] In this embodiment, the specific steps of switching the traffic corresponding to the target area to the remaining areas in the load balancing rule file include: S41-1: Clearing data traffic in the target area.
[0100] In this embodiment, when an abnormality occurs in the container cluster in the target area and traffic needs to be switched, the data traffic in the target area is first cleaned up, the data stored in the container group in the target area is deleted, and the task executed by the container group in the target area is terminated.
[0101] S41-2: Delete the load balancing rule in the target area.
[0102] In this embodiment, when an abnormality occurs in the container group in the target area, the load balancing rule corresponding to the target area is deleted. At this time, the container group in the target area can no longer continue to process traffic data. At this time, the container cluster in the target area is marked as abnormal, and the information is recorded in the log. An attempt is made to restore the container cluster and delete the corresponding load balancing rule.
[0103] S41-3: Send the traffic corresponding to the target area to the virtual addresses corresponding to the remaining areas.
[0104] In this embodiment, when all container groups in the target area are abnormal, the controller sends the traffic data in the target area to the remaining areas set in the load balancing rule file, and sends the data to the normally operating container groups in the remaining areas according to the virtual addresses in the remaining areas and the real addresses of the corresponding container groups.
[0105] In another embodiment of the present application, the method further includes: S51: When it is detected that any of the container groups in the target area is in an abnormal state, distribute the flow corresponding to the container group to the remaining container groups in the target area.
[0106] In this embodiment, when it is detected that any container group in the target area is in an abnormal state, and the remaining container groups in the target area are in a normal operating state, the flow corresponding to the container group is distributed to the remaining container groups in the target area.
[0107] In this embodiment, the specific step of allocating the flow corresponding to the container group to the remaining container groups in the target area includes: S51 - 1 : setting corresponding weights for the remaining container groups in the target area.
[0108] In this embodiment, when the remaining container groups in the target area are in a normal operating state, the weights of the remaining container groups in the load balancing rule file are modified. When modifying the weights in the load balancing rule file, a larger weight can be set for the container groups with stronger load capacity and larger traffic demand in the remaining container groups according to actual conditions, and a smaller weight can be set for the container groups with weaker load capacity and smaller traffic demand. After the setting is completed, the new load balancing rule file is imported into the controller.
[0109] S51 - 2 : Allocate corresponding flows to the remaining container groups in the target area according to the weights.
[0110] In this embodiment, when the controller reads that the weight in the load balancing rule file has changed, it starts to modify the weights in the remaining container groups, and then generates a new traffic load balancing rule. When modifying the weights of the remaining container groups, first send all the currently processed traffic to one of the container groups for processing, and give priority to sending the traffic to the container group with the original larger weight. Modify the corresponding settings of the remaining idle containers, and then apply the new weight to the corresponding container group. After the weight settings in the remaining idle container groups are modified, the traffic is sent to the modified container group, and then the weight of the unmodified container group is modified. After the weights of all the remaining container groups are modified, each remaining normally operating container group is set accordingly according to the new weight set in the new load balancing rule file. At this time, the controller allocates a corresponding proportion of traffic to the remaining container groups in the target area according to the newly set weighting.
[0111] For example, the target area A includes container group A, container group B, and container group C, wherein the weight of container group A is 2, the weight of container group B is 2, and the weight of container group C is 3. When the operation status of container group A is abnormal, container group A is shut down, and all traffic in the target area A is first sent to container group C, and then the weight of container group B is modified to 3. After the modification is completed, the traffic in the target area A is sent to container group B, and the weight of container group C is modified to 4. After the modification is completed, according to the modified weights, the traffic is proportionally distributed to container group B and container group C.
[0112] In this embodiment, it supports configuring different weights for each container group. The controller dynamically adjusts the traffic distribution ratio according to the operating status and weight information of the container group, making the traffic distribution more intelligent and refined, improving resource utilization and system performance. It supports defining regional information in the load balancing rule file. When it is detected that all container groups in a certain area are unavailable, the controller automatically switches the traffic area to the normal operating container groups in other areas. When a container group in a region is unavailable, the traffic in the region is dynamically allocated to the remaining normal operating container groups, ensuring the high availability of the service, reducing the service interruption time, improving the disaster recovery capability of the system and the continuity of the business, and improving the work efficiency of the entire virtual private cloud.
[0113] In another embodiment of the present application, after the controller switches the traffic to the container group of the remaining area, it attempts to restore the target area, allocates a new container group to the target area or restarts the container group of the target area. First, it attempts to restart the container group of the target area to restore the container group in the target area to the initialization state to see if it succeeds. If the restart is successful, the traffic switched to the container group of the remaining area is switched back to the container group that successfully restarted. At this time, the weight in the load balancing rule does not need to be modified, and the original rule is used directly. If the restart is unsuccessful, a new container group is reallocated to the target area. After the new container group is allocated to the target area, the corresponding load balancing rule file needs to be modified, wherein the real address of the backend container group in the target area needs to be modified, and the corresponding weight can remain unchanged or be reset according to the demand. After modifying the load balancing rule file, the modified load balancing rule file is read by the controller, and then according to the regional information and weight in the load balancing rule file, the corresponding load balancing rule is generated for the container cluster in the target area, and the corresponding traffic is allocated to the container group in the target area in accordance with the load balancing rule.
[0114] refer to Figure 2 , Figure 2 is a schematic diagram of a load balancing process proposed in an embodiment of the present application, such as Figure 2As shown, first create a load balancing rule file, then read the load balancing rule file through the controller, the controller connects to the first available area in the load balancing rule file, that is, the target area, obtains the corresponding subnet information according to the namespace in the file, and determines whether the current subnet exists. If the subnet does not exist, create the corresponding subnet according to the virtual address, and then monitor the running status of the container group in the corresponding subnet according to the configuration of the namespace and selector. After obtaining the container group with normal running status, for each container group with normal running status, use the virtual address of the target area as the target virtual address, and use the network address of the backend container group as the real network address to generate the corresponding load balancing rule. When the cluster in this area cannot be connected or there is no container group running normally, try to connect to other areas.
[0115] refer to Figure 3 , Figure 3 Schematic diagram of the working principle of the controller proposed in one embodiment of the present application. Figure 3 As shown, in the conventional virtual private cloud load balancing mode, service information, terminal information, and container group information are obtained, that is, a load balancing rule for the container group corresponding to the service in the default cluster is generated under the default virtual private cloud, for example: serviceIP rr ->pod1 IP ->pod2 IP.
[0116] In the custom private cloud mode, by receiving the load balancing rule file, determining the container group A and container group B in area A, and container group A and container group B in area B in the file, and generating the custom virtual address of the load balancing rule and the custom load balancing rule, for example: Custom IP wlc ->Availability Zone podAIP Masq Weight 1 ->Available Zone podBIP Masq Weight 2.
[0117] In the above embodiments of the present application, the user is allowed to define load balancing rules in a custom virtual private cloud, so that the user can flexibly configure the load balancing strategy according to his own needs, dynamically monitor the running status of the container group in the regional cluster according to the namespace and selector, and realize the automatic management and dynamic adjustment of the load balancing backend container group. Different weights are set for each container group, and traffic scheduling is performed according to the weights, allowing the user to allocate different traffic ratios according to actual needs. The controller dynamically adjusts the traffic allocation ratio according to the running status and weight information of the container group, making the traffic allocation more intelligent, and can be automatically adjusted according to the actual situation, thereby improving the overall performance and resource utilization of the system. Regional information is defined in the load balancing rule file, and cross-regional load balancing can be achieved according to the regional information, so that the load balancing strategy is not limited to a single region, and cross-regional traffic scheduling is realized, and the traffic is always allocated to the container group with normal running status, ensuring the high availability of the service and the continuity of the business, improving the disaster recovery capability of the system, and improving the service quality of the system.
[0118] Based on the same inventive concept, an embodiment of the present application provides a load balancing device. Figure 4 , Figure 4 FIG. 4 is a schematic diagram of a load balancing device 400 proposed in an embodiment of the present application. Figure 4 As shown, the device comprises: A file reading module 401 is used to read a pre-created load balancing rule file, where the load balancing rule file includes traffic load balancing rule information of the container cluster; A rule generation module 402 is used to generate a corresponding traffic load balancing rule for the container cluster in the target area corresponding to the load balancing rule file according to the weight corresponding to each container group included in the load balancing rule file; The traffic distribution module 403 is used to distribute corresponding traffic to each container group in the container cluster in the target area corresponding to the load balancing rule file according to the traffic load balancing rule.
[0119] Optionally, the device further comprises: A first file setting module, used to set the name, virtual address, session persistence strategy, namespace and selector of the custom private cloud in the space part of the load balancing rule file; A second file setting module, used to set the virtual address and weight corresponding to each area in the area part of the load balancing rule file; A third file setting module, used to set the corresponding target service and port list in the port part of the load balancing rule file; The fourth file setting module is used to set the backend network address corresponding to the container group in the terminal part of the load balancing rule file.
[0120] Optionally, the device further comprises: A virtual address acquisition module, used to acquire the virtual address of the target area from the load balancing rule file; A connection establishing module is used to establish a connection with the container cluster in the target area according to the virtual address.
[0121] Optionally, the device further comprises: A subnet information acquisition module, used to determine the subnet information corresponding to the target area according to the namespace in the load balancing rule; A subnet determination module, used to determine whether a subnet corresponding to the subnet information exists; The first monitoring start module is used to start monitoring the subnet if the subnet exists.
[0122] Optionally, the device further comprises: A subnet creation submodule, used for creating a corresponding subnet according to the virtual address of the target area when the subnet does not exist; The second monitoring start module is used to start monitoring the subnet.
[0123] Optionally, the rule generation module includes: An operation status determination submodule, used to determine the operation status of each container group in the target area; A weight acquisition submodule, configured to acquire, for each container group whose operating state is normal operation, a weight corresponding to the container group in the load balancing rule file; The rule generation submodule is used to use the virtual address of the target area as the target virtual address and the backend network address corresponding to the container group as the real network address to generate the traffic load balancing rule.
[0124] Optionally, the operation status determination submodule includes: an operation status information acquisition submodule, configured to acquire operation status information of each of the container groups in the target area; A first operation status determination submodule, configured to determine, when the operation status information is normal, that the operation status of the container group is a normal operation status; The second operation status determination submodule is configured to determine that the operation status of the container group is an abnormal state when the operation status information is abnormal.
[0125] Optionally, the traffic distribution module includes: A traffic load ratio determination submodule, configured to determine the traffic load ratio corresponding to each of the container groups according to the traffic load balancing rule; The flow distribution submodule is used to distribute corresponding flow to the container group according to the flow load ratio corresponding to each container group when receiving the flow data.
[0126] Optionally, the device further comprises: The first traffic switching module is configured to switch the traffic corresponding to the target area to the remaining areas in the load balancing rule file when it is detected that the container group in the target area is in an abnormal state.
[0127] Optionally, the first flow switching module includes: A traffic cleaning submodule, used to clean up the data traffic in the target area; A rule deletion submodule, used to delete the load balancing rule in the target area; The first traffic sending submodule is used to send the traffic corresponding to the target area to the virtual addresses corresponding to the remaining areas.
[0128] Optionally, the device further comprises: The second flow switching module is used to distribute the flow corresponding to the container group to the remaining container groups in the target area when it is detected that any of the container groups in the target area is in an abnormal state.
[0129] Optionally, the second flow switching module includes: A weight setting submodule, used to set corresponding weights for the remaining container groups in the target area; The remaining container group flow distribution submodule is used to distribute corresponding flows to the remaining container groups in the target area according to the weights.
[0130] Based on the same inventive concept, another embodiment of the present application provides a readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps in the method described in any of the above embodiments of the present application.
[0131] Based on the same inventive concept, another embodiment of the present application provides an electronic device, Figure 5 It is a schematic diagram of an electronic device 500 proposed in one embodiment of the present application, including a memory 502, a processor 501 and a computer program stored in the memory and executable on the processor, wherein when the processor is executed, the steps in the dual-site data storage method described in any of the above embodiments of the present application are implemented.
[0132] As for the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.
[0133] The various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the various embodiments can be referenced to each other.
[0134] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, devices, or computer program products. Therefore, the embodiments of the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the embodiments of the present application may adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program codes.
[0135] The embodiments of the present application are described with reference to the flowcharts and / or block diagrams of the methods, terminal devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing terminal device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing terminal device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0136] These computer program instructions may also be stored in a computer readable memory capable of directing a computer or other programmable data processing terminal device to operate in a specific manner, so that the instructions stored in the computer readable memory produce a manufactured product including an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0137] These computer program instructions can also be loaded onto a computer or other programmable data processing terminal device so that a series of operating steps are executed on the computer or other programmable terminal device to produce a computer-implemented process, thereby providing instructions for executing on the computer or other programmable terminal device to implement the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0138] Although the preferred embodiments of the present application have been described, those skilled in the art may make additional changes and modifications to these embodiments once they have learned the basic creative concept. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications that fall within the scope of the embodiments of the present application.
[0139] Finally, it should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or terminal device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or terminal device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or terminal device including the elements.
[0140] The load balancing method, product, device and storage medium provided by the present application are introduced in detail above. Specific examples are used in this article to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method of the present application and its core idea. At the same time, for general technical personnel in this field, according to the idea of the present application, there will be changes in the specific implementation method and application scope. In summary, the content of this specification should not be understood as a limitation on the present application.
Claims
1. A load balancing method, characterized in that: The method comprises: Read a pre-created load balancing rule file, where the load balancing rule file includes traffic load balancing rule information of the container cluster; Generate a corresponding traffic load balancing rule for the container cluster in the target area corresponding to the load balancing rule file according to the weight corresponding to each container group included in the load balancing rule file; According to the traffic load balancing rule, corresponding traffic is allocated to each container group in the container cluster in the target area corresponding to the load balancing rule file.
2. The load balancing method according to claim 1, characterized in that: Before reading the pre-created load balancing rule file, the method further includes: Setting the name, virtual address, session persistence policy, namespace and selector of the custom private cloud in the space part of the load balancing rule file; Setting the virtual address and weight corresponding to each area in the area part of the load balancing rule file; Set the corresponding target service and port list in the port part of the load balancing rule file; The backend network address corresponding to the container group is set in the terminal part in the load balancing rule file.
3. The load balancing method according to claim 1, characterized in that: Before generating a corresponding traffic load balancing rule for the container cluster in the target area corresponding to the load balancing rule file according to the weight corresponding to each container group included in the load balancing rule file, the method further includes: Obtaining a virtual address of a target area from the load balancing rule file; A connection is established with the container cluster in the target area according to the virtual address.
4. The load balancing method according to claim 3, characterized in that: The method further comprises: Determine the subnet information corresponding to the target area according to the namespace in the load balancing rule; Determine whether the subnet corresponding to the subnet information exists; If the subnet exists, start monitoring the subnet.
5. The load balancing method according to claim 4, characterized in that: The method further comprises: If the subnet does not exist, creating a corresponding subnet according to the virtual address of the target area; Start monitoring of the subnet.
6. The load balancing method according to claim 1, characterized in that: The generating, according to the weight corresponding to each container group included in the load balancing rule file, a corresponding traffic load balancing rule for the container cluster in the target area corresponding to the load balancing rule file comprises: Determine the operating status of each container group in the target area; For each container group whose running status is normal operation, obtaining a weight corresponding to the container group in the load balancing rule file; The traffic load balancing rule is generated by taking the virtual address of the target area as the target virtual address and the backend network address corresponding to the container group as the real network address.
7. The load balancing method according to claim 6, characterized in that: Determining the operation status of each container group in the target area includes: acquiring operation status information of each container group in the target area; When the running status information is normal, determining that the running status of the container group is a normal running status; When the running status information is abnormal, it is determined that the running status of the container group is an abnormal status.
8. The load balancing method according to claim 1, characterized in that: The allocating corresponding traffic to each container group in the container cluster in the target area corresponding to the load balancing rule file according to the traffic load balancing rule includes: Determine the traffic load ratio corresponding to each of the container groups according to the traffic load balancing rule; When the flow data is received, the corresponding flow is allocated to the container group according to the flow load ratio corresponding to each container group.
9. The load balancing method according to claim 1, characterized in that: The method further comprises: When it is detected that the container group in the target area is in an abnormal state, the traffic corresponding to the target area is switched to the remaining areas in the load balancing rule file.
10. The load balancing method according to claim 9, characterized in that: Switching the traffic corresponding to the target area to the remaining areas in the load balancing rule file includes: Cleaning up data traffic in the target area; Deleting the load balancing rule in the target area; The traffic corresponding to the target area is sent to the virtual addresses corresponding to the remaining areas.
11. The load balancing method according to claim 1, characterized in that: The method further comprises: When it is detected that any of the container groups in the target area is in an abnormal state, the flow corresponding to the container group is distributed to the remaining container groups in the target area.
12. The load balancing method according to claim 11, characterized in that: The allocating the flow corresponding to the container group to the remaining container groups in the target area includes: Setting corresponding weights for the remaining container groups in the target area; According to the weights, corresponding flows are allocated to the remaining container groups in the target area.
13. A computer program product comprising a computer program / instructions, characterized in that When the computer program / instructions are executed by a processor, the steps in the method according to any one of claims 1 to 12 are implemented.
14. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps in the method according to any one of claims 1 to 12 are implemented.
15. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 12 are implemented.
Citation Information
Patent Citations
Multi-cluster access method and system
CN115150410A
Pod traffic processing method, system and device and storage medium
CN115277586A
Load balancing method and device based on Kubernetes
CN116132447A
Load balance control method and server
WO2021120976A2