// Module included in the following assemblies:
//
// * networking/metallb/metallb-configure-bgp-peers.adoc

:_mod-docs-content-type: PROCEDURE
[id="nw-metallb-example-assign-specific-address-pools-specific-bgp-peers_{context}"]
= Configure a specific set of BGP peers for a given address pool

[role="_abstract"]
To assign specific IP address pools to designated BGP peers, configure MetalLB BGP advertisements. Establishing these mappings ensures that your cluster advertises designated network ranges only to authorized routing peers for precise external traffic control.

This procedure demonstrates the following tasks:

* Configure a set of address pools: `pool1` and `pool2`.
* Configure a set of BGP peers: `peer1` and `peer2`.
* Configure BGP advertisement to assign `pool1` to `peer1` and `pool2` to `peer2`.

.Prerequisites

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

.Procedure

. Create address pool `pool1`.
+
.. Create a file, such as `ipaddresspool1.yaml`, with content like the following example:
+
[source,yaml]
----
apiVersion: metallb.io/v1beta1
kind: IPAddressPool
metadata:
  namespace: metallb-system
  name: pool1
spec:
  addresses:
    - 4.4.4.100-4.4.4.200
    - 2001:100:4::200-2001:100:4::400
# ...
----
+
.. Apply the configuration for the IP address pool `pool1`:
+
[source,terminal]
----
$ oc apply -f ipaddresspool1.yaml
----

. Create address pool `pool2`.
+
.. Create a file, such as `ipaddresspool2.yaml`, with content like the following example:
+
[source,yaml]
----
apiVersion: metallb.io/v1beta1
kind: IPAddressPool
metadata:
  namespace: metallb-system
  name: pool2
spec:
  addresses:
    - 5.5.5.100-5.5.5.200
    - 2001:100:5::200-2001:100:5::400
# ...
----
+
.. Apply the configuration for the IP address pool `pool2`:
+
[source,terminal]
----
$ oc apply -f ipaddresspool2.yaml
----

. Create BGP `peer1`.
+
.. Create a file, such as `bgppeer1.yaml`, with content like the following example:
+
[source,yaml]
----
apiVersion: metallb.io/v1beta2
kind: BGPPeer
metadata:
  namespace: metallb-system
  name: peer1
spec:
  peerAddress: 10.0.0.1
  peerASN: 64501
  myASN: 64500
  routerID: 10.10.10.10
# ...
----
+
.. Apply the configuration for the BGP `peer1`:
+
[source,terminal]
----
$ oc apply -f bgppeer1.yaml
----

. Create BGP `peer2`.
+
.. Create a file, such as `bgppeer2.yaml`, with content like the following example:
+
[source,yaml]
----
apiVersion: metallb.io/v1beta2
kind: BGPPeer
metadata:
  namespace: metallb-system
  name: peer2
spec:
  peerAddress: 10.0.0.2
  peerASN: 64501
  myASN: 64500
  routerID: 10.10.10.10
# ...
----
+
.. Apply the configuration for the BGP `peer2`:
+
[source,terminal]
----
$ oc apply -f bgppeer2.yaml
----

. Create BGP advertisement 1.
+
.. Create a file, such as `bgpadvertisement1.yaml`, with content like the following example:
+
[source,yaml]
----
apiVersion: metallb.io/v1beta1
kind: BGPAdvertisement
metadata:
  name: bgpadvertisement-1
  namespace: metallb-system
spec:
  ipAddressPools:
    - pool1
  peers:
    - peer1
  communities:
    - 65535:65282
  aggregationLength: 32
  aggregationLengthV6: 128
  localPref: 100
# ...
----
+
.. Apply the configuration:
+
[source,terminal]
----
$ oc apply -f bgpadvertisement1.yaml
----

. Create BGP advertisement 2.
+
.. Create a file, such as `bgpadvertisement2.yaml`, with content like the following example:
+
[source,yaml]
----
apiVersion: metallb.io/v1beta1
kind: BGPAdvertisement
metadata:
  name: bgpadvertisement-2
  namespace: metallb-system
spec:
  ipAddressPools:
    - pool2
  peers:
    - peer2
  communities:
    - 65535:65282
  aggregationLength: 32
  aggregationLengthV6: 128
  localPref: 100
# ...
----
+
.. Apply the configuration:
+
[source,terminal]
----
$ oc apply -f bgpadvertisement2.yaml
----
