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
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.
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. |
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.
Install the OpenShift CLI (oc
).
Log in as a user with cluster-admin
privileges.
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
View the address pool:
$ oc describe -n metallb-system addresspool doc-example
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.
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
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
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