Set up Load balancers using MetalLB
Overview
MetalLB provides load balancing for Kubernetes clusters running on bare metal or private cloud infrastructure. By default, load balancer services are not reachable from outside the cluster because egress packets are dropped by security groups. Without the Expose LB feature, you would need to manually allow traffic from the external IP pool specified in the MetalLB address pool, or create a custom security group with the required ingress ports open.
The Expose LB feature simplifies this by letting you configure allowed addresses and inbound ports in one place, eliminating the need to edit security groups on individual worker nodes.
Prerequisites
MetalLB add-on is enabled during cluster creation.
The Expose LB feature is enabled only if the MetalLB add-on was enabled during cluster creation.
Configure MetalLB load balancing
Navigate to Infrastructure > Clusters.
Select the cluster you want to configure.
Select Expose LB.
In the Allowed Addresses field, specify the IP addresses or CIDR ranges that MetalLB can assign to load balancer services. Enter either a specific IP address or a CIDR range from your MetalLB address pool. You should ensure that the IP addresses or CIDR range does not conflict with:
The
serviceCIDR(10.96.0.0./16)The
podCIDR(10.244.0.0/16)The worker node IPs in your environment
The following examples show valid IP address formats:
Single IP address:
CIDR range:
Modifying the Allowed Addresses field triggers a restart of existing worker nodes.
In the Inbound Port Details section, define the ports and protocols that external services can use to communicate with your cluster.
FieldDescriptionExampleName
Identifier for the port rule. Must start with a lowercase letter and contain only lowercase letters, numbers, and hyphens.
custom-load-balancerPort
Port number or range for external traffic.
80or3000-3500Protocol
Network protocol. Select TCP or UDP.
TCPIP Address or CIDR
Source IP address or subnet allowed to send traffic through this port.
10.10.0.7or10.10.0.0/9Select Submit.
Set up MetalLB with L2 mode
In your Kubernetes cluster, create a corresponding IPAddressPool and L2Advertisement resource. For example:
Verify load balancer service works
Create an nginx deployment and expose it via a loadbalancer service:
Get the service IP:
Use curl to get the default nginx page:
Last updated
Was this helpful?
