Chapter 1. Preparing to configure the user workload monitoring stack
Learn which user-defined monitoring components can be configured , how to enable user workload monitoring, and how to prepare for configuring the user workload monitoring stack.
- Not all configuration parameters for the monitoring stack are exposed. Only the parameters and fields listed in the Config map reference for the Cluster Monitoring Operator are supported for configuration.
- The monitoring stack imposes additional resource requirements. Consult the computing resources recommendations in Scaling the Cluster Monitoring Operator and verify that you have sufficient resources.
1.1. Configurable monitoring components Copy linkLink copied to clipboard!
Review configurable monitoring components and their corresponding config map keys used to specify the components in the user-workload-monitoring-config config map.
| Component | user-workload-monitoring-config config map key |
|---|---|
| Prometheus Operator |
|
| Prometheus |
|
| Alertmanager |
|
| Thanos Ruler |
|
Different configuration changes to the ConfigMap object result in different outcomes:
- The pods are not redeployed. Therefore, there is no service outage.
The affected pods are redeployed:
- For single-node clusters, this results in temporary service outage.
- For multi-node clusters, because of high-availability, the affected pods are gradually rolled out and the monitoring stack remains available.
- Configuring and resizing a persistent volume always results in a service outage, regardless of high availability.
Each procedure that requires a change in the config map includes its expected outcome.
1.2. Enabling monitoring for user-defined projects Copy linkLink copied to clipboard!
Enable monitoring for user-defined projects in addition to the default platform monitoring. Monitor your own projects without the need for an additional monitoring solution. Using this feature centralizes monitoring for core platform components and user-defined projects.
Versions of Prometheus Operator installed using Operator Lifecycle Manager (OLM) are not compatible with user-defined monitoring. Therefore, custom Prometheus instances installed as a Prometheus custom resource (CR) managed by the OLM Prometheus Operator are not supported in OpenShift Container Platform.
1.2.1. Enabling monitoring for user-defined projects Copy linkLink copied to clipboard!
Cluster administrators can enable monitoring for user-defined projects by setting the enableUserWorkload: true field in the cluster monitoring ConfigMap object.
You must remove any custom Prometheus instances before enabling monitoring for user-defined projects.
You must have access to the cluster as a user with the cluster-admin cluster role to enable monitoring for user-defined projects in OpenShift Container Platform. Cluster administrators can then optionally grant users permission to configure the components that are responsible for monitoring user-defined projects.
Prerequisites
-
You have access to the cluster as a user with the
cluster-admincluster role. -
You have installed the OpenShift CLI (
oc). -
You have created the
cluster-monitoring-configConfigMapobject. You have optionally created and configured the
user-workload-monitoring-configConfigMapobject in theopenshift-user-workload-monitoringproject. You can add configuration options to thisConfigMapobject for the components that monitor user-defined projects.NoteEvery time you save configuration changes to the
user-workload-monitoring-configConfigMapobject, the pods in theopenshift-user-workload-monitoringproject are redeployed. It might sometimes take a while for these components to redeploy.
Procedure
Edit the
cluster-monitoring-configConfigMapobject:$ oc -n openshift-monitoring edit configmap cluster-monitoring-configAdd
enableUserWorkload: trueunderdata/config.yamlto enable monitoring for user-defined projects in a cluster:apiVersion: v1 kind: ConfigMap metadata: name: cluster-monitoring-config namespace: openshift-monitoring data: config.yaml: | enableUserWorkload: trueSave the file to apply the changes. Monitoring for user-defined projects is then enabled automatically.
NoteIf you enable monitoring for user-defined projects, the
user-workload-monitoring-configConfigMapobject is created by default.
Verification
Verify that the
prometheus-operator,prometheus-user-workload, andthanos-ruler-user-workloadpods are running in theopenshift-user-workload-monitoringproject. It might take a short while for the pods to start:$ oc -n openshift-user-workload-monitoring get podExample output:
NAME READY STATUS RESTARTS AGE prometheus-operator-6f7b748d5b-t7nbg 2/2 Running 0 3h prometheus-user-workload-0 4/4 Running 1 3h prometheus-user-workload-1 4/4 Running 1 3h thanos-ruler-user-workload-0 3/3 Running 0 3h thanos-ruler-user-workload-1 3/3 Running 0 3h
1.2.2. Granting users permission to configure monitoring for user-defined projects Copy linkLink copied to clipboard!
As a cluster administrator, you can assign the user-workload-monitoring-config-edit role to a user. This grants permission to configure and manage monitoring for user-defined projects without giving them permission to configure and manage core OpenShift Container Platform monitoring components.
Prerequisites
-
You have access to the cluster as a user with the
cluster-admincluster role. - The user account that you are assigning the role to already exists.
-
You have installed the OpenShift CLI (
oc).
Procedure
Assign the
user-workload-monitoring-config-editrole to a user in theopenshift-user-workload-monitoringproject:$ oc -n openshift-user-workload-monitoring adm policy add-role-to-user \ user-workload-monitoring-config-edit <user> \ --role-namespace openshift-user-workload-monitoring
Verification
Verify that the user is correctly assigned to the
user-workload-monitoring-config-editrole by displaying the related role binding:$ oc describe rolebinding <role_binding_name> -n openshift-user-workload-monitoringExample command:
$ oc describe rolebinding user-workload-monitoring-config-edit -n openshift-user-workload-monitoringExample output:
Name: user-workload-monitoring-config-edit Labels: <none> Annotations: <none> Role: Kind: Role Name: user-workload-monitoring-config-edit Subjects: Kind Name Namespace ---- ---- --------- User user1In this example,
user1is assigned to theuser-workload-monitoring-config-editrole.
1.3. Enabling alert routing for user-defined projects Copy linkLink copied to clipboard!
An administrator can enable alert routing for user-defined projects to allow developers and other users to configure alert routing for their custom alerts in user-defined projects.
This process consists of the following steps:
Enable alert routing for user-defined projects:
- Use the default platform Alertmanager instance.
- Use a separate Alertmanager instance only for user-defined projects.
- Grant users permission to configure alert routing for user-defined projects.
1.3.1. Enabling the platform Alertmanager instance for user-defined alert routing Copy linkLink copied to clipboard!
Cluster administrators can allow users to create user-defined alert routing configurations that use the main platform instance of Alertmanager to centralize alert management.
Prerequisites
-
You have access to the cluster as a user with the
cluster-admincluster role. - A cluster administrator has enabled monitoring for user-defined projects.
-
You have installed the OpenShift CLI (
oc).
Procedure
Edit the
cluster-monitoring-configConfigMapobject:$ oc -n openshift-monitoring edit configmap cluster-monitoring-configAdd
enableUserAlertmanagerConfig: truein thealertmanagerMainsection underdata/config.yaml:apiVersion: v1 kind: ConfigMap metadata: name: cluster-monitoring-config namespace: openshift-monitoring data: config.yaml: | # ... alertmanagerMain: enableUserAlertmanagerConfig: true # ...Setting the
enableUserAlertmanagerConfigvalue totrueallows users to create user-defined alert routing configurations that use the main platform instance of Alertmanager.- Save the file to apply the changes. The new configuration is applied automatically.
1.3.2. Enabling a separate Alertmanager instance for user-defined alert routing Copy linkLink copied to clipboard!
In some clusters, you might want to enable a dedicated Alertmanager instance for user-defined projects, which can help reduce the load on the default platform Alertmanager instance and can better separate user-defined alerts from default platform alerts.
Prerequisites
-
You have access to the cluster as a user with the
cluster-admincluster role. - You have enabled monitoring for user-defined projects.
-
You have installed the OpenShift CLI (
oc).
Procedure
Edit the
user-workload-monitoring-configConfigMapobject:$ oc -n openshift-user-workload-monitoring edit configmap user-workload-monitoring-configAdd
enabled: trueandenableAlertmanagerConfig: truein thealertmanagersection underdata/config.yaml:apiVersion: v1 kind: ConfigMap metadata: name: user-workload-monitoring-config namespace: openshift-user-workload-monitoring data: config.yaml: | alertmanager: enabled: true enableAlertmanagerConfig: truewhere:
alertmanager.enabled-
Defines whether to enable a dedicated instance of the Alertmanager for user-defined projects in a cluster. Set the value to
trueto enable orfalseto disable. If you set this value tofalseor if the key is omitted, user-defined alerts are routed to the default platform Alertmanager instance. alertmanager.enableAlertmanagerConfig-
Defines whether to enable users to define their own alert routing configurations with
AlertmanagerConfigobjects. Set the value totrueto enable orfalseto disable.
- Save the file to apply the changes. The dedicated instance of Alertmanager for user-defined projects starts automatically.
Verification
Verify that the
user-workloadAlertmanager instance has started:$ oc -n openshift-user-workload-monitoring get alertmanagerExample output:
NAME VERSION REPLICAS AGE user-workload 0.24.0 2 100s
1.3.3. Granting users permission to configure alert routing for user-defined projects Copy linkLink copied to clipboard!
Administrators can grant users permission to configure alert routing for user-defined projects. This enables developers and other users to configure notifications for their custom alerts in user-defined projects.
Prerequisites
-
You have access to the cluster as a user with the
cluster-admincluster role. - You have enabled monitoring for user-defined projects.
- The user account that you are assigning the role to already exists.
-
You have installed the OpenShift CLI (
oc).
Procedure
Assign the
alert-routing-editcluster role to a user in the user-defined project:$ oc -n <namespace> adm policy add-role-to-user alert-routing-edit <user>where:
<namespace>- Specifies the namespace for the user-defined project.
<user>- Specifies the username for the account to which you want to assign the role.
1.4. Granting users permissions for monitoring for user-defined projects Copy linkLink copied to clipboard!
As a cluster administrator, you can monitor all core platform and user-defined projects. To delegate user workload monitoring capabilities to other users, assign different permission levels.
You can grant permissions for different monitoring activities:
- Monitoring user-defined projects
- Configuring the components that monitor user-defined projects
- Configuring alert routing for user-defined projects
- Managing alerts and silences for user-defined projects
You can grant the permissions by assigning one of the following monitoring roles or cluster roles:
| Role name | Description | Project |
|---|---|---|
|
|
Users with this role can edit the |
|
|
| Users with this role have read access to the user-defined Alertmanager API for all projects, if the user-defined Alertmanager is enabled. |
|
|
| Users with this role have read and write access to the user-defined Alertmanager API for all projects, if the user-defined Alertmanager is enabled. |
|
| Cluster role name | Description | Project |
|---|---|---|
|
|
Users with this cluster role have read access to |
Can be bound with |
|
|
Users with this cluster role can create, modify, and delete |
Can be bound with |
|
|
Users with this cluster role have the same privileges as users with the |
Can be bound with |
|
|
Users with this cluster role can create, update, and delete |
Can be bound with |
|
| Users with this cluster role can access Thanos API endpoints for user-defined projects. |
Can be bound with |
1.4.1. Granting user permissions by using the web console Copy linkLink copied to clipboard!
Cluster administrators can grant users permissions for the openshift-monitoring project or their own projects, by using the OpenShift Container Platform web console.
Prerequisites
-
You have access to the cluster as a user with the
cluster-admincluster role. - The user account that you are assigning the role to already exists.
Procedure
-
In the OpenShift Container Platform web console, go to User Management
RoleBindings Create binding. - In the Binding Type section, select the Namespace Role Binding type.
- In the Name field, enter a name for the role binding.
In the Namespace field, select the project where you want to grant the access.
ImportantThe monitoring role or cluster role permissions that you grant to a user by using this procedure apply only to the project that you select in the Namespace field.
- Select a monitoring role or cluster role from the Role Name list.
- In the Subject section, select User.
- In the Subject Name field, enter the name of the user.
- Select Create to apply the role binding.
1.4.2. Granting user permissions by using the CLI Copy linkLink copied to clipboard!
Cluster administrators can grant users permissions to monitor their own projects, by using the OpenShift CLI (oc).
Whichever role or cluster role you choose, you must bind it against a specific project as a cluster administrator.
Prerequisites
-
You have access to the cluster as a user with the
cluster-admincluster role. - The user account that you are assigning the role to already exists.
-
You have installed the OpenShift CLI (
oc).
Procedure
To assign a monitoring role to a user for a project, enter the following command:
$ oc adm policy add-role-to-user <role> <user> -n <namespace> --role-namespace <namespace>where:
<role>- Specifies the wanted monitoring role.
<user>- Specifies the user to whom you want to assign the role.
<namespace>- Specifies the project where you want to grant the access.
To assign a monitoring cluster role to a user for a project, enter the following command:
$ oc adm policy add-cluster-role-to-user <cluster-role> <user> -n <namespace>where:
<cluster-role>- Specifies the wanted monitoring cluster role.
<user>- Specifies the user to whom you want to assign the cluster role.
<namespace>- Specifies the project where you want to grant the access.
1.5. Excluding a user-defined project from monitoring Copy linkLink copied to clipboard!
Exclude individual user-defined projects from monitoring by adding the openshift.io/user-monitoring=false label to the project’s namespace. For example, you can use this to exclude test environments, reduce monitoring overhead, or meet compliance requirements.
Procedure
Add the label to the project namespace:
$ oc label namespace my-project 'openshift.io/user-monitoring=false'To re-enable monitoring, remove the label from the namespace:
$ oc label namespace my-project 'openshift.io/user-monitoring-'NoteIf there were any active monitoring targets for the project, it may take a few minutes for Prometheus to stop scraping them after adding the label.
1.6. Disabling monitoring for user-defined projects Copy linkLink copied to clipboard!
After enabling monitoring for user-defined projects, you can disable it again by setting enableUserWorkload: false in the cluster-monitoring-config config map if you no longer require monitoring of your applications.
Alternatively, you can remove enableUserWorkload: true to disable monitoring for user-defined projects.
Procedure
Edit the
cluster-monitoring-configConfigMapobject:$ oc -n openshift-monitoring edit configmap cluster-monitoring-configSet
enableUserWorkload:tofalseunderdata/config.yaml:apiVersion: v1 kind: ConfigMap metadata: name: cluster-monitoring-config namespace: openshift-monitoring data: config.yaml: | enableUserWorkload: false- Save the file to apply the changes. Monitoring for user-defined projects is then disabled automatically.
Verification
Verify that the
prometheus-operator,prometheus-user-workloadandthanos-ruler-user-workloadpods are terminated in theopenshift-user-workload-monitoringproject. This might take a short while:$ oc -n openshift-user-workload-monitoring get podExample output:
No resources found in openshift-user-workload-monitoring project.
The user-workload-monitoring-config ConfigMap object in the openshift-user-workload-monitoring project is not automatically deleted when monitoring for user-defined projects is disabled. This is to preserve any custom configurations that you may have created in the ConfigMap object.