|
| 1 | +// Module included in the following assemblies: |
| 2 | +// |
| 3 | +// * security/external_secrets_operator/external-secrets-operator-monitoring.adoc |
| 4 | + |
| 5 | +:_mod-docs-content-type: PROCEDURE |
| 6 | +[id="external-secrets-enable-metrics_{context}"] |
| 7 | += Enabling monitoring for the {external-secrets-operator} by using a service monitor |
| 8 | + |
| 9 | +Enable monitoring and metrics collection for the {external-secrets-operator} by using a service monitor to perform the custom metrics scraping. |
| 10 | + |
| 11 | +.Prerequisites |
| 12 | + |
| 13 | +* You have access to the cluster with `cluster-admin` privileges. |
| 14 | +* The {external-secrets-operator-short} is installed. |
| 15 | +
|
| 16 | +.Procedure |
| 17 | + |
| 18 | +. Enable cluster monitoring by labeling the {external-secrets-operator-short} namespace by running the following command: |
| 19 | ++ |
| 20 | +[source,terminal] |
| 21 | +---- |
| 22 | +$ oc label namespace external-secrets-operator openshift.io/cluster-monitoring=true |
| 23 | +---- |
| 24 | + |
| 25 | +. Create a YAML file that defines the `Role`, `RoleBinding`, and `ServiceMonitor` objects: |
| 26 | ++ |
| 27 | +.Example `monitoring.yaml` file |
| 28 | +[source,yaml] |
| 29 | +---- |
| 30 | +apiVersion: rbac.authorization.k8s.io/v1 |
| 31 | +kind: Role |
| 32 | +metadata: |
| 33 | + name: prometheus-k8s |
| 34 | + namespace: external-secrets-operator |
| 35 | +rules: |
| 36 | +- apiGroups: |
| 37 | + - "" |
| 38 | + resources: |
| 39 | + - services |
| 40 | + - endpoints |
| 41 | + - pods |
| 42 | + verbs: |
| 43 | + - get |
| 44 | + - list |
| 45 | + - watch |
| 46 | +--- |
| 47 | +apiVersion: rbac.authorization.k8s.io/v1 |
| 48 | +kind: RoleBinding |
| 49 | +metadata: |
| 50 | + name: prometheus-k8s |
| 51 | + namespace: external-secrets-operator |
| 52 | +roleRef: |
| 53 | + apiGroup: rbac.authorization.k8s.io |
| 54 | + kind: Role |
| 55 | + name: prometheus-k8s |
| 56 | +subjects: |
| 57 | +- kind: ServiceAccount |
| 58 | + name: prometheus-k8s |
| 59 | + namespace: external-secrets-operator |
| 60 | +--- |
| 61 | +apiVersion: monitoring.coreos.com/v1 |
| 62 | +kind: ServiceMonitor |
| 63 | +metadata: |
| 64 | + labels: |
| 65 | + app: external-secrets |
| 66 | + app.kubernetes.io/component: controller |
| 67 | + app.kubernetes.io/instance: external-secrets |
| 68 | + app.kubernetes.io/name: external-secrets |
| 69 | + name: external-secrets |
| 70 | + namespace: external-secrets-operator |
| 71 | +spec: |
| 72 | + endpoints: |
| 73 | + - interval: 30s |
| 74 | + port: tcp-prometheus-servicemonitor |
| 75 | + scheme: http |
| 76 | + selector: |
| 77 | + matchLabels: |
| 78 | + app.kubernetes.io/component: controller |
| 79 | + app.kubernetes.io/instance: external-secrets |
| 80 | +app.kubernetes.io/name: external-secrets |
| 81 | +---- |
| 82 | + |
| 83 | +. Create the `Role`, `RoleBinding`, and `ServiceMonitor` objects by running the following command: |
| 84 | ++ |
| 85 | +[source,terminal] |
| 86 | +---- |
| 87 | +$ oc create -f monitoring.yaml |
| 88 | +---- |
| 89 | + |
0 commit comments