Configuring MetalLB address pools

As a cluster administrator, you can add, modify, and delete address pools. The MetalLB Operator uses the address pool custom resources to set the IP addresses that MetalLB can assign to services.

About the address pool custom resource

The fields for the address pool custom resource are described in the following table.

Table 1. MetalLB address pool custom resource
FieldTypeDescription

metadata.name

string

Specifies the name for the address pool. When you add a service, you can specify this pool name in the metallb.universe.tf/address-pool annotation to select an IP address from a specific pool. The names doc-example, silver, and gold are used throughout the documentation.

metadata.namespace

string

Specifies the namespace for the address pool. Specify the same namespace that the MetalLB Operator uses.

spec.protocol

string

Specifies the protocol for announcing the load balancer IP address to peer nodes. The only supported value is layer2.

spec.autoAssign

boolean

Optional: Specifies whether MetalLB automatically assigns IP addresses from this pool. Specify false if you want explicitly request an IP address from this pool with the metallb.universe.tf/address-pool annotation. The default value is true.

spec.addresses

array

Specifies a list of IP addresses for MetalLB to assign to services. You can specify multiple ranges in a single pool. Specify each range in CIDR notation or as starting and ending IP addresses separated with a hyphen.

Configuring an address pool

As a cluster administrator, you can add address pools to your cluster to control the IP addresses that MetaLLB can assign to load-balancer services.

Prerequisites

  • Install the OpenShift CLI (oc).

  • Log in as a user with cluster-admin privileges.

Procedure

  1. Create a file, such as addresspool.yaml, with content like the following example:

    1. apiVersion: metallb.io/v1alpha1
    2. kind: AddressPool
    3. metadata:
    4. namespace: metallb-system
    5. name: doc-example
    6. spec:
    7. protocol: layer2
    8. addresses:
    9. - 203.0.113.1-203.0.113.10
    10. - 203.0.113.65-203.0.113.75
  2. Apply the configuration for the address pool:

    1. $ oc apply -f addresspool.yaml

Verification

  • View the address pool:

    1. $ oc describe -n metallb-system addresspool doc-example

    Example output

    1. Name: doc-example
    2. Namespace: metallb-system
    3. Labels: <none>
    4. Annotations: <none>
    5. API Version: metallb.io/v1alpha1
    6. Kind: AddressPool
    7. Metadata:
    8. ...
    9. Spec:
    10. Addresses:
    11. 203.0.113.1-203.0.113.10
    12. 203.0.113.65-203.0.113.75
    13. Auto Assign: true
    14. Protocol: layer2
    15. Events: <none>

Confirm that the address pool name, such as doc-example, and the IP address ranges appear in the output.

Example address pool configurations

Example: IPv4 and CIDR ranges

You can specify a range of IP addresses in CIDR notation. You can combine CIDR notation with the notation that uses a hyphen to separate lower and upper bounds.

  1. apiVersion: metallb.io/v1beta1
  2. kind: AddressPool
  3. metadata:
  4. name: doc-example-cidr
  5. namespace: metallb-system
  6. spec:
  7. protocol: layer2
  8. addresses:
  9. - 192.168.100.0/24
  10. - 192.168.200.0/24
  11. - 192.168.255.1-192.168.255.5

Example: Reserve IP addresses

You can set the autoAssign field to false to prevent MetalLB from automatically assigning the IP addresses from the pool. When you add a service, you can request a specific IP address from the pool or you can specify the pool name in an annotation to request any IP address from the pool.

  1. apiVersion: metallb.io/v1beta1
  2. kind: AddressPool
  3. metadata:
  4. name: doc-example-reserved
  5. namespace: metallb-system
  6. spec:
  7. protocol: layer2
  8. addresses:
  9. - 10.0.100.0/28
  10. autoAssign: false

Example: IPv6 address pool

You can add address pools that use IPv6. The following example shows a single IPv6 range. However, you can specify multiple ranges in the addresses list, just like several IPv4 examples.

  1. apiVersion: metallb.io/v1beta1
  2. kind: AddressPool
  3. metadata:
  4. name: doc-example-ipv6
  5. namespace: metallb-system
  6. spec:
  7. protocol: layer2
  8. addresses:
  9. - 2002:2:2::1-2002:2:2::100

Next steps