What is MetalLB?
MetalLB is a network load balancer implementation for Kubernetes clusters that don’t run on supported cloud providers. It provides:- LoadBalancer service type support for bare metal clusters
- Automatic IP address assignment from configured pools
- Layer 2 (ARP/NDP) mode for simple network integration
- BGP mode for advanced routing scenarios
- Multiple IP address pools for different services or tenants
- Cloud-provider parity bringing the LoadBalancer experience to on-premises clusters
Prerequisites
Before installing MetalLB, you need to:- Have a running Talos Kubernetes cluster (see the deployment guide)
- Have
kubectlconfigured to access your cluster - Have
helminstalled on your local machine - Know your available IP address range for load balancer services
- You need a range of IP addresses on your local network that are not used by DHCP
- These IPs must be in the same subnet as your cluster nodes
Configure Namespace Security
MetalLB requires privileged access to manage network interfaces and announce IP addresses at the system level. We need to configure the namespace with appropriate Pod Security Standards. What are Pod Security Standards? Kubernetes Pod Security Standards define three policies:- Privileged: Unrestricted policy (required for system-level operations)
- Baseline: Minimally restrictive policy
- Restricted: Heavily restricted policy (most secure)
- Manipulates network interfaces and ARP/NDP tables
- Manages BGP sessions with network routers
- Performs low-level networking operations
- Interacts directly with the kernel networking stack
- enforce=privileged: Pods violating this policy will be rejected
- audit=privileged: Policy violations are logged to the audit log
- warn=privileged: Users receive warnings for policy violations
- version=latest: Use the latest version of the policy standard
Add MetalLB Helm Repository
MetalLB is distributed via Helm charts, which are packages for Kubernetes applications.Install MetalLB
Now we’ll install MetalLB. The installation happens in two phases: first the controller and speaker components, then the configuration. Install MetalLB:MetalLB Controller
- Watches for Service objects with
type: LoadBalancer - Assigns IP addresses from configured pools
- Manages the overall state of load balancer assignments
- Runs as a Deployment (single instance with leader election)
MetalLB Speaker
- Announces assigned IP addresses to the network
- Runs as a DaemonSet (one pod per node)
- Handles Layer 2 (ARP/NDP) or BGP announcements
- Responds to ARP requests for assigned IPs
- Create CustomResourceDefinitions (CRDs) for MetalLB objects
- Deploy the MetalLB controller
- Deploy the MetalLB speaker DaemonSet on each node
- Set up RBAC permissions
- Create webhook configurations
Configure MetalLB
MetalLB requires configuration to know which IP addresses to use. This is done through two custom resources: IPAddressPool and L2Advertisement. Create a configuration filemetallb-config.yaml:
IPAddressPool
- Defines a pool of IP addresses MetalLB can assign
- addresses: List of IP ranges or CIDR blocks
- Example range:
192.168.1.240-192.168.1.250(11 IPs) - Example CIDR:
192.168.1.240/28(16 IPs)
- Example range:
- You can create multiple pools for different purposes
- Replace the example IPs with your actual available range
L2Advertisement
- Tells MetalLB to advertise IPs using Layer 2 protocols (ARP/NDP)
- ipAddressPools: Which IP pools to advertise via Layer 2
- Layer 2 mode is simpler but all traffic goes through one node
- For production, consider BGP mode for better load distribution
- Choose IPs in the same subnet as your nodes
- Ensure they’re outside your DHCP range
- Reserve enough IPs for your expected services
- Common practice: Use the high end of your subnet (e.g., .240-.250)
Verify Installation
Check pod status:Running):
How to Use MetalLB
Now you can create LoadBalancer services in your cluster:- Assign an IP from your configured pool
- Announce that IP via Layer 2 (ARP/NDP)
- Route traffic to your service’s pods
- Update the service with the
EXTERNAL-IP