Jump to main content

Addon: MetalLB

1.17
Compatibility: amd64 arm64 power s390 strict classic
Source: MetalLB

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

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:

microk8s enable metallb

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

microk8s enable metallb:10.64.140.43-10.64.140.49

Multiple comma-separated ranges 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 from 1.19.

Configure IPAddressPool resources (from 1.25+)

It is possible to configure IP address pools that MetalLB will use to allocate IP addresses using custom resources.

For example, create the following custom address pool:

# addresspool.yaml
---
apiVersion: metallb.io/v1beta1
kind: IPAddressPool
metadata:
  name: custom-addresspool
  namespace: metallb-system
spec: 
  addresses:
  - 192.168.1.1-192.168.1.100

And apply it with:

microk8s kubectl apply -f addresspool.yaml

You can then configure which address pool MetalLB will use for each LoadBalancer service by setting the metallb.universe.tf/address-pool annotation:

apiVersion: v1
kind: Service
metadata:
  name: test-service
  annotations:
    metallb.universe.tf/address-pool: custom-addresspool
spec:
  selector:
    name: nginx
  type: LoadBalancer
  # loadBalancerIP is optional. MetalLB will automatically allocate an IP 
  # from its pool if not specified. You can also specify one manually.
  # loadBalancerIP: x.y.z.a
  ports:
    - protocol: TCP
      port: 80
      targetPort: 80

Setting up a MetalLB/Ingress service

For load balancing in a MicroK8s cluster, MetalLB can make use of Ingress. Make sure you have enabled ingress, with microk8s enable ingress and create a suitable ingress service, for example:

apiVersion: v1
kind: Service
metadata:
  name: ingress
  namespace: ingress
spec:
  selector:
    name: nginx-ingress-microk8s
  type: LoadBalancer
  # loadBalancerIP is optional. MetalLB will automatically allocate an IP 
  # from its pool if not specified. You can also specify one manually.
  # loadBalancerIP: x.y.z.a
  ports:
    - name: http
      protocol: TCP
      port: 80
      targetPort: 80
    - name: https
      protocol: TCP
      port: 443
      targetPort: 443

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

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.

Advertise LoadBalancer IPs

By default, MicroK8s advertises all LoadBalancer IPs by responding to ARP requests on the local network. For more complex setups, like limiting the address pools for which ARP responses are sent, or for more complex BGP configurations, refer to the MetalLB documentation

Last updated 1 year, 9 months ago. Help improve this document in the forum.