KubernetesCXII · Load Balancing on Bare MetalLoad balancing on bare metal
MetalLB BGP mode — multi-node load balancing with ECMP
What you'll learn
- Use MetalLB BGP mode for production load balancing
- Configure IPAddressPool, BGPPeer, BGPAdvertisement
- Apply BGP communities for routing policy
- Apply the operational discipline of BGP mode for production
Prerequisites
Verified against Kubernetes 1.34.x · kubeadm 1.34.x · kubectl 1.34.x · etcd 3.6.x · CoreDNS 1.11.x · containerd 1.7.x / 2.x · 2026-08-16
MetalLB BGP mode advertises Service IPs via BGP, allowing multi-node load balancing with ECMP and fast failover. This lesson walks the mechanism, the configuration, BGP communities, and the discipline.
How BGP mode works
flowchart LR
A[Service LoadBalancer] --> B[MetalLB Controller]
B --> C["IPAddressPool: allocate IP"]
C --> D["Speaker: every node"]
D -->|BGP advertise| E[Router]
E -->|ECMP| F[Node 1]
E -->|ECMP| G[Node 2]
E -->|ECMP| H[Node 3]
F -->|kube-proxy| I[Service backend]
G --> I
H --> I
The BGP mechanism:
- The MetalLB controller allocates an IP from the IPAddressPool.
- Every Speaker (one per node) advertises the IP via BGP to the upstream router.
- The router sees multiple equal-cost paths (ECMP) and load-balances across them.
- Each node’s kube-proxy distributes traffic to Service backends.
- If a node fails, BGP withdraws its advertisement; the router stops sending traffic to it. BFD (Bidirectional Forwarding Detection) detects the failure in < 1 second.
The configuration
apiVersion: metallb.io/v1beta1
kind: IPAddressPool
metadata:
name: prod-pool
namespace: metallb-system
spec:
addresses:
- 192.168.100.0/24
---
apiVersion: metallb.io/v1beta2
kind: BGPPeer
metadata:
name: prod-router
namespace: metallb-system
spec:
peerAddress: 192.168.1.1
peerASN: 64512
myASN: 64513
holdTime: 90s
keepaliveTime: 30s
---
apiVersion: metallb.io/v1beta1
kind: BGPAdvertisement
metadata:
name: prod-advert
namespace: metallb-system
spec:
ipAddressPools:
- prod-pool
peers:
- prod-router
communities:
- 64512:100
The configuration:
- IPAddressPool. The range of IPs.
- BGPPeer. The router’s IP, ASN; MetalLB’s ASN; timers.
- BGPAdvertisement. Binds the pool to the peer; BGP communities.
# On the router (Cisco IOS example)
show ip bgp neighbors
Verify the BGP sessions are established and the IPs are advertised.
BGP communities
flowchart LR
A[MetalLB advertises IP] --> B["With community 64512:100"]
B --> C[Router receives]
C --> D{Match community?}
D -->|64512:100| E[Set local-preference 200]
D -->|Other| F[Default preference]
E --> G[Route preferred]
BGP communities are tags attached to BGP routes. The router can match on communities and apply routing policy:
64512:100— tag MetalLB-originated routes for the prod pool.64512:200— tag for a different pool; different local-preference.
Communities allow granular routing policy without manual filter lists.
BFD for fast failover
apiVersion: metallb.io/v1beta2
kind: BGPPeer
metadata:
name: prod-router
spec:
peerAddress: 192.168.1.1
peerASN: 64512
myASN: 64513
bfd:
receiveInterval: 50ms
transmitInterval: 50ms
multiplier: 3
BFD (Bidirectional Forwarding Detection) detects peer failure in milliseconds:
- receiveInterval / transmitInterval: how often BFD packets are sent.
- multiplier: how many missed packets before declaring failure (3 × 50ms = 150ms total).
With BFD, failover is sub-second instead of 30-60 seconds (default BGP timers).
The failover
flowchart LR
A[Node fails] --> B[BFD detects in milliseconds]
B --> C[BGP withdraws the route]
C --> D[Router stops sending traffic]
D --> E[Other nodes continue serving]
E --> F[Sub-second failover]
The failover:
- A node fails (network, power, etc.).
- BFD detects the failure in milliseconds.
- The Speaker on the failed node withdraws its BGP advertisement.
- The router stops sending traffic to the failed node.
- The remaining nodes continue serving traffic.
- End-to-end failover: < 1 second.
The operational trade-offs
flowchart LR
A[BGP mode] --> B[+ Multi-node load balancing]
A --> C[+ ECMP for throughput]
A --> D[+ Sub-second failover with BFD]
A --> E[- Requires router config]
A --> F["- AS numbers, communities"]
A --> G[- Operational complexity]
The trade-offs:
- Pros. Multi-node; ECMP; sub-second failover.
- Cons. Requires router config; AS numbers, communities; operational complexity.
Quiz
Knowledge check · 4 questions
Q1. What lets MetalLB BGP mode spread a single Service's traffic across nodes?
Q2. ECMP rehashing on a topology change can reset established connections.
Q3. Explain why BGP mode is delivering all traffic to one node and enable equal-cost multipath.
MetalLB BGP mode is configured across six nodes with pool 192.168.100.0/24 and a BGPPeer to 192.168.1.1 in ASN 64512. All six sessions are Established. On the router, `show ip bgp 192.168.100.20/32` lists six paths but only one is marked as best with `*>`. Interface counters confirm every external packet for that address enters through node-1, and draining node-1 causes a brief outage.
Q4. What is MetalLB's default BGP hold time, and what configuration brings failure detection below one second?
Passing score: 75%. Answers are checked in this browser.
The operational discipline
MetalLB BGP in production rests on five non-negotiable elements:
- BGP communities. Use them for routing policy.
- BFD for fast failover. Sub-second failover is essential for production.
- Verify BGP sessions. Use
show ip bgp summaryon the router. - Test failover. Disconnect a node; verify traffic redistributes.
- Document the topology. IP pools, peers, ASNs, communities, BFD configuration.
MetalLB BGP is the production-grade load balancer for on-prem. The discipline is to test failover, monitor BGP sessions, and document the configuration.