|
| 1 | +// Module included in the following assemblies: |
| 2 | +// |
| 3 | +// * security/zer_trust_workload_identity_manager/zero-trust-manager-monitoring.adoc |
| 4 | + |
| 5 | +:_mod-docs-content-type: PROCEDURE |
| 6 | +[id="zero-trust-manager-enable-metrics-operator_{context}"] |
| 7 | += Configuring metrics collection for the Operator by using a ServiceMonitor |
| 8 | + |
| 9 | +[role="_abstract"] |
| 10 | +The {zero-trust-full} exposes metrics by default on port 8443 at the `/metrics` service endpoint. You can configure metrics collection for the Operator by creating a `ServiceMonitor` custom resource (CR) that enables the Prometheus Operator to collect custom metrics. For more information, see "Configuring user workload monitoring". |
| 11 | + |
| 12 | + |
| 13 | +The SPIRE Server operand exposes metrics by default on port `9402` at the `/metrics` endpoint. You can configure metrics collection for the SPIRE Server by creating a `ServiceMonitor` custom resource (CR) that enables the Prometheus Operator to collect custom metrics. |
| 14 | + |
| 15 | + |
| 16 | +.Prerequisites |
| 17 | + |
| 18 | +* You have access to the cluster as a user with the `cluster-admin` cluster role. |
| 19 | +
|
| 20 | +* You have installed the {zero-trust-full}. |
| 21 | +
|
| 22 | +* You have enabled the user workload monitoring. |
| 23 | +
|
| 24 | +.Procedure |
| 25 | + |
| 26 | +. Configure the Operator to use HTTP or HTTPS protocols for the metrics server. |
| 27 | + |
| 28 | +.. Update the subscription object for {zero-trust-full} to configure the HTTP protocol by running the following command: |
| 29 | ++ |
| 30 | +[source,terminal] |
| 31 | +---- |
| 32 | +$ oc -n zero-trust-workload-identity-manager patch subscription zero-trust-workload-identity-manager-subscription --type='merge' -p '{"spec":{"config":{"env":[{"name":"METRICS_BIND_ADDRESS","value":":8080"}, {"name": "METRICS_SECURE", "value": "false"}]}}}' |
| 33 | +---- |
| 34 | + |
| 35 | +.. Verify the {zero-trust-full} pod is redeployed and that the configured values for `METRICS_BIND_ADDRESS` and `METRICS_SECURE` is updated by running the following command: |
| 36 | ++ |
| 37 | +[source,terminal] |
| 38 | +---- |
| 39 | +$ oc set env --list deployment/zero-trust-workload-identity-manager-controller-manager -n zero-trust-workload-identity-manager | grep -e METRICS_BIND_ADDRESS -e METRICS_SECURE -e container |
| 40 | +---- |
| 41 | ++ |
| 42 | +.Example output |
| 43 | +[source,text] |
| 44 | +---- |
| 45 | +deployments/zero-trust-workload-identity-manager-controller-manager, container manager |
| 46 | +METRICS_BIND_ADDRESS=:8080 |
| 47 | +METRICS_SECURE=false |
| 48 | +---- |
| 49 | + |
| 50 | +. Create the `Secret` resource with `kubernetes.io/service-account.name` annotation to inject the token required for authenticating with the metrics server. |
| 51 | + |
| 52 | +.. Create the `secret-zero-trust-workload-identity-manager.yaml` YAML file: |
| 53 | ++ |
| 54 | +[source,yaml] |
| 55 | +---- |
| 56 | +apiVersion: v1 |
| 57 | +kind: Secret |
| 58 | +metadata: |
| 59 | + labels: |
| 60 | + name: zero-trust-workload-identity-manager |
| 61 | + name: zero-trust-workload-identity-manager-metrics-auth |
| 62 | + namespace: zero-trust-workload-identity-manager |
| 63 | + annotations: |
| 64 | + kubernetes.io/service-account.name: zero-trust-workload-identity-manager-controller-manager |
| 65 | +type: kubernetes.io/service-account-token |
| 66 | +---- |
| 67 | + |
| 68 | +.. Create the `Secret` resource by running the following command: |
| 69 | ++ |
| 70 | +[source,terminal] |
| 71 | +---- |
| 72 | +$ oc apply -f secret-zero-trust-workload-identity-manager.yaml |
| 73 | +---- |
| 74 | + |
| 75 | +. Create the `ClusterRoleBinding` resource required for granting permissions to access the metrics. |
| 76 | + |
| 77 | +.. Create the `clusterrolebinding-zero-trust-workload-identity-manager.yaml` YAML file: |
| 78 | ++ |
| 79 | +[source,yaml] |
| 80 | +---- |
| 81 | +apiVersion: rbac.authorization.k8s.io/v1 |
| 82 | +kind: ClusterRoleBinding |
| 83 | +metadata: |
| 84 | + labels: |
| 85 | + name: zero-trust-workload-identity-manager |
| 86 | + name: zero-trust-workload-identity-manager-allow-metrics-access |
| 87 | +roleRef: |
| 88 | + apiGroup: rbac.authorization.k8s.io |
| 89 | + kind: ClusterRole |
| 90 | + name: zero-trust-workload-identity-manager-metrics-reader |
| 91 | +subjects: |
| 92 | +- kind: ServiceAccount |
| 93 | + name: zero-trust-workload-identity-manager-controller-manager |
| 94 | + namespace: zero-trust-workload-identity-manager |
| 95 | +---- |
| 96 | + |
| 97 | +.. Create the `ClusterRoleBinding` resource by running the following command: |
| 98 | ++ |
| 99 | +[source,terminal] |
| 100 | +---- |
| 101 | +$ oc apply -f clusterrolebinding-zero-trust-workload-identity-manager.yaml |
| 102 | +---- |
| 103 | + |
| 104 | +. Create the following `ServiceMonitor` CR if the metrics server is configured to use `http`. |
| 105 | + |
| 106 | +.. Create the `servicemonitor-zero-trust-workload-identity-manager-http.yaml` YAML file: |
| 107 | ++ |
| 108 | +[source,yaml] |
| 109 | +---- |
| 110 | +apiVersion: monitoring.coreos.com/v1 |
| 111 | +kind: ServiceMonitor |
| 112 | +metadata: |
| 113 | + labels: |
| 114 | + name: zero-trust-workload-identity-manager |
| 115 | + name: zero-trust-workload-identity-manager-metrics-monitor |
| 116 | + namespace: zero-trust-workload-identity-manager |
| 117 | +spec: |
| 118 | + endpoints: |
| 119 | + - authorization: |
| 120 | + credentials: |
| 121 | + name: zero-trust-workload-identity-manager-metrics-auth |
| 122 | + key: token |
| 123 | + type: Bearer |
| 124 | + interval: 60s |
| 125 | + path: /metrics |
| 126 | + port: metrics-http |
| 127 | + scheme: http |
| 128 | + scrapeTimeout: 30s |
| 129 | + namespaceSelector: |
| 130 | + matchNames: |
| 131 | + - zero-trust-workload-identity-manager |
| 132 | + selector: |
| 133 | + matchLabels: |
| 134 | + name: zero-trust-workload-identity-manager |
| 135 | +---- |
| 136 | + |
| 137 | +.. Create the `ServiceMonitor` CR by running the following command: |
| 138 | ++ |
| 139 | +[source,terminal] |
| 140 | +---- |
| 141 | +$ oc apply -f servicemonitor-zero-trust-workload-identity-manager-http.yaml |
| 142 | +---- |
| 143 | +. Create the following `ServiceMonitor` CR if the metrics server is configured to use `https`. |
| 144 | + |
| 145 | +.. Create the `servicemonitor-zero-trust-workload-identity-manager-https.yaml` YAML file: |
| 146 | ++ |
| 147 | +[source,yaml] |
| 148 | +---- |
| 149 | +apiVersion: monitoring.coreos.com/v1 |
| 150 | +kind: ServiceMonitor |
| 151 | +metadata: |
| 152 | + labels: |
| 153 | + name: zero-trust-workload-identity-manager |
| 154 | + name: zero-trust-workload-identity-manager-metrics-monitor |
| 155 | + namespace: zero-trust-workload-identity-manager |
| 156 | +spec: |
| 157 | + endpoints: |
| 158 | + - authorization: |
| 159 | + credentials: |
| 160 | + name: zero-trust-workload-identity-manager-metrics-auth |
| 161 | + key: token |
| 162 | + type: Bearer |
| 163 | + interval: 60s |
| 164 | + path: /metrics |
| 165 | + port: metrics-https |
| 166 | + scheme: https |
| 167 | + scrapeTimeout: 30s |
| 168 | + tlsConfig: |
| 169 | + ca: |
| 170 | + configMap: |
| 171 | + name: openshift-service-ca.crt |
| 172 | + key: service-ca.crt |
| 173 | + serverName: zero-trust-workload-identity-manager-metrics-service.zero-trust-workload-identity-manager.svc.cluster.local |
| 174 | + namespaceSelector: |
| 175 | + matchNames: |
| 176 | + - zero-trust-workload-identity-manager |
| 177 | + selector: |
| 178 | + matchLabels: |
| 179 | + name: zero-trust-workload-identity-manager |
| 180 | +---- |
| 181 | + |
| 182 | +.. Create the `ServiceMonitor` CR by running the following command: |
| 183 | ++ |
| 184 | +[source,terminal] |
| 185 | +---- |
| 186 | +$ oc apply -f servicemonitor-zero-trust-workload-identity-manager-https.yaml |
| 187 | +---- |
| 188 | ++ |
| 189 | +After the `ServiceMonitor` CR is created, the user workload Prometheus instance begins metrics collection from the SPIRE Server. The collected metrics are labeled with `job="zero-trust-workload-identity-manager-metrics-service"`. |
| 190 | + |
| 191 | +.Verification |
| 192 | + |
| 193 | +. In the {product-title} web console, navigate to *Observe* → *Targets*. |
| 194 | + |
| 195 | +. In the *Label* filter field, enter the following label to filter the metrics targets: |
| 196 | ++ |
| 197 | +[source,terminal] |
| 198 | +---- |
| 199 | +$ service=zero-trust-workload-identity-manager-metrics-service |
| 200 | +---- |
| 201 | + |
| 202 | +. Confirm that the *Status* column shows `Up` for the `zero-trust-workload-identity-manager` entry. |
| 203 | + |
0 commit comments