One of the benefits I planned to get by switching from standalone laptop to Kubernetes cluster was to get multiple services behind a single IP address. This is not a benefit of a Kubernetes per se, as you could different techniques to accomplish that, but Kubernetes gave me a valid reason to start using load balancers.
A minor problem with Kubernetes is that there are not too many load balancers for bare metal clusters. I guess the typical situation is that you are running k8s inside some cloud service, which offers you their load balancing solutions. Without the load balancer you can’t expose your services outside the cluster, unless you use NodePort or externalIP, which have their own limitations.
After a brief study about different load balancers, I decided to use MetalLB. The only caveat I could find was that it is a young project and it should be considered as beta product, as they state in their site.
Installing MetalLB was a delightful experience compared to many other components forming my cluster. As per their installation document, installation by manifest files requires just a couple of commands:
kubectl apply -f https://raw.githubusercontent.com/metallb/metallb/v0.9.6/manifests/namespace.yaml kubectl apply -f https://raw.githubusercontent.com/metallb/metallb/v0.9.6/manifests/metallb.yaml # On first install only kubectl create secret generic -n metallb-system memberlist --from-literal=secretkey="$(openssl rand -base64 128)"
I chose to download the two files beforehand and modify metallb.yaml to better suite my network. Besides that, there is not much to be done.
To use MetalLB, the service can be exposed by creating it with spec.type set to LoadBalancer. MetalLB will then give it an IP address from its address pool and you can use it to connect to service from outside the cluster.