Metal LB with Nginx Ingress Controller on Bare Metal Kubernetes

Exposing your services in a manged Kubernetes service such as EKS, AKS or GKE is much simpler as once you deploy a Kubernetes service with a type load balancer, it would deploy the relative cloud native load balancer for you.

When it comes to Kubernetes clusters which are deployed on bare metal, this option is not available. If you need to expose your services and nodePort is not an option, you could use Metal LB to expose your services. Metal LB would deploy a virtual load balancer which would allow you to expose your services.

First you would need to deploy the Metal LB control plane in your cluster.

kubectl apply -f
kubectl apply -f

The following Metal LB configmap would need to be deployed in order to configure the IP addresses used for Metal LB.

apiVersion: v1
kind: ConfigMap
  namespace: metallb-system
  name: config
  config: |
    - name: default
      protocol: layer2

Please note that the addresses should be within the sub net of your Kubernetes cluster.

Deploy Nginx ingress controller using helm.

helm install ingress-nginx ingress-nginx \    
--repo \
--namespace ingress-nginx --create-namespace

The IP address would be allocated to the Nginx load balancer service.

kubectl get svc -n ingress-nginx

NAME                                 TYPE           CLUSTER-IP      EXTERNAL-IP   PORT(S)                      AGE
ingress-nginx-controller             LoadBalancer   80:31480/TCP,443:30573/TCP   60s
ingress-nginx-controller-admission   ClusterIP     <none>        443/TCP                      60s

The main configurations regarding Metal LB and the Nginx Ingress Controller are now done. You could use an ingress with a sample service and deploy to test the above scenario.