Add on: MetalLB

MetalLB Loadbalancer is a network LB implementation that tries to “just work” on bare metal clusters.

When you enable this add on you will be asked for an IP address pool that MetalLB will hand out IPs from:

  1. microk8s enable metallb

Alternatively you can provide the IP address pool in the enable command:

  1. microk8s enable metallb:10.64.140.43-10.64.140.49

Multiple comma separated ranges (eg microk8s enable as well as CIDR notation metallb:10.64.140.43-10.64.140.49,10.64.141.53-10.64.141.59,10.12.13.0/24) are supported on the latest and 1.19+ tracks.

Note that currently this add on does not work under Multipass on macOS, due to filtering that macOS applies to network traffic.

Setting up a MetalLB/Ingress service

For load balancing in a MicroK8s cluster, MetalLB can make use of Ingress to properly balance across the cluster ( make sure you have also enabled ingress in MicroK8s first, with microk8s enable ingress). To do this, it requires a service. A suitable ingress service is defined here:

  1. apiVersion: v1
  2. kind: Service
  3. metadata:
  4. name: ingress
  5. namespace: ingress
  6. spec:
  7. selector:
  8. name: nginx-ingress-microk8s
  9. type: LoadBalancer
  10. # loadBalancerIP is optional. MetalLB will automatically allocate an IP
  11. # from its pool if not specified. You can also specify one manually.
  12. # loadBalancerIP: x.y.z.a
  13. ports:
  14. - name: http
  15. protocol: TCP
  16. port: 80
  17. targetPort: 80
  18. - name: https
  19. protocol: TCP
  20. port: 443
  21. targetPort: 443

You can save this file as ingress-service.yaml and then apply it with:

  1. microk8s kubectl apply -f ingress-service.yaml

Now there is a load-balancer which listens on an arbitrary IP and directs traffic towards one of the listening ingress controllers.

(Thanks to jonathan gazeley for his contributions to this).

Last updated 7 months ago. Help improve this document in the forum.