MetalLB: Load Balancer for Bare Metal Kubernetes

What is MetalLB?

MetalLB is a load balancer solution for Kubernetes clusters running on bare metal. It provides network load balancing functionality where cloud provider solutions like AWS ELB or GCP LB are unavailable. This document covers its key features and installation steps on Kubernetes clusters.

Key Features of MetalLB

Installing MetalLB on Kubernetes

Step 1: Install MetalLB

Apply the official MetalLB manifests:

kubectl apply -f https://raw.githubusercontent.com/metallb/metallb/main/config/manifests/metallb-native.yaml

Step 2: Configure MetalLB

Create a ConfigMap defining the address pool:

apiVersion: v1
kind: ConfigMap
metadata:
  namespace: metallb-system
  name: config
data:
  config: |
    address-pools:
    - name: default-pool
      protocol: layer2
      addresses:
      - 192.168.1.100-192.168.1.200

Step 3: Verify Installation

kubectl get pods -n metallb-system

Exposing a Service with MetalLB

Step 1: Create a LoadBalancer Service

apiVersion: v1
kind: Service
metadata:
  name: my-service
spec:
  selector:
    app: my-app
  ports:
  - protocol: TCP
    port: 80
    targetPort: 80
  type: LoadBalancer

Step 2: Check the Assigned External IP

kubectl get svc my-service

The external IP should be assigned from the configured range.

Conclusion

MetalLB enables Kubernetes clusters running on bare metal to leverage external load balancing without cloud provider dependencies. By following these steps, you can set up MetalLB to handle Kubernetes LoadBalancer services efficiently.