Skip to content

Deploying MetalLB in BGP mode peering with a Mikrotik or Cisco router

Full installer for MetalLB v0.14 in BGP mode — speaker config, BGP session setup against Mikrotik RouterOS and Cisco IOS, ECMP advertisement.

L2 mode worked fine for the first month. Then traffic doubled, you started running a thousand requests a second through a single Service IP, and you noticed that all of it lands on one node — because that’s how L2 mode works. The other two nodes are reachable, the kernel forwards through iptables, and your “load-balanced” cluster is in fact bottlenecked behind one NIC. The fix is BGP mode: every speaker tells the upstream router “I have a path to this prefix,” the router installs ECMP routes across all of them, and traffic actually load-balances at the network layer. The hard part isn’t MetalLB. The hard part is getting your network admin (or your past self) to peer BGP with a Kubernetes cluster, with the right ASN, the right hold timers, and a route map that doesn’t accidentally export the LB pool to the rest of the internet.

What’s happening

In BGP mode, each MetalLB speaker opens a BGP session to one or more configured peers (your routers). When a Service of type: LoadBalancer gets an IP from a pool with an BGPAdvertisement, every speaker announces a /32 route for that IP to its peers, with the speaker’s node IP as the next-hop. The router sees multiple equal-cost paths to the same /32 and installs them as ECMP — incoming traffic for that IP is hashed across the node IPs (typically by 5-tuple), and kube-proxy on each node forwards to the actual Pod. The result is real per-flow load balancing, no single-node bottleneck, and fast failover: when a node dies, its BGP session drops, the router removes that path from the ECMP set within seconds, and traffic shifts to the remaining nodes. The pieces you must get right: a private ASN for the cluster (64512–65534 for 16-bit, or 4200000000–4294967294 for 32-bit), a separate ASN on the router side (you can’t peer iBGP with the same ASN unless the router is a route reflector, and that’s a more advanced setup), eBGP multihop is usually NOT needed because speakers peer directly on the same L2, and a prefix-list or route-map on the router that accepts only your LB pool — otherwise a misconfigured cluster could blackhole arbitrary prefixes for your network. Mikrotik RouterOS 7 has a fundamentally different BGP config syntax from RouterOS 6 and from Cisco IOS, so we cover both vendors in the installer.

How to verify

Speakers should establish sessions to the configured peers:

kubectl -n metallb-system get bgppeers
# NAME              ADDRESS       ASN
# router-primary    10.10.0.1     65000

kubectl -n metallb-system logs -l component=speaker --tail=200 | grep -i "BGP session"
# {"caller":"bgp_controller.go","event":"sessionUp","msg":"BGP session established","peer":"10.10.0.1:179"}

On a Mikrotik RouterOS 7 peer:

/routing/bgp/session/print
# Flags: E - established
#  E peer-address=10.10.0.11 remote.as=65100 ...
#  E peer-address=10.10.0.12 remote.as=65100 ...
#  E peer-address=10.10.0.13 remote.as=65100 ...

/ip/route/print where bgp
# 10.10.0.240/32 [200/0] via 10.10.0.11 ECMP
#                       via 10.10.0.12 ECMP
#                       via 10.10.0.13 ECMP

On a Cisco IOS peer:

show bgp ipv4 unicast summary
# Neighbor   V  AS    MsgRcvd  MsgSent ... State/PfxRcd
# 10.10.0.11 4  65100      89       91 ...    1
# 10.10.0.12 4  65100      89       91 ...    1
# 10.10.0.13 4  65100      89       91 ...    1

show ip route 10.10.0.240
# Routing entry for 10.10.0.240/32
#   Known via "bgp 65000", distance 20, metric 0, type external
#   Last update from 10.10.0.13 ... ago
#   Routing Descriptor Blocks:
#   * 10.10.0.11, ...
#     10.10.0.12, ...
#     10.10.0.13, ...

If you see one path instead of three, ECMP isn’t configured on the router — see the IOS / RouterOS notes at the end of the installer.

The fix

