Skip to content

Commit 41b8688

Browse files
Merge pull request #68 from Kuadrant/grafana-on-openshift-for-kuadrant-obs
Add blog post for installing grafana on openshift
2 parents 8af6589 + 0f376b1 commit 41b8688

File tree

1 file changed

+141
-0
lines changed

1 file changed

+141
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
---
2+
title: Installing Grafana on Openshift for Kaudrant Observability.
3+
date: 2024-11-08
4+
author: David Martin
5+
---
6+
7+
To make the most out of Kuadrant on OpenShift, you can install Grafana and import example dashboards for enhanced observability. This guide demonstrates how to install and configure Grafana using the Grafana Operator on OpenShift, specifically using `oc` commands. We'll also set up datasources to pull metrics from the OpenShift Thanos Query instance.
8+
9+
## Prerequisites
10+
11+
- **OpenShift version 4.17** (commands tested on this version)
12+
- **Kuadrant installed** on your OpenShift cluster
13+
- `oc` CLI tool installed and configured
14+
- User with `cluster-monitoring-view` role
15+
16+
## Installing the Grafana Operator
17+
18+
Grafana can be installed and managed on OpenShift using the [Grafana Operator](https://grafana.github.io/grafana-operator/). The operator is available via the `community-operators` source in OpenShift.
19+
20+
Create a `Subscription` to install the Grafana Operator:
21+
22+
```bash
23+
cat << EOF | oc apply -f -
24+
apiVersion: operators.coreos.com/v1alpha1
25+
kind: Subscription
26+
metadata:
27+
labels:
28+
operators.coreos.com/grafana-operator.openshift-operators: ""
29+
name: grafana-operator
30+
namespace: openshift-operators
31+
spec:
32+
channel: v5
33+
installPlanApproval: Automatic
34+
name: grafana-operator
35+
source: community-operators
36+
sourceNamespace: openshift-marketplace
37+
EOF
38+
```
39+
40+
> **Note:** The `v5` channel introduces changes that are **not** backward compatible with version 4 of the operator.
41+
42+
## Creating a Grafana Instance
43+
44+
Next, create a Grafana Custom Resource (CR):
45+
46+
```bash
47+
cat << EOF | oc apply -f -
48+
apiVersion: grafana.integreatly.org/v1beta1
49+
kind: Grafana
50+
metadata:
51+
labels:
52+
dashboards: grafana
53+
name: grafana
54+
namespace: openshift-operators
55+
spec:
56+
config:
57+
auth:
58+
disable_login_form: 'false'
59+
log:
60+
mode: console
61+
security:
62+
admin_password: secret
63+
admin_user: root
64+
route:
65+
metadata: {}
66+
spec: {}
67+
version: 10.4.3
68+
EOF
69+
```
70+
71+
> **Note:** For simplicity, the admin username and password are set inline as `root` and `secret` respectively. Adjust these values as needed for your environment.
72+
73+
## Configuring Grafana DataSource
74+
75+
The source of metrics for Kuadrant dashboards will be the Thanos Query instance in the OpenShift cluster. This Thanos instance provides important cluster metrics, as well as any metrics pushed from the user-workload Prometheus instance (which includes metrics from the gateway and Kuadrant components).
76+
77+
> **Note:** User workload monitoring needs to be enabled to include metrics from user workloads. See the [Openshift documentation](https://docs.openshift.com/container-platform/4.17/observability/monitoring/enabling-monitoring-for-user-defined-projects.html) for how to do this.
78+
79+
To allow Grafana to access Thanos Query, you can either use a user token or create a ServiceAccount token. In this guide, we'll use the token of the currently logged-in user.
80+
81+
> **Note:** The user/serviceaccount must have the `cluster-monitoring-view` role. Depending on the type of account used, the token may expire after a set amount of time. For more information on accessing Thanos Query in an OpenShift cluster, refer to the [OpenShift documentation](https://docs.openshift.com/container-platform/4.15/observability/monitoring/accessing-third-party-monitoring-apis.html#accessing-metrics-from-outside-cluster_accessing-monitoring-apis-by-using-the-cli).
82+
83+
Retrieve the user token and Thanos Query hostname:
84+
85+
```bash
86+
TOKEN=$(oc whoami -t)
87+
HOST=$(oc -n openshift-monitoring get route thanos-querier -o jsonpath={.status.ingress[].host})
88+
```
89+
90+
Create the Grafana datasource:
91+
92+
```bash
93+
cat << EOF | oc apply -f -
94+
apiVersion: grafana.integreatly.org/v1beta1
95+
kind: GrafanaDatasource
96+
metadata:
97+
name: thanos-query-ds
98+
namespace: openshift-operators
99+
spec:
100+
datasource:
101+
access: proxy
102+
isDefault: true
103+
jsonData:
104+
httpHeaderName1: 'Authorization'
105+
timeInterval: 5s
106+
tlsSkipVerify: true
107+
secureJsonData:
108+
httpHeaderValue1: 'Bearer ${TOKEN}'
109+
name: thanos-query-ds
110+
type: prometheus
111+
url: 'https://${HOST}'
112+
instanceSelector:
113+
matchLabels:
114+
dashboards: grafana
115+
EOF
116+
```
117+
118+
> **Note:** The token is included in plaintext in the `secureJsonData` section. For different authentication methods and best practices, consult the [Grafana Operator documentation](https://grafana.github.io/grafana-operator/docs/quick-start/).
119+
120+
## Accessing Grafana
121+
122+
Retrieve the Grafana route to access the UI:
123+
124+
```bash
125+
oc -n openshift-operators get routes grafana-route -o jsonpath="https://{.status.ingress[].host}"
126+
```
127+
128+
Open the provided URL in your web browser and log in using the credentials set earlier (`root`/`secret`).
129+
130+
## Importing Kuadrant Dashboards
131+
132+
Import the Kuadrant dashboards into Grafana as detailed in the [Kuadrant documentation](https://docs.kuadrant.io/latest/kuadrant-operator/doc/observability/examples/).
133+
134+
If you have a gateway configured with Kuadrant policies, you should see activity on the various dashboards.
135+
136+
## Further Reading
137+
138+
- [Metrics](https://docs.kuadrant.io/latest/kuadrant-operator/doc/observability/metrics/)
139+
- [Dashboards and Alerts](https://docs.kuadrant.io/latest/kuadrant-operator/doc/observability/examples/)
140+
- [Tracing](https://docs.kuadrant.io/latest/kuadrant-operator/doc/observability/tracing/)
141+
- [Deploying Grafana on Openshift (using older v4 channel)](https://cloud.redhat.com/experts/o11y/ocp-grafana/)

0 commit comments

Comments
 (0)