Networking and traffic
MetalLB
1.Why MetalLB ?
On bare metal a LoadBalancer Service stays EXTERNAL-IP <pending> forever: no cloud controller hands out IPs.
- NodePort is ugly (high ports, clients must know node IPs)
- Cloud LBs (ELB, GCP LB) are not available on-prem, in homelabs or at the edge
- MetalLB = IP allocation from your pools + announcement to the network (L2 or BGP)
Fills in type: LoadBalancer, the Service type after NodePort.
2.Components
Installs into metallb-system, idle until you create a pool and an advertisement.
- Two jobs : assign IPs, then advertise them
- Works with IPv4, IPv6 and dual stack
- Config is Custom Resources only
- controllerDeployment. Watches Services, picks an IP from an IPAddressPool, writes it to the Service status.
- speakerDaemonSet. Announces the IP via ARP/NDP or BGP. Uses memberlist (7946 TCP/UDP) to spot dead nodes.
- frr-k8sDefault BGP backend. Wrapper around FRR, adds BFD and IPv6.
3.L2 Mode Flow
Controller allocates, speaker announces. Only the leader node answers ARP/NDP.
Allocation and announcement (L2)
Then traffic :
kubectl applyService type=LoadBalancer
API serverSends a watch event.
controllerPicks a free IP from the pool, sets status.
speaker (leader)Answers ARP/NDP for the IP.
One leader per IP, chosen via memberlist. If it dies a new one wins, brief gap.
4.BGP Mode
Every node peers with your routers and announces the Service IP. Traffic is spread across nodes (ECMP).
- Needs a BGP-capable router
- Backends : FRR-K8s (default), native, legacy FRR (deprecated)
| Aspect | L2 (ARP/NDP) | BGP |
|---|---|---|
| Needs | Same LAN | BGP router |
| Load balancing | No, one node per IP | Yes (ECMP) |
| Failover | New leader, brief gap | Route withdrawn, BFD speeds it up |
| Setup | Very low | Higher (ASNs, peers) |
| Use | Homelab, small LAN | Datacenter, larger scale |
L2 = failover only, one node takes it all.
BGP = real load spreading across nodes.
BGP = real load spreading across nodes.
In short : Controller allocates an IP from your pool, speaker announces it via L2 (one leader, failover) or BGP (ECMP, needs routers).
1.Config Objects (CRDs)
Before v0.13.0 config was a ConfigMap. Now it is CRDs in metallb-system. Convert old config with quay..
| Kind | apiVersion | Purpose |
|---|---|---|
| IPAddressPool | v1beta1 | IP ranges to allocate |
| L2Advertisement | v1beta1 | Announce via ARP/NDP |
| BGPPeer | v1beta2 | Router to peer with |
| BGPAdvertisement | v1beta1 | Announce via BGP |
| BFDProfile | v1beta1 | BFD timers |
kind: IPAddressPool
metadata: {name: first-pool, namespace: metallb-system}
spec:
addresses: [192.168.10.0/24]
---
kind: L2Advertisement
metadata: {name: example, namespace: metallb-system}
spec:
ipAddressPools: [first-pool]
Pool and advert
- Both use
apiVersion: metallb.io/ v1beta1 - A Service can pick a pool with the annotation
metallb.io/ address-pool - A pool with no advertisement is unreachable
- An L2Advertisement with no
ipAddressPoolsannounces every pool
2.Commands
| Command | Description |
|---|---|
| kubectl apply -f metallb-frr-k8s.yaml | Install, FRR-K8s backend (recommended). metallb-native.yaml is L2 only |
| helm install metallb metallb/metallb -n metallb-system --create-namespace | Install with Helm, after helm repo add |
| kubectl get pods -n metallb-system | Check controller and speaker |
| kubectl get ipaddresspools -n metallb-system | List the pools |
| kubectl logs -n metallb-system ds/speaker | Debug announcements and leader election |
| kubectl describe svc <name> | Events show IP and announcing node |
3.Gotchas
- kube-proxy in IPVS mode needs
ipvs.strictARP: trueor L2 misbehaves (ipvs is deprecated since v1.35) - Install alone does nothing: no pool, no advertisement, no IP
- Pool IPs must be unused on your LAN (outside the DHCP range)
- Port 7946 (TCP/UDP) must be open between nodes for memberlist
- L2 is failover, not load balancing. Legacy FRR mode is deprecated
In short : A pool plus an advertisement is all MetalLB needs. Check pods, pools and speaker logs when an IP stays pending.