Overview

Setting up MetalLB IP range involves configuring the IP address range that the MetalLB load balancer will use to assign external IP addresses to services running in a Kubernetes cluster. This allows you to expose applications externally using load balancers within the defined IP range. It’s an essential step for managing the allocation of external IPs to services and ensuring connectivity from outside the cluster to your applications.

Setup the MetalLB IP Range

You can setup the MetalLB IP range using either one of the following methods:

  • Using “opsramp-collector-start” setup command
  • Edit the metallb-ip range manually after installing the metallb

Method 1: Using “opsramp-collector-start” setup command

  1. To pass the Loadbalancer IP Range during the K3s installation, run the following command.

    opsramp-collector-start setup init --enable-ha --loadbalancer-ip 192.25.45.45-192.25.45.48
    Example:
    bootstrap

  2. To verify if the IP range is properly configured using the following steps.

    • First check the metallb version using below command:

         helm list -n kube-system
         
      Example:
      bootstrap

    • If the metallb version is 4.4.2 or above use below command to verify the ip-range.

         kubectl describe ipaddresspool first-pool -n kube-system
         
      Example:
      bootstrap

    • If the metallb version is between 1.0.0 and 4.4.1 use below command to verify the ip-range.

         kubectl describe configmap metallb-config -n kube-system
         
      Example:
      bootstrap

Method 2: Edit the metallb-ip range manually after installing the metallb

If the user has already installed metallb, they need to manually change the metallb-config configmap and update the Loadbalancer IP range.

  1. First check the metallb version using below command:

       helm list -n kube-system
       
    Example:
    bootstrap

  2. If the metallb version is 4.4.2 or above then edit the first-pool ipaddresspool.

    kubectl edit ipaddresspool first-pool -n kube-system
    Example:
    bootstrap

  3. If the metallb version is between 1.0.0 and 4.4.1 then Edit the metallb-config configmap.
    If the user already installed metallb then they should edit metallb-config configmap manually and update the Loadbalancer IP range.

kubectl edit configmap metallb-config -n kube-system

Example:

bootstrap

  1. To reflect your changes to the metallb, restart the metallb-controller and metallb-speaker pods using the following command.

kubectl get pods -n kube-system | grep metallb
Example:
bootstrap

  1. Replace pod names using the following command.

kubectl delete pod metallb-controller-7954c9c84d-x8wct metallb-speaker-467jm -n kube-system
Example:
bootstrap

  1. Verify if the IP range is properly configured using the following command.

kubectl describe configmap metallb-config -n kube-system
Example:
bootstrap

IP Range

In addition to the IP ranges shown in the table below, you can add additional IP ranges based on your requirements.

IP RangeDescriptionResult Value
192.25.254.45/32This is used to add single metallb IP
192.25.254.45
192.25.254.45/30This is used to add 4 IPs from a given IP
192.25.254.44 - 192.25.254.47
192.25.254.44 - 192.25.254.49This is used to add a custom range
192.25.254.44 - 192.25.254.49