Configuring MetalLB address pools
- About the address pool custom resource
- Configuring an address pool
- Example address pool configurations
- Next steps
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.
Field | Type | Description |
---|---|---|
|
| Specifies the name for the address pool. When you add a service, you can specify this pool name in the |
|
| Specifies the namespace for the address pool. Specify the same namespace that the MetalLB Operator uses. |
|
| Specifies the protocol for announcing the load balancer IP address to peer nodes. The only supported value is |
|
| Optional: Specifies whether MetalLB automatically assigns IP addresses from this pool. Specify |
|
| 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
Create a file, such as
addresspool.yaml
, with content like the following example:apiVersion: metallb.io/v1alpha1
kind: AddressPool
metadata:
namespace: metallb-system
name: doc-example
spec:
protocol: layer2
addresses:
- 203.0.113.1-203.0.113.10
- 203.0.113.65-203.0.113.75
Apply the configuration for the address pool:
$ oc apply -f addresspool.yaml
Verification
View the address pool:
$ oc describe -n metallb-system addresspool doc-example
Example output
Name: doc-example
Namespace: metallb-system
Labels: <none>
Annotations: <none>
API Version: metallb.io/v1alpha1
Kind: AddressPool
Metadata:
...
Spec:
Addresses:
203.0.113.1-203.0.113.10
203.0.113.65-203.0.113.75
Auto Assign: true
Protocol: layer2
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.
apiVersion: metallb.io/v1beta1
kind: AddressPool
metadata:
name: doc-example-cidr
namespace: metallb-system
spec:
protocol: layer2
addresses:
- 192.168.100.0/24
- 192.168.200.0/24
- 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.
apiVersion: metallb.io/v1beta1
kind: AddressPool
metadata:
name: doc-example-reserved
namespace: metallb-system
spec:
protocol: layer2
addresses:
- 10.0.100.0/28
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.
apiVersion: metallb.io/v1beta1
kind: AddressPool
metadata:
name: doc-example-ipv6
namespace: metallb-system
spec:
protocol: layer2
addresses:
- 2002:2:2::1-2002:2:2::100