// This assembly is included in the following assemblies:
//
// metrics/assembly_metrics-prometheus-deploy.adoc/

[id='proc-metrics-deploying-prometheus-{context}']

= Deploying Prometheus

To deploy Prometheus to your Kafka cluster to obtain monitoring data, apply the xref:ref-metrics-config-files-{context}[example resource file for the Prometheus docker image and the YAML files for Prometheus-related resources].

The deployment process creates a `ClusterRoleBinding` and discovers an Alertmanager instance in the namespace specified for the deployment.

NOTE: By default, the Prometheus Operator only supports jobs that include an `endpoints` role for service discovery. Targets are discovered and scraped for each endpoint port address. For endpoint discovery, the port address may be derived from service (`role: service`) or pod (`role: pod`) discovery.

.Prerequisites

* Check the xref:ref-metrics-alertmanager-examples-{context}[example alerting rules provided]

.Procedure

. Modify the Prometheus installation file (`prometheus.yaml`) according to the namespace Prometheus is going to be installed in:
+
On Linux, use:
+
[source,shell,subs="+quotes,attributes"]
sed -i 's/namespace: .*/namespace: _my-namespace_/' prometheus.yaml
+
On MacOS, use:
+
[source,shell,subs="+quotes,attributes"]
sed -i '' 's/namespace: .*/namespace: _my-namespace_/' prometheus.yaml

. Edit the `ServiceMonitor` resource in `strimzi-service-monitor.yaml` to define Prometheus jobs that will scrape the metrics data from services.
`ServiceMonitor` is used to scrape metrics through services and is used for Apache Kafka, ZooKeeper.

. Edit the `PodMonitor` resource in `strimzi-pod-monitor.yaml` to define Prometheus jobs that will scrape the metrics data from pods.
`PodMonitor` is used to scrape data directly from pods and is used for Operators.

. To use another role:

.. Create a `Secret` resource:
+
[source,shell,subs="+quotes,attributes"]
kubectl create secret generic additional-scrape-configs --from-file=prometheus-additional.yaml

.. Edit the `additionalScrapeConfigs` property in the `prometheus.yaml` file to include the name of the `Secret` and the YAML file (`prometheus-additional.yaml`) that contains the additional configuration.

. Deploy the Prometheus resources:
+
[source,shell,subs="+quotes,attributes"]
kubectl apply -f strimzi-service-monitor.yaml
kubectl apply -f strimzi-pod-monitor.yaml
kubectl apply -f prometheus-rules.yaml
kubectl apply -f prometheus.yaml
