MetalLB on Loopback

Want to give MetalLB a try with your Minikube but don't have control over your L2 network? Don't have enough free IP addresses? You can actually create a loopback adapter on your local host with a non-routable subnet and use that to allocate your L2 IP addresses.

As in my previous post, I'm setting up Minikube using the none driver so MetalLB has direct access to the host system's networking.

First, you'll want to create a new loopback adapter on the subnet of your choice. This is my work machine and the 192.168.1.0/24 network is unused so I'll use that:

ifconfig lo:0 192.168.1.1 netmask 255.255.255.0 up

I now have a new lo:0 adapter on my system that's running on 192.168.1.1/24. I can now use that subnet in my metallb ConfigMap:

root@jason-c30:~# cat metallb-config.yaml 
apiVersion: v1
kind: ConfigMap
metadata:
  namespace: metallb-system
  name: config
data:
  config: |
    address-pools:
    - name: my-ip-space
      protocol: layer2
      addresses:
      - 192.168.1.128/25

root@jason-c30:~# kubectl apply -f metallb-config.yaml 
configmap/config created

VoilĂ ! I now have my load balancer allocating IP addresses on the upper half of my /24. Edit the kubernetes-dashboard service and make it a LoadBalancer instead of ClusterIP:

root@jason-c30:~# kubectl edit service kubernetes-dashboard -n kube-system
service/kubernetes-dashboard edited

Wait a second and check the service. You'll see it now has an EXTERNAL-IP address on your new subnet:

root@jason-c30:~# kubectl get service -n kube-system kubernetes-dashboard
NAME                   TYPE           CLUSTER-IP    EXTERNAL-IP     PORT(S)        AGE
kubernetes-dashboard   LoadBalancer   10.104.6.92   192.168.1.128   80:30287/TCP   21h

Open a web browser on your local host and you'll now see the dashboard! Since this is address is on a loopback adapter, you must use your local host for all activities since there will be no routing for your new subnet, but it does provide a local environment for development and testing with MetalLB.


Comments

Popular posts from this blog

Minikube + MetalLB