Out of the box, the MicroK8s distribution of ingress-nginx installed as the MicroK8s addon
ingress binds to ports 80+443 on the node’s IP address using a
hostPort, as we can see here on line 20:
microk8s kubectl -n ingress describe daemonset.apps/nginx-ingress-microk8s-controller Name: nginx-ingress-microk8s-controller Selector: name=nginx-ingress-microk8s Node-Selector: Labels: microk8s-application=nginx-ingress-microk8s Annotations: deprecated.daemonset.template.generation: 1 Desired Number of Nodes Scheduled: 4 Current Number of Nodes Scheduled: 4 Number of Nodes Scheduled with Up-to-date Pods: 4 Number of Nodes Scheduled with Available Pods: 4 Number of Nodes Misscheduled: 0 Pods Status: 4 Running / 0 Waiting / 0 Succeeded / 0 Failed Pod Template: Labels: name=nginx-ingress-microk8s Service Account: nginx-ingress-microk8s-serviceaccount Containers: nginx-ingress-microk8s: Image: quay.io/kubernetes-ingress-controller/nginx-ingress-controller-amd64:0.25.1 Ports: 80/TCP, 443/TCP Host Ports: 80/TCP, 443/TCP Args: /nginx-ingress-controller --configmap=$(POD_NAMESPACE)/nginx-load-balancer-microk8s-conf --publish-status-address=127.0.0.1 Liveness: http-get http://:10254/healthz delay=30s timeout=5s period=10s #success=1 #failure=3 Environment: POD_NAME: (v1:metadata.name) POD_NAMESPACE: (v1:metadata.namespace) Mounts: Volumes: Events:
This is fine for a single-node deployment, but now MicroK8s supports clustering we need to find a way of load-balancing our Ingress, as a multi-node cluster will have one Ingress controller per node, each bound to its own node’s IP.
Enter MetalLB, a software load-balancer which works well in layer 2 mode, which is also available as a MicroK8s addon
metallb. We can use MetalLB to load-balance between the ingress controllers.
There’s one snag though, MetalLB requires a Service resource, and the MicroK8s distribution of Ingress does not include one.
microk8s kubectl -n ingress get svc No resources found in ingress namespace.
This gist contains the definition for a Service which should work with default deployments of the MicroK8s addons Ingress and MetalLB. It assumes that both of these addons are already enabled.
microk8s enable ingress metallb
Download this manifest
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
Apply it to your cluster 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. In this case, MetalLB has picked
192.168.0.61 as the load-balanced IP so I can route my traffic here.
microk8s kubectl -n ingress get svc NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE ingress LoadBalancer 10.152.183.141 192.168.0.61 80:30029/TCP,443:30276/TCP 24h
This content is also available as a Github gist.
2 thoughts on “Load-balancing Ingress with MetalLB on MicroK8s”
Troubleshooting ingress and metallb.
My load balancer cannot find my web app nginx
instead I end up on the ingress service nginx
is more information about metallb and ingress available?
External IP never leaves pending state 😦
ubuntu@m8s7:~$ microk8s kubectl -n ingress get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
ingress LoadBalancer 10.152.183.31 80:30080/TCP,443:31580/TCP 95s