Understanding MetalLB
TOC
Terminology
Principles of High Availability in MetalLB

By default, the platform uses MetalLB's ARP mode, and the specific implementation process and principles are as follows:
-
The Controller component of MetalLB selects an IP address from the external address pool and allocates it to the LoadBalancer type internal routing as a VIP.
-
MetalLB selects an available node to host the VIP based on the algorithm, which then forwards the traffic.
-
The Speaker component on this node actively sends GARP, establishing a mapping relationship between the VIP and MAC address across all nodes.
-
Nodes within the same subnet, upon learning the mapping between the VIP and the available node's MAC address, will communicate directly with this node when accessing the VIP.
-
Nodes in different subnets will route traffic to the gateway of their subnet first, which will then forward the traffic to the node hosting the VIP.
-
-
When this node encounters a failure, MetalLB selects another available node to host the VIP, thereby ensuring high availability.
-
Upon reaching the node, Kube-Proxy forwards the traffic to the corresponding Pod.
MetalLB's Algorithm for Selecting VIP Host Nodes
MetalLB hashes all available nodes corresponding to the external address pool with the VIP and sorts them according to a specific algorithm, choosing the first available node as the host for the VIP.
External Address Pools and Number of Nodes
Create an external address pool and add available nodes. All available nodes maintain a backup relationship, meaning only the node hosting the VIP can forward traffic, requiring it to handle all traffic for the VIPs in the external address pool.
Calculation Formula
The formula is: Number of external address pools = ceil(n-vip / n-node), where ceil rounds up.
Note: If using virtual machines, the number of virtual machines = Number of external address pools * n. Here, n must be greater than 2, with a maximum of one node failure allowed.
-
n-vip: Represents the number of VIPs.
-
n-node: Represents the number of VIPs a single node can handle.
Application Example
If a company has 10 VIPs, and each available node can handle 5 VIPs, allowing for one node failure, how should the company plan the number of external address pools and available nodes?
Analysis:
A total of two external address pools and four available nodes are needed.
-
Each available node can handle a maximum of 5 VIPs, meaning one external address pool can accommodate 5 VIPs, so two external address pools are required for 10 VIPs.
-
Allowing one node failure means that each address pool must include one node hosting the VIP and one backup node, resulting in two available nodes for each of the two external address pools.