// Module included in the following assemblies:
//
//* observability/otel/otel-installing.adoc

:_mod-docs-content-type: PROCEDURE
[id="installing-otel-by-using-the-cli_{context}"]
= Installing the {OTELShortName} by using the CLI

You can install the {OTELShortName} from the command line.

.Prerequisites

* An active {oc-first} session by a cluster administrator with the `cluster-admin` role.
+
[TIP]
====
* Ensure that your {oc-first} version is up to date and matches your {product-title} version.

* Run `oc login`:
+
[source,terminal]
----
$ oc login --username=<your_username>
----
====

.Procedure

. Install the {OTELOperator}:

.. Create a project for the {OTELOperator} by running the following command:
+
[source,terminal]
----
$ oc apply -f - << EOF
apiVersion: project.openshift.io/v1
kind: Project
metadata:
  labels:
    kubernetes.io/metadata.name: openshift-opentelemetry-operator
    openshift.io/cluster-monitoring: "true"
  name: openshift-opentelemetry-operator
EOF
----

.. Create an Operator group by running the following command:
+
[source,terminal]
----
$ oc apply -f - << EOF
apiVersion: operators.coreos.com/v1
kind: OperatorGroup
metadata:
  name: openshift-opentelemetry-operator
  namespace: openshift-opentelemetry-operator
spec:
  upgradeStrategy: Default
EOF
----

.. Create a subscription by running the following command:
+
[source,terminal]
----
$ oc apply -f - << EOF
apiVersion: operators.coreos.com/v1alpha1
kind: Subscription
metadata:
  name: opentelemetry-product
  namespace: openshift-opentelemetry-operator
spec:
  channel: stable
  installPlanApproval: Automatic
  name: opentelemetry-product
  source: redhat-operators
  sourceNamespace: openshift-marketplace
EOF
----

.. Check the Operator status by running the following command:
+
[source,terminal]
----
$ oc get csv -n openshift-opentelemetry-operator
----

. Create a permitted project of your choice for the OpenTelemetry Collector instance that you will create in a subsequent step:

** To create a permitted project without metadata, run the following command:
+
[source,terminal]
----
$ oc new-project <permitted_project_of_opentelemetry_collector_instance> # <1>
----
<1> Project names beginning with the `openshift-` prefix are not permitted.

** To create a permitted project with metadata, run the following command:
+
[source,terminal]
----
$ oc apply -f - << EOF
apiVersion: project.openshift.io/v1
kind: Project
metadata:
  name: <permitted_project_of_opentelemetry_collector_instance> # <1>
EOF
----
<1> Project names beginning with the `openshift-` prefix are not permitted.

. Create an OpenTelemetry Collector instance in the project that you created for it.
+
[NOTE]
====
You can create multiple OpenTelemetry Collector instances in separate projects on the same cluster.
====
+
.. Customize the `OpenTelemetryCollector` custom resource (CR):
+
--
include::snippets/otel-collector-custom-resource.adoc[]
--

.. Apply the customized CR by running the following command:
+
[source,terminal]
----
$ oc apply -f - << EOF
<OpenTelemetryCollector_custom_resource>
EOF
----


.Verification

. Verify that the `status.phase` of the OpenTelemetry Collector pod is `Running` and the `conditions` are `type: Ready` by running the following command:
+
[source,terminal]
----
$ oc get pod -l app.kubernetes.io/managed-by=opentelemetry-operator,app.kubernetes.io/instance=<namespace>.<instance_name> -o yaml
----

. Get the OpenTelemetry Collector service by running the following command:
+
[source,terminal]
----
$ oc get service -l app.kubernetes.io/managed-by=opentelemetry-operator,app.kubernetes.io/instance=<namespace>.<instance_name>
----
