Minikube - Enable MetalLB Addon
MetalLB is a network plugin used to support LoadBalancer type services in Kubernetes environments running on bare metal (physical servers).
Minikube offers many addons, and this is one of my favorites. It’s a very useful tool for accessing my LoadBalancer services.
To list all the addons available in Minikube, you can use the minikube addons list
command. By default, these addons come disabled. Let’s enable the MetalLB addon.
1
minikube addons enable metallb
Once enabled, MetalLB will be installed in the metallb-system
namespace.
After enabling MetalLB, the next step is to configure it. Earlier, we used minikube ip to get the IP address of the Minikube VM — make sure to note this down. When we define a LoadBalancer service, MetalLB will need to assign an IP address, so we’ll need to specify a range of IPs for it to use.
1
2
3
4
minikube addons configure metallb
-- Enter Load Balancer Start IP: 192.168.49.100
-- Enter Load Balancer End IP: 192.168.49.120
Now that we’ve configured MetalLB, you can always check the IP range you specified in the configuration. If you ever want to review or verify the IP range and other settings, you can access the ConfigMap from the metallb-system namespace.
By looking at this output, you can find the IP range you defined earlier, as well as any other related settings that MetalLB is using. It’s a great way to verify or adjust your IP range if needed or troubleshoot any issues with your LoadBalancer services.
1
2
3
4
5
6
7
8
9
10
11
12
kind: ConfigMap
apiVersion: v1
metadata:
name: config
namespace: metallb-system
data:
config: |
address-pools:
- name: default
protocol: layer2
addresses:
- 192.168.49.100-192.168.49.120
Let’s now test this with a simple example application.
First, create a deployment for Nginx and expose it as a LoadBalancer service using the following commands:
1
2
3
kubectl create deployment nginx --image=nginx:alpine
kubectl expose deployment nginx --port=80 --type=LoadBalancer --name=nginx-lb
kubectl get svc nginx-lb
After that, check the IP address assigned to the nginx-lb
service. This will show the external IP MetalLB assigned to your service. Once you have the IP, test it by making a request to port 80 using curl, and you should see the Nginx welcome page.