:_mod-docs-content-type: PROCEDURE
[id="nw-viewing-service-bgp-status_{context}"]
= Viewing the ServiceBGPStatus custom resource

[role="_abstract"]
You can verify border gateway protocol (BGP) advertisement status for your services by viewing the `ServiceBGPStatus` custom resource, which shows which BGP peers receive advertisements from each node. This is essential for debugging connectivity in telco environments.

The `ServiceBGPStatus` CR reports the BGP peering status for a service, detailing which neighbors are receiving updates from a specific node.

[NOTE]
====
`ServiceBGPStatus` resources are created in the `metallb-system` namespace, not in the namespace where your `LoadBalancer` service is deployed. Always query these resources with `-n metallb-system`.
====

.Prerequisites

* You have an {product-title} cluster with the MetalLB Operator installed.
* You have deployed a MetalLB instance.

This example shows how to configure MetalLB for BGP mode, deploy a service, and view the `ServiceBGPStatus` to verify BGP advertisements.

.Procedure

. Create an `IPAddressPool` CR for BGP, like the following example, and save it as `ipaddresspool.yaml`:
+
[source,yaml]
----
apiVersion: metallb.io/v1beta1
kind: IPAddressPool
metadata:
  name: bgp-pool
  namespace: metallb-system
spec:
  addresses:
  - 192.168.122.210-192.168.122.220
  autoAssign: true
----

. Run the following command to create the `IPAddressPool` configuration:
+
[source,terminal]
----
$ oc apply -f ipaddresspool.yaml
----

. To configure a BGP peer, create a file named `bgppeer.yaml` with the following content:
+
[source,yaml]
----
apiVersion: metallb.io/v1beta2
kind: BGPPeer
metadata:
  name: bgp-peer
  namespace: metallb-system
spec:
  myASN: 64501
  peerASN: 64500
  peerAddress: 192.168.1.1
----
+
* Set the `spec:peerAddress` field to the IP address of your BGP router.

. Apply the BGPPeer configuration by running the following command:
+
[source,terminal]
----
$ oc apply -f bgppeer.yaml
----

. To create a BGP advertisement to advertise the pool, create a file named `bgpadvertisement.yaml` with the following content:
+
[source,yaml]
----
apiVersion: metallb.io/v1beta1
kind: BGPAdvertisement
metadata:
  name: bgp-advertisement
  namespace: metallb-system
spec:
  ipAddressPools:
  - bgp-pool
----

. Apply the BGPAdvertisement configuration by running the following command:
+
[source,terminal]
----
$ oc apply -f bgpadvertisement.yaml
----

. Deploy an application and expose it with a `LoadBalancer` service. For this example, create a simple test application named for example `test-app` by creating a file named `deployment.yaml` with the following content:
+
[source,yaml]
----
apiVersion: apps/v1
kind: Deployment
metadata:
  name: test-app
  namespace: default
spec:
  replicas: 2
  selector:
    matchLabels:
      app: test-app
  template:
    metadata:
      labels:
        app: test-app
    spec:
      containers:
      - name: test-app
        image: quay.io/openshifttest/hello-openshift:multiarch
        ports:
        - containerPort: 8080
----

. Apply the deployment:
+
[source,terminal]
----
$ oc apply -f deployment.yaml
----

. Create a `LoadBalancer` service for the application:
+
[source,yaml]
----
apiVersion: v1
kind: Service
metadata:
  name: test-service
  namespace: default
spec:
  selector:
    app: test-app
  ports:
    - protocol: TCP
      port: 80
      targetPort: 8080
  type: LoadBalancer
----
+
[IMPORTANT]
====
The system creates `ServiceBGPStatus` resources automatically only when the service has at least one ready endpoint (running pod). Ensure your application pods are running before checking for `ServiceBGPStatus` resources.
====

. Apply the service configuration by running the following command:
+
[source,terminal]
----
$ oc apply -f service.yaml
----

. Verify the service received an external IP by running the following command:
+
[source,terminal]
----
$ oc get svc test-service -n default
----
+
The output is similar to the following:
+
[source,terminal]
----
NAME           TYPE           CLUSTER-IP       EXTERNAL-IP       PORT(S)        AGE
test-service   LoadBalancer   172.30.116.108   192.168.122.210   80:32431/TCP   2m
----

. View the `ServiceBGPStatus` resources by running the following command:
+
[source,terminal]
----
$ oc get servicebgpstatus -n metallb-system
----
+
The output is similar to the following:
+
[source,terminal]
----
NAME                  NODE       SERVICE NAME   SERVICE NAMESPACE
bgp-xxxxx             worker0    test-service   default
----
+
[NOTE]
====
`ServiceBGPStatus` resources are created with generated names. Use labels to find the status for your service:

[source,terminal]
----
$ oc get servicebgpstatus -n metallb-system -l metallb.io/service-name=test-service
----
====

. View the details of the `ServiceBGPStatus` CR for your service:
+
[source,terminal]
----
$ oc get servicebgpstatus bgp-xxxxx -n metallb-system -o yaml
----
+
The output is similar to the following:
+
[source,yaml]
----
apiVersion: metallb.io/v1beta1
kind: ServiceBGPStatus
metadata:
  name: bgp-xxxxx
  namespace: metallb-system
  labels:
    metallb.io/node: worker0
    metallb.io/service-name: test-service
    metallb.io/service-namespace: default
status:
  node: worker0
  peers:
  - bgp-peer
  serviceName: test-service
  serviceNamespace: default
----
+
* `metadata.labels.metallb.io/node` indicates the node that is advertising the service via BGP.
* `metadata.labels.metallb.io/service-name` identifies the service being advertised.
* `metadata.labels.metallb.io/service-namespace` identifies the namespace of the service being advertised.
* `status.node` confirms the name of the node advertising the service.
* `status.peers` lists the names of the BGPPeer resources to which the service is being advertised. This is useful for confirming that the advertisement is reaching the intended peers.
* `status.serviceName` indicates the name of the service being advertised.
* `status.serviceNamespace` indicates the namespace of the service being advertised.