The installer below deploys MetalLB v0.14 in BGP mode, peering with a single upstream router. Run it from a workstation with kubectl configured. The router-side config (RouterOS or Cisco) is included as separate snippets to copy onto the router.

#!/usr/bin/env bash
set -euo pipefail

### MetalLB v0.14 BGP-mode installer for k3s/k8s on bare metal
### Cluster ASN peers with one or more upstream routers and advertises a /32 per LB IP.
### After applying, paste the router-side snippet (Mikrotik or Cisco) at the bottom.

if ! command -v kubectl >/dev/null 2>&1; then
  echo "kubectl is required."
  exit 1
fi

# === EDIT FOR YOUR ENVIRONMENT ===
METALLB_VERSION="v0.14.8"
CLUSTER_ASN="65100"                # private ASN used by every speaker
ROUTER_ASN="65000"                 # private ASN of the upstream router
ROUTER_IP="10.10.0.1"              # the router's IP on the cluster L2
POOL_NAME="prod-bgp-pool"
POOL_RANGE="10.10.0.240-10.10.0.250"
BGP_ADV_NAME="prod-bgp-adv"
HOLD_TIME="30s"
KEEPALIVE_TIME="10s"
# =================================

echo
echo "========================================"
echo "MetalLB ${METALLB_VERSION} BGP install"
echo "Cluster ASN ${CLUSTER_ASN}  ->  Router ASN ${ROUTER_ASN} (${ROUTER_IP})"
echo "Pool ${POOL_NAME}: ${POOL_RANGE}"
echo "========================================"
echo

echo "==> Verifying cluster reachable"
kubectl cluster-info >/dev/null

echo "==> Applying MetalLB native manifest"
kubectl apply -f \
  "https://raw.githubusercontent.com/metallb/metallb/${METALLB_VERSION}/config/manifests/metallb-native.yaml"

echo "==> Waiting for controller + speaker rollouts"
kubectl -n metallb-system rollout status deploy/controller --timeout=180s
kubectl -n metallb-system rollout status ds/speaker --timeout=180s

echo "==> Waiting for the CRDs to be Established"
for crd in ipaddresspools.metallb.io bgpadvertisements.metallb.io \
           bgppeers.metallb.io communities.metallb.io \
           bfdprofiles.metallb.io l2advertisements.metallb.io; do
  kubectl wait --for=condition=Established --timeout=60s "crd/${crd}"
done

echo "==> Writing IPAddressPool, BGPPeer, BGPAdvertisement"
cat > /tmp/metallb-bgp.yaml <<EOF
apiVersion: metallb.io/v1beta1
kind: IPAddressPool
metadata:
  name: ${POOL_NAME}
  namespace: metallb-system
spec:
  addresses:
    - ${POOL_RANGE}
  autoAssign: true
  avoidBuggyIPs: true
---
apiVersion: metallb.io/v1beta2
kind: BGPPeer
metadata:
  name: router-primary
  namespace: metallb-system
spec:
  myASN: ${CLUSTER_ASN}
  peerASN: ${ROUTER_ASN}
  peerAddress: ${ROUTER_IP}
  holdTime: ${HOLD_TIME}
  keepaliveTime: ${KEEPALIVE_TIME}
  ebgpMultiHop: false
  # Add password: 'xxx' if your router uses TCP-MD5 (RFC 2385)
---
apiVersion: metallb.io/v1beta1
kind: BGPAdvertisement
metadata:
  name: ${BGP_ADV_NAME}
  namespace: metallb-system
spec:
  ipAddressPools:
    - ${POOL_NAME}
  aggregationLength: 32           # advertise as /32 (host route)
  localPref: 100
EOF

kubectl apply -f /tmp/metallb-bgp.yaml

echo "==> Allowing 10 seconds for sessions to come up"
sleep 10

echo "==> Smoke test"
kubectl create deploy metallb-smoke --image=traefik/whoami --port=80 \
  --dry-run=client -o yaml | kubectl apply -f -
