Prometheus Query Workshop: Setup Requirements
This page is for the instructor or cluster administrator who prepares an OpenShift cluster for the Prometheus Query Workshop. It lists everything the exercises rely on, derived from the commands and manifests in the modules. It has two audiences: the cluster administrator, who prepares the cluster, the operators and the attendee accounts once before the workshop (sections Cluster to Network and Image Access), and the attendee, who only needs a workstation or terminal with the tools listed under Attendee Workstation. Modules 1 to 4 only need read access to the platform metrics; Modules 5 and 6 need additional cluster-wide preparation.
Cluster
-
OpenShift version: the content is written for and tested with OpenShift 4.16 (Prometheus 2.x); later 4.x releases work. From OpenShift 4.19, the Developer perspective of the web console is disabled by default. Modules 5 and 6 use it (Observe → Metrics and Alerts for a project, silencing alerts). Either enable it in the console customization settings (the Perspectives settings of the cluster
Consoleconfiguration; see the OpenShift documentation of your release), or let attendees use the API alternatives that Module 5 describes. -
Monitoring stack: the default platform monitoring stack in
openshift-monitoring(Prometheus, Thanos Querier, Alertmanager). The exercises use:-
the web console Observe → Metrics page (Modules 1 to 6)
-
the tenancy ports of the
thanos-querierservice: 9092 for queries (Modules 1, 4, 5, 6) and 9093 for alerts and rules (Module 5) -
the tenancy port 9092 of the
alertmanager-mainservice for silences (Module 5, optional step). Alerts of user projects must go to the platform Alertmanager, which is the default. -
the
prometheus-k8sroute inopenshift-monitoring, only in the optional cluster-administrator examples (Modules 1 and 4)
-
-
User workload monitoring: must be enabled for Modules 5 and 6 (see Enabling User Workload Monitoring).
-
Topology and size: there is no minimum number of worker nodes. Several queries in Modules 2 and 3 group by
node(for examplebottomk(3, …) by (node)and "Are the nodes balanced?"); they are more instructive on a cluster with several nodes, but they also work on single-node OpenShift, where they return one series. Each attendee runs at most these pods in their project:prometheus-example-app(1 replica),api-client(ubi-minimal, idle) and one Grafana instance. Enabling user workload monitoring adds aprometheus-user-workloadand athanos-ruler-user-workloadStatefulSet (two replicas each by default, one on single-node OpenShift) inopenshift-user-workload-monitoring; plan cluster capacity for those plus one Grafana pod per attendee. -
Ingress: attendees create routes (
oc expose servicein Module 5, thegrafana-routein Module 6) and must be able to reach*.apps.<cluster-domain>from their terminal and browser.
Operators and Cluster Components
| Component | Install source | Namespace | Configuration needed | Modules |
|---|---|---|---|---|
Platform monitoring (Prometheus, Thanos Querier, Alertmanager) |
Built into OpenShift |
|
None. Attendees need the |
1–6 |
User workload monitoring |
Built into OpenShift, disabled by default |
|
Set |
5, 6 |
Grafana Operator (community, version 5) |
OperatorHub, catalog |
|
Install once for the whole cluster (see Installing the Grafana Operator). The community operator is not supported by Red Hat. |
6 |
Enabling User Workload Monitoring
User workload monitoring is disabled by default. Enable it by setting enableUserWorkload: true in the cluster-monitoring-config ConfigMap in the openshift-monitoring namespace:
apiVersion: v1
kind: ConfigMap
metadata:
name: cluster-monitoring-config
namespace: openshift-monitoring
data:
config.yaml: |
enableUserWorkload: true
If the ConfigMap already exists, add the enableUserWorkload: true line to its existing config.yaml key instead of replacing the ConfigMap:
oc -n openshift-monitoring edit configmap cluster-monitoring-config
After a few minutes, the prometheus-user-workload and thanos-ruler-user-workload pods run in the openshift-user-workload-monitoring namespace:
oc -n openshift-user-workload-monitoring get pods
User workload monitoring skips the namespaces of the platform (openshift-, kube-) and namespaces labeled openshift.io/user-monitoring=false. Make sure that the attendee projects do not carry that label.
Installing the Grafana Operator
Install the community Grafana Operator once for the whole cluster:
-
In the Administrator perspective of the web console, navigate to Operators → OperatorHub.
-
Search for Grafana Operator, select the community operator, and click Install.
-
Select the
v5update channel and the All namespaces on the cluster installation mode, and click Install.
Alternatively, create a Subscription in the openshift-operators namespace:
apiVersion: operators.coreos.com/v1alpha1
kind: Subscription
metadata:
name: grafana-operator
namespace: openshift-operators
spec:
channel: v5
name: grafana-operator
source: community-operators
sourceNamespace: openshift-marketplace
When the operator is installed, project administrators and editors can create its resources (Grafana, GrafanaDatasource, GrafanaDashboard in the grafana.integreatly.org/v1beta1 API group) in their projects. No further role bindings are needed.
Attendee Accounts, Projects and Roles
This repository contains no provisioning automation; the instructor creates the users and projects with the identity provider and tooling of the lab environment. Each attendee needs:
-
A user account that can log in with
oc loginusing a user name and password or a token. The exercises runoc whoami -tto get an OAuth token, which does not work with a client-certificate kubeconfig (such askubeadmin’s `kubeconfigfile). -
One workshop project of their own, in which they have the
adminrole (or at leastedit). The content does not prescribe a project name; every exercise usesNS=$(oc project -q), so attendees only need to switch to their project. A simple convention is one project per user, named after the user, for example<user>-prometheus. Either let attendees runoc new-project(self-provisioning, enabled by default), or create the projects in advance:oc new-project <user>-prometheus oc adm policy add-role-to-user admin <user> -n <user>-prometheus -
The
cluster-monitoring-viewcluster role (Modules 1 to 4). It lets Observe → Metrics in the Administrator perspective show the metrics of every namespace, which the exercises query (for exampleopenshift-monitoringand node metrics). The role allows reading metrics, alerts and rules, and listing the names of all namespaces (sooc get projectsshows every project); it grants no access to other projects' resources. The tenancy API examples in Module 1 work with or without it.oc adm policy add-cluster-role-to-user cluster-monitoring-view <user> -
The
monitoring-editrole in their project (Modules 5 and 6). As project administrators, attendees can deploy applications, but creatingServiceMonitorandPodMonitorobjects, creatingPrometheusRuleobjects, reading the alerts and rules of the project through the tenancy port 9093 and creating silences require one of the monitoring roles:oc adm policy add-role-to-user monitoring-edit <user> \ -n <user>-prometheusmonitoring-rules-viewandmonitoring-rules-editare narrower roles, but Module 5 creates aServiceMonitor, which needsmonitoring-edit. -
No extra role for Module 6. Attendees create a service account
grafana-thanosand bind theviewcluster role to it in their own project, which the projectadminrole allows.
To prepare many users at once, loop over the user names, for example:
for u in user1 user2 user3; do
oc new-project "$u-prometheus"
oc adm policy add-role-to-user admin "$u" -n "$u-prometheus"
oc adm policy add-role-to-user monitoring-edit "$u" \
-n "$u-prometheus"
oc adm policy add-cluster-role-to-user cluster-monitoring-view "$u"
done
Instructor-only (not needed by attendees, and attendees cannot do these):
-
Enabling user workload monitoring and installing the Grafana Operator.
-
The port-forward examples in Modules 1 and 2: regular users cannot port-forward into
openshift-monitoring. The examples run:oc port-forward -n openshift-monitoring pod/prometheus-k8s-0 9090:9090 -
Querying all namespaces through the
prometheus-k8sroute works for users withcluster-monitoring-view; it is shown as an optional alternative in Modules 1 and 4. -
oc get nodes(Module 2, Exercise "find all pods running on a specific node") needs permission to list nodes, whichcluster-monitoring-viewdoes not grant. Attendees without it can read the node names from thenodelabel ofkube_node_infoinstead.
Attendee Workstation
Attendees work in the OpenShift web console and in a shell that is logged in to the cluster. When the workshop is served together with the OpenShift 102 lab, the introduction page includes the shared CLI tools container of that lab, which provides a terminal with these tools.
| Tool | Version | Used in |
|---|---|---|
|
Matching the cluster version; tested with the |
All modules: |
|
Any recent version |
Module 5: generating traffic to the route of the sample application from the workstation. Optional in Modules 1 and 4 for the |
Web browser |
A browser supported by the OpenShift web console |
All modules: Observe → Metrics; Module 6: Grafana UI |
|
GNU coreutils |
Module 5 (silence through the Alertmanager API, optional), Module 6 ( |
|
From a Prometheus release; optional |
Module 5: checking rule files before applying them (optional) |
No other CLIs (helm, podman, jq, istioctl) are used.
Network and Image Access
Container images that the exercises pull into attendee projects:
| Image | Used in |
|---|---|
|
Module 5 (Deployment of the sample application, kept running for Module 6) |
|
Modules 1, 4, 5, 6 ( |
|
Module 6 (Grafana instance created by the operator) |
Grafana Operator bundle and operator images (from the |
Module 6 (installed by the cluster administrator) |
External URLs used during the workshop:
-
https://prometheus.io/docs/introduction/overview/(reading link on the introduction page; not needed to run the exercises). -
The exercises themselves fetch nothing from the internet; all API calls go to cluster-internal services (
thanos-querier.openshift-monitoring.svc,alertmanager-main.openshift-monitoring.svc) or to routes under*.apps.<cluster-domain>.
For disconnected or restricted-egress clusters:
-
Mirror
quay.io/brancz/prometheus-example-app:v0.5.0andregistry.access.redhat.com/ubi9/ubi-minimal:latest, and either configure anImageDigestMirrorSet/ImageTagMirrorSetfor them or tell attendees to replace the image references in the manifests. -
Mirror the
community-operatorscatalog (at least thegrafana-operatorpackage, channelv5) withoc-mirror, together with the operator image and thedocker.io/grafana/grafanaimage that the installed operator version deploys. The Grafana image tag depends on the operator version; find it by creating a testGrafanainstance on a connected cluster and running this command in its project:oc get pods \ -l app=grafana \ -o jsonpath='{..image}' -
Docker Hub rate limits can affect the
docker.io/grafana/grafanapull when many attendees start Grafana at the same time; consider mirroring it even on connected clusters.
Verification Checklist
Instructor (as a cluster administrator):
-
The cluster version is 4.16 or later:
oc get clusterversion -
User workload monitoring is running; expect
prometheus-user-workload-andthanos-ruler-user-workload-pods inRunningstate:oc -n openshift-user-workload-monitoring get pods -
The Grafana Operator is installed; expect a
grafana-operator.v5.*CSV in phaseSucceeded:oc get csv -n openshift-operators | grep grafana-operator -
Each attendee has the roles; expect
yesfor every command:oc auth can-i get prometheuses/k8s \ --subresource=api \ -n openshift-monitoring \ --as <user> oc auth can-i create servicemonitors.monitoring.coreos.com \ -n <user>-prometheus \ --as <user> oc auth can-i create prometheusrules.monitoring.coreos.com \ -n <user>-prometheus \ --as <user> oc auth can-i create grafanas.grafana.integreatly.org \ -n <user>-prometheus \ --as <user>The first command checks the
cluster-monitoring-viewrole, which grantsgeton theapisubresource of theprometheusesresource namedk8s(a check without the name answersno). To see the binding directly, run:oc get clusterrolebinding -o wide | grep cluster-monitoring-viewThe output must list the user.
-
The images can be pulled: run the
api-clientpod from Module 1 in a test project and check that it reachesRunning.
Attendee (logged in with oc login, in their workshop project):
-
These commands print a token and the workshop project:
oc whoami -t oc project -q -
In the web console, Administrator perspective, Observe → Metrics, this query returns a number (not an empty result or a permission error):
count(kube_pod_info{namespace="openshift-monitoring"}) -
These commands print
yes:oc auth can-i create servicemonitors.monitoring.coreos.com oc auth can-i create prometheusrules.monitoring.coreos.com oc auth can-i create grafanas.grafana.integreatly.org