Metallb Loadbalancer
MetalLB hooks into your Kubernetes cluster, and provides a network load-balancer implementation. In short, it allows you to create Kubernetes services of type LoadBalancer in clusters that don’t run on a cloud provider, and thus cannot simply hook into paid products to provide load balancers.
This example has been tested on a Ubuntu 1.27 Cluster running on a VMWare ESX host. The IP range 192.168.0.230->192.168.0.240 is available on the local network for use.
Edit Kube Proxy to allow ARP
1kubectl get configmap kube-proxy -n kube-system -o yaml | \ sed -e "s/strictARP: false/strictARP: true/" | \ kubectl apply -f - -n kube-system
Install Metallb via helm
1helm repo add metallb https://metallb.github.io/metallb
2helm install metallb
This will deploy a contoller and a DaemonSet onto all the workers
1(base) (⎈|kubernetes-admin@kubernetes:default)➜ ~ kubectl get po -n metallb
2NAME READY STATUS RESTARTS AGE
3metallb-controller-58c5997556-ldlvj 1/1 Running 0 116m
4metallb-speaker-7xx4p 4/4 Running 0 116m
5metallb-speaker-g4b8l 4/4 Running 0 116m
6metallb-speaker-pqpng 4/4 Running 0 116m
7metallb-speaker-vgmk2 4/4 Running 0 116m
8(base) (⎈|kubernetes-admin@kubernetes:default)➜ ~
Create a file for the Address pool - changing the address range to match your local setup
1
2apiVersion: metallb.io/v1beta1
3kind: IPAddressPool
4metadata:
5 name: first-pool
6 namespace: metallb
7spec:
8 addresses:
9 - 192.168.0.230-192.168.0.240
Apply it
1kubectl apply -f address.yml
Create a file to advertise the address pool
1apiVersion: metallb.io/v1beta1
2kind: L2Advertisement
3metadata:
4 name: example
5 namespace: metallb
and apply it
1kubectl apply -f advertise.yml
Now it can be tested
This will just create a local nginx pod and create a Loadbalancer
1kubectl create deploy nginx --image nginx:latest
2
3kubectl expose deploy nginx --port 80 --type LoadBalancer
The Load balancer Ip can then be found
1(base) (⎈|kubernetes-admin@kubernetes:default)➜ kubectl get svc
2NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
3kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 80d
4nginx LoadBalancer 10.107.115.48 192.168.0.230 80:30282/TCP 4s