MetalLB

Modified on Tue, 26 Nov at 12:33 PM

What is MetalLB?

MetalLB is a network load balancer implementation tailored for bare-metal Kubernetes clusters. It bridges the gap between Kubernetes services and standard network protocols, enabling the use of external services without specialized hardware.

Key Features:

  • Compatible with bare-metal clusters
  • Supports both Layer 2 (ARP/NDP) and Layer 3 (BGP) networking
  • Works with standard routers and switches

Note: 

If you're using Azure VMs and vNets, Azure Load Balancers are required, so MetalLB isn't necessary/recomended. Stick to servicelb, but be aware of potential port collisions."


Installing or Upgrading MetalLB

Step 1: Disable Default servicelb (On Node machines)

Ensure the default k3s servicelb is disabled. If this wasn't done during cluster creation, disable it on each node manually:

  1. Edit the k3s systemd service:

    sudo nano /etc/systemd/system/k3s.service
  2. Add the flag --disable=servicelb to the ExecStart line:

    ExecStart=/usr/local/bin/k3s server --disable=servicelb
  3. Reload and restart the k3s service:

    sudo systemctl daemon-reload sudo systemctl restart k3s


Step 2: Prepare configuration files (On user machine)

Download the files metallb.values.yml and metallb.basics.yml (attached to this article).

metallb.values.yml contains configuration values to start MetalLB. It is already filled with the values recommended by Collab.

metallb.basics.yml contains configurations to controll the IP Range that MetalLB should manage.

Open a CommandLine or PowerShell in the folder containing metallb.values.yml and metallb.basics.yml.



Step 3: Install MetalLB

  1. Add the MetalLB Helm repository:

    helm repo add metallb https://metallb.github.io/metallb
    helm upgrade --install metallb metallb/metallb \  -n metallb --create-namespace --version 0.14.5 -f metallb.values.yml
    helm repo update
  2. Install or upgrade MetalLB:

    helm upgrade --install metallb metallb/metallb \  -n metallb --create-namespace --version 0.14.5 -f metallb.values.yml


Step 4: Configure IP Address Range

  1. Open the metallb.basics.yml file and edit the IP address range under spec > addresses. MetalLB supports CIDR notation or a specific range (e.g., 10.23.0.100-10.23.0.200).

  2. Apply the configuration to your cluster:

    kubectl -n metallb apply -f metallb.basics.yml


Usage

Provisioning IPs for LoadBalancer Services

With MetalLB installed and configured, any Kubernetes service of type LoadBalancer will automatically be assigned an external IP address from the configured range. For manual IP assignment, use the LoadBalancerIP field in your service manifest.


Key Notes

  1. IP Address Management:
    MetalLB provisions IPs based on the range specified in your configuration. It can also accept manual IP assignments.

  2. Azure-specific Considerations:
    For Azure VMs, MetalLB may be unnecessary due to the mandatory use of Azure Load Balancers. Stick to servicelb in such scenarios, and carefully manage port assignments to avoid collisions.

  3. CIDR or Range Support:
    MetalLB supports both CIDR notation and specific ranges for IP addresses.


Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons

Feedback sent

We appreciate your effort and will try to fix the article