How to configure Prometheus inside Openshift to scrape necessary metrics for Applications Manager?
To setup Prometheus inside a Openshift Cluster and scrape metrics for monitoring the same in Applications Manager, kindly follow the steps given below:
- Create a new Project "monitor" inside the Desired Cluster to be monitored using the below command. You can use this project to deploy Applications Manager's monitoring stack for scraping Openshift metrics.
- #Command to create a new namespace monitor
- oc new-project monitor
- Applications Manager uses the official Kube-state-metrics deployment image to export Openshift Cluster metrics. Since this deployment uses Kubernetes API to collect and expose Openshift Cluster level metrics, you will need to configure certain Cluster roles and their corresponding Cluster role bindings to provide appropriate permissions.
- Download the cluster-role.yaml and cluster-role-binding.yaml files attached in this article.
- Navigate to the namespace monitor that you just created and execute the following commands to create Cluster role and Cluster Role bindings required for monitoring,
- #Command to navigate to the namespace monitor
- oc project monitor
- #Command to create ClusterRole and ClusterRoleBinding using the files provided
- oc apply -f cluster-role.yaml
- oc apply -f cluster-role-binding.yaml
- This will create a monitor named ClusterRole that will be bound to the ServiceAccount default of the namespace monitor using the ClusterRoleBinding, which you just created.
- Now that the required Cluster roles and Cluster role bindings have been created successfully, you can proceed with installing the components required to expose Prometheus. The following components will be deployed in the namespace that you created earlier and assigned Cluster role and Cluster role bindings:
- Kube-state-metrics
- Prometheus
- To Deploy the above mentioned components, execute the below mentioned commands after logging into the Openshift CLI interface.
- #Command to navigate to namespace monitor
- oc project monitor
- #Command to deploy kube-state-metrics
- oc new-app bitnami/kube-state-metrics
- #Command to deploy prometheus
- oc new-app prom/prometheus
- Once this is done, and the components that you deployed are up and running, you need to configure Prometheus to discover Kube-state-metrics deployment as a target and scrape the metrics for monitoring in Applications Manager.
- Download the prometheus.yml file attached to this article.
- Navigate to the namespace monitor where Applications Manager's monitoring components are running and create a ConfigMap for the prometheus.yml configuration file using the below command,
- #Command to navigate to the namespace
- oc project monitor
- #Command to create a ConfigMap named prom-config for our prometheus configuration
- oc create configmap prom-config --from-file=prometheus.yml
- Now the ConfigMap has been created successfully. Note that the name of the file should not be changed since this is crucial for Applications Manager's Prometheus deployment to pick up the configuration file as you proceed with further steps.
- Execute the following command to open the DeploymentConfig for the Prometheus deployment.
- #Command to navigate to the namespace monitor
- oc project monitor
- #Command to edit DeploymentConfig for prometheus deployment
- oc edit dc prometheus
- This will open up the DeploymentConfig for the Prometheus deployment
- Now you have to create a Volume for the ConfigMap prom-config that you created earlier and mount it to /etc/prometheus/ path inside the deployment for Prometheus to pick up the Configuration changes.
- To create a new volume, find the volumes tag in the DeploymentConfig for Prometheus and add the below mentioned changes as required.
The changes to be added are highlighted below,
- volumes:
- emptyDir: {}
name: prometheus-volume-1
- configMap:
defaultMode: 420
name: prom-config
name: prom-config-volume
- Now create a Volume mount to mount the prom-config-volume volume to /etc/prometheus/ path. To do this, find the volumeMounts tag and add the below mentioned changes as required. The changes to be added are highlighted below,
- volumeMounts:
- mountPath: /prometheus
name: prometheus-volume-1
- mountPath: /etc/prometheus/
name: prom-config-volume
- A sample DeploymentConfig is attached in this Article (Ref. DeplymentConfig.yaml).
- Now save and close the DeploymentConfig. Once this is done, the configuration will be picked up by the Prometheus deployment in no time and the kube-state-metrics target will be discovered as shown in the below image.
- The service Prometheus has to be exposed in order to configure it in Applications Manager. To do this, execute the below command,
- #Command to convert a required service's type to NodePort
- oc patch svc prometheus -p '{"spec":{"type": "NodePort"}}'
- Once this is done, Prometheus can be integrated in Applications Manager using the NodePort which can be obtained using the below command.
The port required for integration is highlighted below.
- #Command to get the details of a service
- oc get svc prometheus
- #Output
- NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
prometheus NodePort 172.30.6.154 <none> 9090:32486/TCP 6d
New to ADSelfService Plus?
Related Articles
Absence of data in the Pods tab or some tabs in the OpenShift monitor
To collect data for the OpenShift Monitor, Applications Manager uses the SSH protocol to connect to the OpenShift server and execute "oc" commands. However, a timeout issue may occur while collecting data if the environment has a large number of ...
How to configure Tomcat Exporter to scrape metrics from Prometheus?
To setup exporter, follow the steps given below: Install a standalone Tomcat-sever or as a container as kubernetes cluster. Download the Tomcat exporter servlet file in .war format from here. Rename the file as metrics.war and deploy it in the ...
OpenShift Monitoring in Rest API Mode
For the OpenShift monitor, data collection when carried out using SSH mode sometimes results in timeout exception due to the presence of large amount of data to be collected. To avoid this, an enhancement has been made and now data collection will ...
Steps to configure AWS RDS database as Applications Manager's back-end
Browse through the following topics to configure AWS RDS as a database backend in Applications Manager: Note: Make sure to verify the DB permissions required to run Applications Manager. Learn more Steps to configure AWS RDS - PostgreSQL database The ...
Installing Applications Manager in Microsoft Azure
Applications manager can be installed in Azure Virtual Machines in both Windows and Linux platforms. Applications Manager comes with bundled PostgreSQL. Installing Applications Manager in VM for Windows Go to Virtual Machines and create a "Windows" ...