MetalLB in L2
Kubernetes architecture requires a LoadBalancer.
MetalLB can be deployed as a LoadBalancer in L2 mode, which is good for bare metal homelab style environments.
Example Deployment
deployment/controller 1 replica
daemonset/speaker 7 pods
Theory
Controller
- Watches for
LoadBalancerrequest - Picks a free IP out of the pool
- Assigns it to the Service as its EXTERNAL-IP
Speaker
- bound to
hostNetwork - Runs stateless hash
- First on the list advertise the MetalLB IPs
L2 Operation
Is the service running?
kubectl get l2advertisements -n metallb-system
What services are consuming an IP?
kubectl get svc -A --field-selector spec.type=LoadBalancer
How the L2 leader election works
- Stateless
- Creates a list of all speakers could announce the IP.
- Sorts the list with a specific hash.
- First speaker on the list announces the IP (responds to ARP).