Skip to content

Commit 05acfd6

Browse files
committed
metallb: Describe how load balancing works
Despite being called MetalLB, the project does not actually implement load balancing as it is typically thought of (something like haproxy). It is one piece of a larger setup that results in load balancing for Service Load Balancers. These additions to the doc attempt to help explain further how load balancing works with MetalLB.
1 parent 5999c9b commit 05acfd6

File tree

1 file changed

+50
-1
lines changed

1 file changed

+50
-1
lines changed

enhancements/network/on-prem-service-load-balancers.md

+50-1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,19 @@ custom manner. For more information on the existing `IngressIPs` feature:
5151

5252
### Goals
5353

54+
Some more context is helpful before specifying the goals of this enhancement.
55+
When a Service has an external IP address, the OpenShift network plugin in use
56+
must already prepare networking on Nodes to be able to receive traffic with
57+
that IP address as a destination. The network plugin does not know or care
58+
about how that traffic reaches the Node because the mechanism differs depending
59+
on which platform the cluster is running on. Once that traffic reaches a Node,
60+
the existing Service proxy functionality handles forwarding that traffic to a
61+
Service backend, including some degree of load balancing.
62+
63+
With this context in mind, the goal of this enhancement is less about load
64+
balancing itself, and more about providing mechanisms of routing traffic to
65+
Nodes for external IP addresses used for Service Load Balancers.
66+
5467
A SLB solution must provide these high level features:
5568

5669
* Management of one or more pools of IP addresses to be allocated for SLBs
@@ -63,8 +76,11 @@ A SLB solution must provide these high level features:
6376
(likely BGP), but should also be usable in smaller, simpler environments
6477
using L2 protocols. Tradeoffs include:
6578
* Layer 2 (gratuitous ARP for IPv4, NDP for IPv6) - good for wide range of
66-
environment compatibility, but limiting for larger clusters
79+
environment compatibility, but limiting for larger clusters. All traffic
80+
for a single Service Load Balancer IP address must go through one node.
6781
* Layer 3 (BGP) - good for integration with networks for larger clusters
82+
and opens up the possibility for a greater degree of load balancing using
83+
ECMP to send traffic to multiple Nodes for a single Service Load Balancer
6884
* Suitable for large scale clusters (target up to 2000 nodes).
6985
* Must be compatible with at least the following cluster network types:
7086
[OpenShift-SDN](https://github.com/openshift/sdn) and
@@ -103,6 +119,39 @@ also consider a MetalLB enhancement that makes it understand different L2
103119
domains and manage different IP address pools for each domain where SLBs may
104120
reside.
105121

122+
### How Load Balancing Works with MetalLB
123+
124+
As mentioned in the Goals section, MetalLB does not have to implement load
125+
balancing itself. It only implements ensuring load balancer IP addresses are
126+
reachable on appropriate Nodes. The way a cluster uses MetalLB does have an
127+
impact on how load balancing works, though.
128+
129+
When the Layer 2 mode is in use, all traffic for a single external IP address
130+
must go through a single Node in the cluster. MetalLB is responsible for
131+
choosing which Node this should be. From that Node, the Service proxy will
132+
distribute load across the Endpoints for that Service. This provides a degree
133+
of load balancing, as long as the Service traffic does not exceed what can go
134+
through a single Node.
135+
136+
The BGP mode of MetalLB offers some improved capabilities. It is possible for
137+
the router(s) for the cluster to send traffic for a single external IP address
138+
to multiple Nodes. This removes the single Node bottleneck. The number of
139+
Nodes which can be used as targets for the traffic depends on the configuration
140+
of a given Service. There is a field on Services called
141+
[`externalTrafficPolicy` that can be `cluster` or
142+
`local`](https://kubernetes.io/docs/tasks/access-application-cluster/create-external-load-balancer/#preserving-the-client-source-ip).
143+
144+
* `local` -- In this mode, the pod expects to receive traffic with the original
145+
source IP address still intact. To achieve this, the traffic must go directly
146+
to a Node where one of the Endpoints for that Service is running. Only those
147+
Nodes advertise the Service IP in this case.
148+
149+
* `cluster` -- In this mode, traffic may arrive on any Node and will be
150+
redirected to another Node if necessary to reach a Service Endpoint. The
151+
source IP address will be changed to the Node's IP to ensure traffic returns
152+
via the same path it arrived on. The Service IP is advertised for all Nodes
153+
for these Services.
154+
106155
### User Stories
107156

108157
#### Match Cloud Load Balancer Functionality Where Possible

0 commit comments

Comments
 (0)