// Module included in the following assemblies:
//
// * networking/metallb/metallb-operator-install.adoc

:_mod-docs-content-type: PROCEDURE
[id="nw-metallb-installing-operator-cli_{context}"]
= Installing from the software catalog using the CLI

[role="_abstract"]
To install the MetalLB Operator from the software catalog in {product-title} without using the web console, you can use the {oc-first}.

It is recommended that when using the CLI you install the Operator in the `metallb-system` namespace.

.Prerequisites

* A cluster installed on bare-metal hardware.
* Install the OpenShift CLI (`oc`).
* Log in as a user with `cluster-admin` privileges.

.Procedure

. Create a namespace for the MetalLB Operator by entering the following command:
+
[source,terminal]
----
$ cat << EOF | oc apply -f -
apiVersion: v1
kind: Namespace
metadata:
  name: metallb-system
EOF
----

. Create an Operator group custom resource (CR) in the namespace:
+
[source,terminal]
----
$ cat << EOF | oc apply -f -
apiVersion: operators.coreos.com/v1
kind: OperatorGroup
metadata:
  name: metallb-operator
  namespace: metallb-system
EOF
----

. Confirm the Operator group is installed in the namespace:
+
[source,terminal]
----
$ oc get operatorgroup -n metallb-system
----
+
.Example output
[source,terminal]
----
NAME               AGE
metallb-operator   14m
----

. Create a `Subscription` CR:
.. Define the `Subscription` CR and save the YAML file, for example, `metallb-sub.yaml`:
+
[source,yaml]
----
apiVersion: operators.coreos.com/v1alpha1
kind: Subscription
metadata:
  name: metallb-operator-sub
  namespace: metallb-system
spec:
  channel: stable
  name: metallb-operator
  source: redhat-operators
  sourceNamespace: openshift-marketplace
----
+
** For the `spec.source` parameter, must specify the `redhat-operators` value.

.. To create the `Subscription` CR, run the following command:
+
[source,terminal]
----
$ oc create -f metallb-sub.yaml
----

. Optional: To ensure BGP and BFD metrics appear in Prometheus, you can label the namespace as in the following command:
+
[source,terminal]
----
$ oc label ns metallb-system "openshift.io/cluster-monitoring=true"
----

.Verification

The verification steps assume the MetalLB Operator is installed in the `metallb-system` namespace.

. Confirm the install plan is in the namespace:
+
[source,terminal]
----
$ oc get installplan -n metallb-system
----
+
.Example output
[source,terminal,subs="attributes+"]
----
NAME            CSV                                   APPROVAL    APPROVED
install-wzg94   metallb-operator.{product-version}.0-nnnnnnnnnnnn   Automatic   true
----
+
[NOTE]
====
Installation of the Operator might take a few seconds.
====

. To verify that the Operator is installed, enter the following command and then check that output shows `Succeeded` for the Operator:
+
[source,terminal]
----
$ oc get clusterserviceversion -n metallb-system \
  -o custom-columns=Name:.metadata.name,Phase:.status.phase
----
