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.

circle-info

The Expose LB feature is enabled only if the MetalLB add-on was enabled during cluster creation.

Configure MetalLB load balancing

  1. Navigate to Infrastructure > Clusters.

  2. Select the cluster you want to configure.

  3. Select Expose LB.

  4. 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:

    1. The serviceCIDR (10.96.0.0./16)

    2. The podCIDR (10.244.0.0/16)

    3. The worker node IPs in your environment

The following examples show valid IP address formats:

Single IP address:

CIDR range:

circle-exclamation
  1. In the Inbound Port Details section, define the ports and protocols that external services can use to communicate with your cluster.

    Field
    Description
    Example

    Name

    Identifier for the port rule. Must start with a lowercase letter and contain only lowercase letters, numbers, and hyphens.

    custom-load-balancer

    Port

    Port number or range for external traffic.

    80 or 3000-3500

    Protocol

    Network protocol. Select TCP or UDP.

    TCP

    IP Address or CIDR

    Source IP address or subnet allowed to send traffic through this port.

    10.10.0.7 or 10.10.0.0/9

  2. Select 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?