// Module included in the following assemblies:
//
// * networking/metallb/about-advertising-ipaddresspool.adoc

:_mod-docs-content-type: PROCEDURE
[id="nw-metallb-configure-with-L2-advertisement-label_{context}"]
= Configuring MetalLB with an L2 advertisement and labels

[role="_abstract"]
You can use the `ipAddressPoolSelectors` field in the `L2Advertisement` custom resource definition to associate the `IPAddressPool` with the advertisement based on the label assigned to the pool instead of the pool name.
The example configures MetalLB to advertise the pool over Layer 2 by using `ipAddressPoolSelectors`.

.Prerequisites

* Install the {oc-first}.
* Log in as a user with `cluster-admin` privileges.

.Procedure

. Create an IP address pool.
+
.. Create a file, such as `ipaddresspool.yaml`, with content like the following example:
+
[source,yaml]
----
apiVersion: metallb.io/v1beta1
kind: IPAddressPool
metadata:
  namespace: metallb-system
  name: doc-example-l2-label
  labels:
    zone: east
spec:
  addresses:
    - 172.31.249.87/32
# ...
----
+
.. Apply the configuration for the IP address pool:
+
[source,terminal]
----
$ oc apply -f ipaddresspool.yaml
----

. Create an L2 advertisement that advertises the IP address by using `ipAddressPoolSelectors`.
+
.. Create a file, such as `l2advertisement.yaml`, with content like the following example:
+
[source,yaml]
----
apiVersion: metallb.io/v1beta1
kind: L2Advertisement
metadata:
  name: l2advertisement-label
  namespace: metallb-system
spec:
  ipAddressPoolSelectors:
    - matchExpressions:
        - key: zone
          operator: In
          values:
            - east
# ...
----
+
.. Apply the configuration:
+
[source,terminal]
----
$ oc apply -f l2advertisement.yaml
----