kubectl expose deploy metallb-smoke --type=LoadBalancer --port=80 --target-port=80 \
  --dry-run=client -o yaml | kubectl apply -f -

for i in {1..30}; do
  IP=$(kubectl get svc metallb-smoke -o jsonpath='{.status.loadBalancer.ingress[0].ip}' 2>/dev/null || true)
  if [[ -n "${IP}" ]]; then break; fi
  sleep 2
done

echo
echo "========================================"
echo "DONE"
echo "========================================"
echo
echo "BGP peers (from cluster):"
kubectl -n metallb-system get bgppeers
echo
echo "Speaker session states:"
kubectl -n metallb-system logs -l component=speaker --tail=10 | grep -i session || true
echo
echo "Smoke service IP: ${IP:-<pending>}"
echo
echo "==> Now configure the router with the snippet for your vendor below."

Once MetalLB is applied, paste the matching snippet onto the router.

Mikrotik RouterOS 7.x

# /routing/bgp/connection
/routing/bgp/connection add name=k3s-node1 \
    remote.address=10.10.0.11 remote.as=65100 \
    local.role=ebgp .as=65000 \
    hold-time=30s keepalive-time=10s \
    multihop=no

/routing/bgp/connection add name=k3s-node2 \
    remote.address=10.10.0.12 remote.as=65100 \
    local.role=ebgp .as=65000 \
    hold-time=30s keepalive-time=10s \
    multihop=no

/routing/bgp/connection add name=k3s-node3 \
    remote.address=10.10.0.13 remote.as=65100 \
    local.role=ebgp .as=65000 \
    hold-time=30s keepalive-time=10s \
    multihop=no

# Only accept the LB pool back from the cluster
/routing/filter/rule
add chain=k3s-in rule="if (dst in 10.10.0.240/28) { accept } else { reject }"

# Apply the filter
/routing/bgp/connection
set [find name~"^k3s-"] input.filter=k3s-in

# Enable ECMP across equal-cost BGP routes
/routing/settings set kernel-route-distance=200
# RouterOS 7 enables BGP multipath automatically when multiple equal-cost
# routes exist for the same prefix from different next-hops, but you can
# verify with:
/ip/route/print where bgp ecmp

Cisco IOS XE 17+

router bgp 65000
 bgp log-neighbor-changes
 bgp listen range 10.10.0.0/24 peer-group K3S
 maximum-paths 16

 address-family ipv4 unicast
  maximum-paths 16
 exit-address-family

 neighbor K3S peer-group
 neighbor K3S remote-as 65100
 neighbor K3S timers 10 30
 neighbor K3S prefix-list LB-POOL-IN in
 neighbor 10.10.0.11 peer-group K3S
 neighbor 10.10.0.12 peer-group K3S
 neighbor 10.10.0.13 peer-group K3S

ip prefix-list LB-POOL-IN seq 10 permit 10.10.0.240/28 le 32
ip prefix-list LB-POOL-IN seq 20 deny 0.0.0.0/0 le 32

Operational notes. Use aggregationLength: 32 so each Service gets its own host route — the alternative (/24 aggregation) hides which Services are actually advertised and is a debugging nightmare. Set a hold time of 30 seconds with a 10-second keepalive so a node failure pulls the path within ~30 seconds; lower values churn unnecessarily, higher values mean longer outages. If you want sub-second failover, add BFD: deploy a BFDProfile CRD with transmitInterval: 200ms and reference it from the BGPPeer, and configure BFD on the router side. Never advertise the LB pool to your transit provider — keep the prefix-list on the router strict so a misconfigured cluster can’t blackhole arbitrary prefixes. Finally, if you use Calico or Cilium with their own BGP speakers, you must pick one: running MetalLB BGP and CNI BGP in parallel on the same nodes will fight over port 179.

Running BGP from your Kubernetes cluster against your network gear is the kind of integration that benefits from running both layers under one operator. Our Cloud Compute team builds Kubernetes on bare metal with BGP-attached load balancing and runs it under Managed Cloud Ops — book a network-design review if you want a second pair of eyes on the routing layout before you cut over production traffic.