|
4 | 4 |
|
5 | 5 | :_mod-docs-content-type: PROCEDURE |
6 | 6 | [id="cert-manager-enable-metrics_{context}"] |
7 | | -= Enabling monitoring by using a service monitor for the {cert-manager-operator} |
| 7 | += Configuring metrics collection for {cert-manager-operator} operands by using a ServiceMonitor |
8 | 8 |
|
9 | | -You can enable monitoring and metrics collection for the {cert-manager-operator} by using a service monitor to perform the custom metrics scraping. |
| 9 | +The {cert-manager-operator} operands exposes metrics by default on port `9402` at the `/metrics` service endpoint. You can configure metrics collection for the cert-manager operands by creating a `ServiceMonitor` custom resource (CR) that enables Prometheus Operator to collect custom metrics. For more information, see "Configuring user workload monitoring". |
10 | 10 |
|
11 | 11 | .Prerequisites |
12 | 12 |
|
13 | | -* You have access to the cluster with `cluster-admin` privileges. |
14 | | -* The {cert-manager-operator} is installed. |
| 13 | +* You have access to the cluster as a user with the `cluster-admin` role. |
| 14 | +* You have installed the {cert-manager-operator}. |
| 15 | +* You have enabled the user workload monitoring. |
15 | 16 |
|
16 | 17 | .Procedure |
17 | 18 |
|
18 | | -. Add the label to enable cluster monitoring by running the following command: |
19 | | -+ |
20 | | -[source,terminal] |
21 | | ----- |
22 | | -$ oc label namespace cert-manager openshift.io/cluster-monitoring=true |
23 | | ----- |
| 19 | +. Create the `ServiceMonitor` CR: |
24 | 20 |
|
25 | | -. Create a service monitor: |
26 | | - |
27 | | -.. Create a YAML file that defines the `Role`, `RoleBinding`, and `ServiceMonitor` objects: |
| 21 | +.. Create the YAML file that defines the `ServiceMonitor` CR: |
28 | 22 | + |
29 | | -.Example `monitoring.yaml` file |
30 | | - |
| 23 | +.Example `servicemonitor-cert-manager.yaml` file |
31 | 24 | [source,yaml] |
32 | 25 | ---- |
33 | | -apiVersion: rbac.authorization.k8s.io/v1 |
34 | | -kind: Role |
35 | | -metadata: |
36 | | - name: prometheus-k8s |
37 | | - namespace: cert-manager |
38 | | -rules: |
39 | | -- apiGroups: |
40 | | - - "" |
41 | | - resources: |
42 | | - - services |
43 | | - - endpoints |
44 | | - - pods |
45 | | - verbs: |
46 | | - - get |
47 | | - - list |
48 | | - - watch |
49 | | ---- |
50 | | -apiVersion: rbac.authorization.k8s.io/v1 |
51 | | -kind: RoleBinding |
52 | | -metadata: |
53 | | - name: prometheus-k8s |
54 | | - namespace: cert-manager |
55 | | -roleRef: |
56 | | - apiGroup: rbac.authorization.k8s.io |
57 | | - kind: Role |
58 | | - name: prometheus-k8s |
59 | | -subjects: |
60 | | -- kind: ServiceAccount |
61 | | - name: prometheus-k8s |
62 | | - namespace: openshift-monitoring |
63 | | ---- |
64 | 26 | apiVersion: monitoring.coreos.com/v1 |
65 | 27 | kind: ServiceMonitor |
66 | 28 | metadata: |
67 | 29 | labels: |
68 | 30 | app: cert-manager |
69 | | - app.kubernetes.io/component: controller |
70 | 31 | app.kubernetes.io/instance: cert-manager |
71 | 32 | app.kubernetes.io/name: cert-manager |
72 | 33 | name: cert-manager |
73 | 34 | namespace: cert-manager |
74 | 35 | spec: |
75 | 36 | endpoints: |
76 | | - - interval: 30s |
77 | | - port: tcp-prometheus-servicemonitor |
78 | | - scheme: http |
| 37 | + - honorLabels: false |
| 38 | + interval: 60s |
| 39 | + path: /metrics |
| 40 | + scrapeTimeout: 30s |
| 41 | + targetPort: 9402 |
79 | 42 | selector: |
80 | | - matchLabels: |
81 | | - app.kubernetes.io/component: controller |
82 | | - app.kubernetes.io/instance: cert-manager |
83 | | - app.kubernetes.io/name: cert-manager |
| 43 | + matchExpressions: |
| 44 | + - key: app.kubernetes.io/name |
| 45 | + operator: In |
| 46 | + values: |
| 47 | + - cainjector |
| 48 | + - cert-manager |
| 49 | + - webhook |
| 50 | + - key: app.kubernetes.io/instance |
| 51 | + operator: In |
| 52 | + values: |
| 53 | + - cert-manager |
| 54 | + - key: app.kubernetes.io/component |
| 55 | + operator: In |
| 56 | + values: |
| 57 | + - cainjector |
| 58 | + - controller |
| 59 | + - webhook |
| 60 | +---- |
| 61 | + |
| 62 | +.. Create the `ServiceMonitor` CR by running the following command: |
| 63 | ++ |
| 64 | +[source,terminal] |
84 | 65 | ---- |
| 66 | +$ oc apply -f servicemonitor-cert-manager.yaml |
| 67 | +---- |
| 68 | ++ |
| 69 | +After the `ServiceMonitor` CR is created, the user workload Prometheus instance begins metrics collection from the {cert-manager-operator} operands. The collected metrics are labeled with `job="cert-manager"`,`job="cert-manager-cainjector"`, and `job="cert-manager-webhook"`. |
| 70 | + |
| 71 | +.Verification |
| 72 | + |
| 73 | +. In the {product-title} web console, navigate to *Observe* → *Targets*. |
85 | 74 |
|
86 | | -.. Create the `Role`, `RoleBinding`, and `ServiceMonitor` objects by running the following command: |
| 75 | +. In the *Label* filter field, enter the following labels to filter the metrics targets for each operand: |
| 76 | ++ |
| 77 | +[source,terminal] |
| 78 | +---- |
| 79 | +$ service=cert-manager |
| 80 | +---- |
87 | 81 | + |
88 | 82 | [source,terminal] |
89 | 83 | ---- |
90 | | -$ oc create -f monitoring.yaml |
91 | | ----- |
| 84 | +$ service=cert-manager-webhook |
| 85 | +---- |
| 86 | ++ |
| 87 | +[source,terminal] |
| 88 | +---- |
| 89 | +$ service=cert-manager-cainjector |
| 90 | +---- |
| 91 | + |
| 92 | +. Confirm that the *Status* column shows `Up` for the `cert-manager`, `cert-manager-webhook`, and `cert-manager-cainjector` entries. |
0 commit comments