Skip to content
lorebow

Introduction to MetalLB

What MetalLB is, why a bare-metal Kubernetes cluster needs it, and the two ways it makes a Service's address reachable.

KFounder and editor Written for MetalLB v0.16.2 1,032 words 5 min read Find it on the map

MetalLB gives LoadBalancer Services a real IP address on clusters that don't run on a cloud. You give it a range of addresses you own. When a Service asks for a load balancer, MetalLB picks an address from that range and tells your network where to send traffic for it, using three protocols your network already speaks:

Stands forIn one line
ARPAddress Resolution ProtocolAn IPv4 machine asks "who has this IP?" and learns which network card to send to
NDPNeighbor Discovery ProtocolThe same question and answer, for IPv6
BGPBorder Gateway ProtocolRouters tell each other which addresses they can reach, and through whom

#Why a bare-metal cluster needs it

A Service of type: LoadBalancer asks for an address that clients outside the cluster can reach. Kubernetes doesn't create one itself. It waits for a controller to do it, and the only ones it ships with call a cloud provider's APIApplication Programming Interface: the requests one program accepts from others, like the Kubernetes API or a cloud provider’s API.: AWSAmazon Web Services, Amazon’s cloud., Azure, Google Cloud and the rest. On your own servers nothing answers, so the Service stays <pending> for good.

Each tab in the figure is one scenario:

TabWhat it shows
On a cloudWhat Kubernetes was built for. The cloud controller asks the provider for a load balancer and writes its public address onto the Service.
Bare metalThe same Service on your own servers. Nothing answers, so EXTERNAL-IP stays <pending> and clients have nothing to connect to.
With MetalLBMetalLB gives the Service an address from its pool and answers for it on node-1. Traffic goes straight to the node, then on to a pod.

Without MetalLB you're left with two weaker options:

OptionWhat you getWhy it falls short
NodePortA port from 30000–32767 opened on every nodeClients need a node's address and an odd port; if that node goes down, they have to switch to another one by hand
externalIPsKubernetes accepts traffic for addresses you listNothing makes the network send those addresses to a node; you route them yourself, and nothing moves them when a node fails
LoadBalancer with MetalLBOne stable address per Service, on a normal portMetalLB hands it out, announces it, and moves it when a node fails

#What MetalLB does

1. Hands out an address

You give MetalLB pools of addresses. Each LoadBalancer Service gets one, and gives it back when it's deleted. If the pools run out, Services wait.

2. Announces it

An address is no use until the network knows which machine has it. MetalLB answers ARP or NDP for it, or advertises it to your routers over BGP.

How MetalLB works follows one Service from kubectl apply to its first reply.

#Two ways to announce an address

Each tab in the figure is one scenario:

TabWhat it shows
Layer 2One node answers "who has 192.168.1.240?" and gets all the traffic. When it dies, another node takes over and tells the network with a gratuitous ARP, an announcement nobody asked for.
BGPEvery node tells the router "send 192.168.1.240 to me". The router spreads connections across all three, and stops using a node when its route disappears.
Layer 2 modeBGP mode
HowOne node answers ARP or NDP for the addressEvery node advertises a route to your routers
You needAny Ethernet network, nothing specialRouters that speak BGP, and that you control
TrafficAll of it enters through one nodeSpread across nodes, one connection at a time
When a node failsAnother node takes the address over in a few secondsIts route is withdrawn; connections that were going to it reset
Main limitOne node's bandwidthConnections reset whenever the set of nodes changes

Most home labs and small clusters start with layer 2. BGP is for data centres where you already run BGP and want the load spread with ECMPEqual-cost multi-path: a router keeps several equally good routes to one address and spreads connections across them..

#What you need

  • A Kubernetes cluster that doesn't already have a network load balancer. k3s's built-in one (ServiceLB) has to be turned off, for example.
  • A network plugin that works with MetalLB. Most do; Calico and kube-router need care in BGP mode.
  • Some IPv4 or IPv6 addresses for MetalLB to hand out, that nothing else on the network uses.
  • For layer 2: TCPTransmission Control Protocol: the reliable, connection-based way most traffic travels, such as web requests. and UDPUser Datagram Protocol: a lighter way to send single packets, without a connection. port 7946 open between nodes. The speakers use it to notice when a node goes away, with memberlistA library that keeps a list of live members by gossiping between them, so a dead node is noticed in seconds..
  • For BGP: one or more routers that speak BGP.

#How mature it is

MetalLB calls itself beta, mostly because of its configuration format, and has been run in production by many companies for years. What that means in practice:

  • Configuration changes are announced first. When a field changes, one release understands both the old and the new form, so you can update your objects before upgrading again. The release notes say what to change.
  • Kubernetes versions: the maintainers keep MetalLB working with the Kubernetes versions that are still supported; older ones get best effort.
  • A small team. MetalLB was started by one person, then handed to a small group of volunteer maintainers. There is no company behind it, so bug reports and fixes from users matter.

#In the source

MetalLB lives at github.com/metallb/metallb. The pieces these docs link to:

Two more repositories: metallb/frr-k8s, the BGP backend MetalLB uses by default, and metallb/metallb-operator, an OperatorA program in the cluster that installs and manages an app from a custom object, here a MetalLB object. that installs and upgrades MetalLB.