Configuring MetalLB address pools
The fields for the IPAddressPool
custom resource are described in the following tables.
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. |
|
| Optional: Specifies the key value pair assigned to the |
|
| Specifies a list of IP addresses for MetalLB Operator to assign to services. You can specify multiple ranges in a single pool; they will all share the same settings. Specify each range in CIDR notation or as starting and ending IP addresses separated with a hyphen. |
|
|
You can assign IP addresses from an IPAddressPool
to services and namespaces by configuring the spec.serviceAllocation
specification.
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
).
Procedure
Create a file, such as
ipaddresspool.yaml
, with content like the following example:1 This label assigned to the IPAddressPool
can be referenced by theipAddressPoolSelectors
in theBGPAdvertisement
CRD to associate theIPAddressPool
with the advertisement.Apply the configuration for the IP address pool:
$ oc apply -f ipaddresspool.yaml
Verification
View the address pool:
Example output
Name: doc-example
Namespace: metallb-system
Labels: zone=east
Annotations: <none>
API Version: metallb.io/v1beta1
Metadata:
...
Spec:
Addresses:
203.0.113.1-203.0.113.10
203.0.113.65-203.0.113.75
Auto Assign: true
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.
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: IPAddressPool
metadata:
name: doc-example-reserved
namespace: metallb-system
addresses:
- 10.0.100.0/28
autoAssign: false
You can add address pools that use IPv4 and IPv6. You can specify multiple ranges in the addresses
list, just like several IPv4 examples.
Whether the service is assigned a single IPv4 address, a single IPv6 address, or both is determined by how you add the service. The spec.ipFamilies
and spec.ipFamilyPolicy
fields control how IP addresses are assigned to the service.
You can assign IP addresses from an IPAddressPool
to services and namespaces that you specify.
If you assign a service or namespace to more than one IP address pool, MetalLB uses an available IP address from the higher-priority IP address pool. If no IP addresses are available from the assigned IP address pools with a high priority, MetalLB uses available IP addresses from an IP address pool with lower priority or no priority.
apiVersion: metallb.io/v1beta1
kind: IPAddressPool
metadata:
namespace: metallb-system
spec:
addresses:
- 192.168.20.0/24
serviceAllocation:
priority: 50 (1)
namespaces: (2)
- namespace-a
- namespace-b
namespaceSelectors: (3)
- matchLabels:
zone: east
serviceSelectors: (4)
- matchExpressions:
- key: security
operator: In
values:
1 | Assign a priority to the address pool. A lower number indicates a higher priority. |
2 | Assign one or more namespaces to the IP address pool in a list format. |
3 | Assign one or more namespace labels to the IP address pool by using label selectors in a list format. |
4 | Assign one or more service labels to the IP address pool by using label selectors in a list format. |
For BGP mode, see Configuring MetalLB BGP peers.