Let us today see how we can deploy MetalLB in a Kubernetes cluster using helm.
Introduction
In short MetalLB is a Load Balancer for Kubernetes clusters.
In a multi node Kubernetes cluster we will require a Load Balancer so access the applications and the dashboards running on that cluster. To achieve that we either have an option of external physical load balancer or OS load balancer like HA-Proxy. However sometimes it becomes difficult to get access to physical load balancers and spare additional resource for setting up OS level LB like HA Proxy. That is when we can use MetalLB which can run as an application on a Kubernetes cluster and serve the LB purpose very well.
Installation
Add Helm Repository:
#helm repo add metallb/metallb https://metallb.github.io/metallb
Refresh the repository:
#helm repo update
Install MetalLB:
#helm install metallb metallb/metallb --namespace metallb-system --create-namespace
Configuration
Create a working directory and Navigate into it
#mkdir /metallb && cd /metallb
Create the IP Pool File
#cat <<'EOF' >> ipaddresspool.yaml
apiVersion: metallb.io/v1beta1
kind: IPAddressPool
metadata:
name: add-pool
namespace: metallb-system
spec:
addresses: ["192.168.1.201-192.168.1.220"]
EOF
Please Note that the IP pool is of the same segment as the node IP Pool.
Next create the l2 advertising file
#cat <<'EOF >> l2adv.yaml
apiVersion: metallb.io/v1beta1
kind: L2Advertisement
metadata:
name: l2adv
namespace: metallb-system
EOF
Apply both the files just created within Kubernetes using the kubectl commands
#kubectl apply -f ipaddresspool.yaml
#kubectl apply -f l2adv.yaml
Check whether the metalLB pods are running
#kubectl get pods -n metallb-system

Post setting this up all you have to do is spin up new application with the service type of Load Balancer and metallb system will assign an IP from the pool you have mentioned to that service and you can access the application via that IP.
Conclusion
We saw how we can leverage metallb for load balancer implementation for our multi node Kubernetes cluster.
1 thought on “Kubernetes: MetalLB”