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
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:Note
You can pass multiple load balancer IP ranges separated by commas.
For example: 192.25.251.12/32, 192.25.251.23/28, 192.251.50-192.25.251.56To verify if the IP range is properly configured using the following steps.
First check the metallb version using below command:
Example:helm list -n kube-system
If the metallb version is 4.4.2 or above use below command to verify the ip-range.
Example:kubectl describe ipaddresspool first-pool -n kube-system
If the metallb version is between 1.0.0 and 4.4.1 use below command to verify the ip-range.
Example:kubectl describe configmap metallb-config -n kube-system
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.
First check the metallb version using below command:
Example:helm list -n kube-system
If the metallb version is 4.4.2 or above then edit the first-pool ipaddresspool.
Example:kubectl edit ipaddresspool first-pool -n kube-system
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:
- 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:- Replace pod names using the following command.
kubectl delete pod metallb-controller-7954c9c84d-x8wct metallb-speaker-467jm -n kube-system
Example:- Verify if the IP range is properly configured using the following command.
kubectl describe configmap metallb-config -n kube-system
Example:IP Range
In addition to the IP ranges shown in the table below, you can add additional IP ranges based on your requirements.
IP Range | Description | Result Value |
---|---|---|
192.25.254.45/32 | This is used to add single metallb IP | 192.25.254.45 |
192.25.254.45/30 | This 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.49 | This is used to add a custom range | 192.25.254.44 - 192.25.254.49 |
Note
If you are using a proxy agent, replace your proxy IP in your command with your squid-proxy service IP.
To get the IP address, use the following command.
kubectl get svc squid-proxy -n {namespace} -o jsonpath={.status.loadBalancer.ingress[0].ip}