Kubernetes LoadBalancer

Shardul | Apr 25, 2025 min read

To install MetalLB, a load-balancer implementation for bare-metal Kubernetes clusters, follow these steps:

Prerequisites:

  • A running Kubernetes cluster (v1.30+)
  • kubectl access to the cluster
  • A Layer 2 network or BGP setup (depending on the MetalLB mode)

Install MetalLB Components

You can install the official manifests directly from the MetalLB project:

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

Replace the version (v0.13.12) with the latest from: https://github.com/metallb/metallb/releases

Create a Secret for Memberlist (Layer 2 Mode Only)

This is required for MetalLB to function in Layer 2 mode:

kubectl create secret generic -n metallb-system memberlist \
  --from-literal=secretkey="$(openssl rand -base64 128)"

Configure MetalLB

Layer 2 Mode (most common) : Create a ConfigMap with an address pool in your subnet:

# metallb-config.yaml
apiVersion: metallb.io/v1beta1
kind: IPAddressPool
metadata:
  name: my-ip-pool
  namespace: metallb-system
spec:
  addresses:
  - 192.168.1.240-192.168.1.250  # Change to match your network
---
apiVersion: metallb.io/v1beta1
kind: L2Advertisement
metadata:
  name: l2-advertisement
  namespace: metallb-system

Apply it:

kubectl apply -f metallb-config.yaml

Verify Installation

Check that MetalLB components are running:

kubectl get pods -n metallb-system

Then try deploying a LoadBalancer-type service and see if it gets an IP from your MetalLB pool.