|
| 1 | +// Module included in the following assemblies: |
| 2 | +// |
| 3 | +// * security/external_secrets_operator/exteernal-secrets-monitoring.adoc |
| 4 | + |
| 5 | +:_mod-docs-content-type: PROCEDURE |
| 6 | +[id="external-secrets-enable-metrics_{context}"] |
| 7 | += Configuring metrics collection for {external-secrets-operator} operands by using a ServiceMonitor |
| 8 | + |
| 9 | +[role="_abstract"] |
| 10 | +The {external-secrets-operator} operands exposes metrics by default on port `8080` at the `/metrics` service endpoint for all three components (`external-secrets`, `external-secrets-cert-controll`, and `external-secrets-webhook`). You can configure metrics collection for the external-secrets operands 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 | +.Prerequisites |
| 13 | + |
| 14 | +* You have access to the cluster as a user with the `cluster-admin` role. |
| 15 | +* You have installed the {external-secrets-operator}. |
| 16 | +* You have enabled the user workload monitoring. |
| 17 | +
|
| 18 | +.Procedure |
| 19 | + |
| 20 | +. Create the `ClusterRoleBinding` resource required for granting permissions to access metrics: |
| 21 | + |
| 22 | +.. Create the `clusterrolebinding-external-secrets.yaml` YAML file: |
| 23 | ++ |
| 24 | +The following example shows a `cluserrolebinding-external-secrets.yaml` file. |
| 25 | ++ |
| 26 | +[source,yaml] |
| 27 | +---- |
| 28 | +apiVersion: rbac.authorization.k8s.io/v1 |
| 29 | +kind: ClusterRoleBinding |
| 30 | +metadata: |
| 31 | + labels: |
| 32 | + app: external-secrets |
| 33 | + name: external-secrets-allow-metrics-access |
| 34 | +roleRef: |
| 35 | + apiGroup: rbac.authorization.k8s.io |
| 36 | + kind: ClusterRole |
| 37 | + name: external-secrets-operator-metrics-reader |
| 38 | +subjects: |
| 39 | + - kind: ServiceAccount |
| 40 | + name: external-secrets |
| 41 | + namespace: external-secrets |
| 42 | + - kind: ServiceAccount |
| 43 | + name: external-secrets-cert-controller |
| 44 | + namespace: external-secrets |
| 45 | + - kind: ServiceAccount |
| 46 | + name: external-secrets-webhook |
| 47 | + namespace: external-secrets |
| 48 | +---- |
| 49 | + |
| 50 | +.. Create the `ClusterRoldeBinding` custom resource by running the following command: |
| 51 | ++ |
| 52 | +[source,terminal] |
| 53 | +---- |
| 54 | +$ oc apply -f clusterrolebinding-external-secrets.yaml |
| 55 | +---- |
| 56 | + |
| 57 | +. Create the `ServiceMonitor` CR: |
| 58 | + |
| 59 | +.. Create the `servicemonitor-external-secrets.yaml` YAML file: |
| 60 | ++ |
| 61 | +[source,yaml] |
| 62 | +---- |
| 63 | +apiVersion: monitoring.coreos.com/v1 |
| 64 | +kind: ServiceMonitor |
| 65 | +metadata: |
| 66 | + labels: |
| 67 | + app: external-secrets |
| 68 | + name: external-secrets-metrics-monitor |
| 69 | + namespace: external-secrets |
| 70 | +spec: |
| 71 | + endpoints: |
| 72 | + - interval: 60s |
| 73 | + path: /metrics |
| 74 | + port: metrics |
| 75 | + scheme: http |
| 76 | + scrapeTimeout: 30s |
| 77 | + namespaceSelector: |
| 78 | + matchNames: |
| 79 | + - external-secrets |
| 80 | + selector: |
| 81 | + matchExpressions: |
| 82 | + - key: app.kubernetes.io/name |
| 83 | + operator: In |
| 84 | + values: |
| 85 | + - external-secrets |
| 86 | + - external-secrets-cert-controller |
| 87 | + - external-secrets-webhook |
| 88 | + - key: app.kubernetes.io/instance |
| 89 | + operator: In |
| 90 | + values: |
| 91 | + - external-secrets |
| 92 | + - key: app.kubernetes.io/managed-by |
| 93 | + operator: In |
| 94 | + values: |
| 95 | + - external-secrets-operator |
| 96 | +---- |
| 97 | + |
| 98 | +.. Create the `ServiceMonitor` CR by running the following command: |
| 99 | ++ |
| 100 | +[source,terminal] |
| 101 | +---- |
| 102 | +$ oc apply -f servicemonitor-external-secrets.yaml |
| 103 | +---- |
| 104 | ++ |
| 105 | +After the `ServiceMonitor` CR is created, the user workload Prometheus instance begins metrics collection from the {external-secrets-operator} operands. The collected metrics are labeled with `job="external-secrets"`,`job="external-secrets-cainjector"`, and `job="external-secrets-webhook"`. |
| 106 | + |
| 107 | +.Verification |
| 108 | + |
| 109 | +. In the {product-title} web console, navigate to *Observe* -> *Targets*. |
| 110 | + |
| 111 | +. In the Label filter field, enter the following labels to filter the metrics targets for each operand: |
| 112 | ++ |
| 113 | +[source,terminal] |
| 114 | +---- |
| 115 | +$ service=external-secrets |
| 116 | +---- |
| 117 | ++ |
| 118 | +[source,terminal] |
| 119 | +---- |
| 120 | +$ service=external-secrets-cert-controller-metrics |
| 121 | +---- |
| 122 | ++ |
| 123 | +[source,terminal] |
| 124 | +---- |
| 125 | +$ service=external-secrets-webhook |
| 126 | +---- |
| 127 | + |
| 128 | +. Confirm that the *Status* column shows `Up` for the `external-secrets`, `external-secrets-cert-controller` and `external-secrets-webhook`. |
0 commit comments