Configure MetalLB

TOC

Prerequisites

Please ensure that you have read the Installation documentation before proceeding.

Configure an External IP Address Pool by using the web console

  1. Go to Administrator.

  2. In the left navigation bar, click Network Management > External IP Address Pool.

  3. Click Create External IP Address Pool.

  4. Refer to the following instructions to configure certain parameters.

    ParameterDescription
    Type
    • L2: Communication and forwarding based on MAC addresses, suitable for small-scale or local area networks that require simple and fast layer 2 switching, with advantages in simple configuration and low latency.
    • BGP (Alpha): Routing and forwarding based on IP addresses, using BGP protocol to exchange routing information, suitable for large-scale networks requiring complex routing across multiple autonomous systems, with advantages in high scalability and reliability.
    IP ResourcesSupport input in CIDR and IP range formats. Click Add to support multiple entries, examples as follows:
    CIDR: 192.168.1.1/24.
    IP Range: 192.168.2.1 ~ 192.168.2.255.
    Available NodesIn L2 mode, available nodes are those used to carry all VIP traffic; in BGP mode, available nodes are those used to carry VIPs, establish BGP connections with peers, and announce routes externally.
    • Node Name: Select available nodes based on node names.
    • Label Selector: Select available nodes based on labels.
    • Show Node Details: View final available nodes in a list format.
    Note:
    • When using BGP type, the available nodes are the next-hop nodes; ensure that the selected available nodes are a subset of the BGP Connection Nodes.
    • You can configure either the label selector or the node name separately to choose available nodes; if both are configured simultaneously, the final available nodes are the intersection of both.
    BGP PeersSelect BGP peers; please refer to BGP Peers for specific configurations.
  5. Click Create.

Configure BGP Peers by using the web console

  1. Go to Administrator.

  2. In the left navigation bar, click Network Management > BGP Peers.

  3. Click Create BGP Peer.

  4. Refer to the instructions below to configure the parameters.

    ParameterDescription
    Local AS NumberThe AS number of the AS where the BGP-connected node resides.

    Note: If there are no special requirements, it is recommended to use an IBGP configuration, meaning the local AS number should be consistent with the peer AS number.
    Peer AS NumberThe AS number of the AS where the BGP peer resides.
    Peer IPThe IP address of the BGP peer, which must be a valid IP address capable of establishing a BGP connection.
    Local IPThe IP address of the BGP-connected node. When the BGP-connected node has multiple IPs, select the specified local IP to establish a BGP connection with the peer.
    Peer PortThe port number of the BGP peer.
    BGP-Connected NodeThe node that establishes the BGP connection. If this parameter is not configured, all nodes will establish BGP connections.
    eBGP Multi-HopAllows the establishment of BGP sessions between BGP routers that are not directly connected. When this feature is enabled, the default TTL value of BGP packets is 5, allowing the establishment of BGP peer relationships across multiple intermediate network devices, making network design more flexible.
    RouterIDA 32-bit numeric value (usually represented in dotted-decimal format, similar to IPv4 address format) used to uniquely identify a BGP router in the BGP network, generally used for establishing BGP neighbor relationships, detecting routing loops, selecting optimal paths, and troubleshooting network issues.
  5. Click Create.

Configure an External IP Address Pool with L2Advertisement or BGPAdvertisement by using the CLI

# ippool-with-L2advertisement.yaml
kind: IPAddressPool
apiVersion: metallb.io/v1beta1
metadata:
  name: test-ippool
  namespace: metallb-system
spec:
  addresses:
    - 13.1.1.1/24
  avoidBuggyIPs: true
---
kind: L2Advertisement
apiVersion: metallb.io/v1beta1
metadata:
  name: test-ippool
  namespace: metallb-system
spec:
  ipAddressPools:
    - test-ippool
  nodeSelectors:
    - matchLabels: {}
      matchExpressions:
        - key: kubernetes.io/hostname
          operator: In
          values:
            - 192.168.66.210

BGP mode

# ippool-with-bgpadvertisement.yaml
kind: IPAddressPool
apiVersion: metallb.io/v1beta1
metadata:
  name: test-pool-bgp
  namespace: metallb-system
spec:
  addresses:
    - 4.4.4.3/23
  avoidBuggyIPs: true
---
kind: BGPAdvertisement
apiVersion: metallb.io/v1beta1
metadata:
  name: test-pool-bgp
  namespace: metallb-system
spec:
  ipAddressPools:
    - test-pool-bgp
  nodeSelectors:
    - matchLabels:
        alertmanager: 'true'
  peers:
    - test-bgp-example
kubectl apply -f ippool-with-L2advertisement.yaml -f ippool-with-bgpadvertisement.yaml

Troubleshooting MetalLB

SymptomPossible CauseResolution
No external IP assignedNo valid IPAddressPool or pool misconfiguredVerify IP range and namespace
Pods CrashLoopSpeaker or Controller RBAC missingCheck Operator permissions
BGP not establishedASN mismatch or peer unreachableCheck BGPPeer spec and network routes
L2 not workingWrong VLAN or ARP filteringUse arping to verify broadcast reachability

To see more Troubleshooting MetalLB