Skip to content

MetalLB Configuration

Aleksei Sviridkin edited this page Apr 22, 2025 · 1 revision

MetalLB Configuration

MetalLB is deployed in this Kubernetes cluster to provide network load balancing functionality for bare metal environments.

Overview

MetalLB allows you to create Kubernetes services of type LoadBalancer without requiring a cloud provider. It assigns real IP addresses to LoadBalancer services, making them accessible from your network.

IP Address Pools

The cluster has several IP address pools configured for different purposes:

1. Ingress Pool

File: manifests/metallb/IPAddressPool-ingress.yaml

apiVersion: metallb.io/v1beta1
kind: IPAddressPool
metadata:
  name: ingress-pool
spec:
  addresses:
    - 172.16.100.251/32

This pool assigns a single IP address (172.16.100.251) dedicated to the Traefik ingress controller.

2. Other Specialized Pools

Additional pools are defined for specific services:

  • IPAddressPool-default.yaml: For general services
  • IPAddressPool-mc.yaml: For Minecraft servers
  • IPAddressPool-transmission.yaml: For the Transmission BitTorrent client

L2 Advertisement

MetalLB is configured to use Layer 2 mode for announcing IP addresses:

File: manifests/metallb/L2Advertisement.yaml

apiVersion: metallb.io/v1beta1
kind: L2Advertisement
metadata:
  name: default
spec:
  ipAddressPools:
    - default-pool
    - ingress-pool
    - mc-pool
    - transmission-pool

This configuration advertises all defined IP pools using ARP (for IPv4) or NDP (for IPv6).

Prerequisites

To use MetalLB effectively:

  1. Reserve IP Addresses: Ensure the IPs used in the address pools are excluded from your DHCP server's allocation range
  2. Network Connectivity: Ensure all Kubernetes nodes have layer 2 connectivity to the addresses in the pools
  3. Disable WiFi: WiFi interfaces often don't support the necessary protocols for MetalLB; use wired connections for nodes

How It Works

When a service of type LoadBalancer is created:

  1. Kubernetes asks MetalLB for an external IP for the service
  2. MetalLB assigns an IP from the appropriate address pool
  3. MetalLB announces the IP address to the network
  4. In L2 mode, the node becomes the "owner" of the IP and responds to ARP requests

Usage Example

To create a service that uses MetalLB:

apiVersion: v1
kind: Service
metadata:
  name: example-service
  annotations:
    metallb.universe.tf/address-pool: default-pool  # Optional: specify a pool
spec:
  type: LoadBalancer
  ports:
  - port: 80
    targetPort: 8080
  selector:
    app: example

Troubleshooting

Common issues and solutions:

  1. IP Address Conflicts: Ensure the IP addresses in your pools are not used elsewhere in your network

  2. No Layer 2 Connectivity: Verify network connectivity between nodes and client devices

  3. Check Speaker Pods: Ensure MetalLB speaker pods are running on all nodes

    kubectl get pods -n metallb-system -o wide
  4. Logs: Check logs for errors

    kubectl logs -n metallb-system -l app=metallb

Further Reading

Clone this wiki locally