Skip to content

Commit 91dad5f

Browse files
(doc): Add a doc as a guidance to help users know how to consume the metrics and integrate it with other solutions
1 parent 46cec30 commit 91dad5f

File tree

1 file changed

+289
-0
lines changed

1 file changed

+289
-0
lines changed
Lines changed: 289 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,289 @@
1+
# Consuming Metrics
2+
3+
!!! warning
4+
The metrics endpoints and their associated ports are available for use but are in Alpha maturity and subject to change.
5+
This information is provided as general guidance and is not a guaranteed or officially supported solution.
6+
Additionally, any examples involving third-party solutions such as Prometheus are for reference only and are not officially supported.
7+
8+
Operator-Controller and CatalogD are configured to export metrics by default. The metrics are exposed on the `/metrics` endpoint of the respective services.
9+
10+
The metrics are secured by [RBAC policies][rbac-k8s-docs], requiring appropriate permissions for access.
11+
By default, they are exposed over HTTPS, necessitating valid certificates for integration with services like Prometheus.
12+
The following sections cover enabling metrics, validating access, and integrating with the [Prometheus Operator][prometheus-operator].
13+
14+
Below, you will learn how to enable the metrics, validate access, and integrate with [Prometheus Operator][prometheus-operator].
15+
16+
---
17+
18+
## Operator-Controller Metrics
19+
20+
### Step 1: Enable Access
21+
22+
To enable access to the Operator-Controller metrics, create a `ClusterRoleBinding` to
23+
allow the Operator-Controller service account to access the metrics.
24+
25+
```shell
26+
kubectl create clusterrolebinding operator-controller-metrics-binding \
27+
--clusterrole=operator-controller-metrics-reader \
28+
--serviceaccount=olmv1-system:operator-controller-controller-manager
29+
```
30+
31+
### Step 2: Validate Access Manually
32+
33+
#### Create a Token and Extract Certificates
34+
35+
Generate a token for the service account and extract the required certificates:
36+
37+
```shell
38+
TOKEN=$(kubectl create token operator-controller-controller-manager -n olmv1-system)
39+
echo $TOKEN
40+
```
41+
42+
#### Deploy a Pod to Consume Metrics
43+
44+
Ensure that the Pod is deployed in a namespace labeled to enforce restricted permissions. Apply the following:
45+
46+
```shell
47+
kubectl apply -f - <<EOF
48+
apiVersion: v1
49+
kind: Pod
50+
metadata:
51+
name: curl-metrics
52+
namespace: olmv1-system
53+
spec:
54+
serviceAccountName: operator-controller-controller-manager
55+
containers:
56+
- name: curl
57+
image: curlimages/curl:latest
58+
command:
59+
- sh
60+
- -c
61+
- sleep 3600
62+
securityContext:
63+
runAsNonRoot: true
64+
readOnlyRootFilesystem: true
65+
runAsUser: 1000
66+
runAsGroup: 1000
67+
allowPrivilegeEscalation: false
68+
capabilities:
69+
drop:
70+
- ALL
71+
volumeMounts:
72+
- mountPath: /tmp/cert
73+
name: olm-cert
74+
readOnly: true
75+
volumes:
76+
- name: olm-cert
77+
secret:
78+
secretName: olmv1-cert
79+
securityContext:
80+
runAsNonRoot: true
81+
restartPolicy: Never
82+
EOF
83+
```
84+
85+
#### Access the Pod and Test Metrics
86+
87+
Access the pod:
88+
89+
```shell
90+
kubectl exec -it curl-metrics -n olmv1-system -- sh
91+
```
92+
93+
From the shell use the `TOKEN` value obtained above to check the metrics:
94+
95+
```shell
96+
curl -v -k -H "Authorization: Bearer <TOKEN>" \
97+
https://operator-controller-controller-manager-metrics-service.olmv1-system.svc.cluster.local:8443/metrics
98+
```
99+
100+
Validate using certificates and token:
101+
102+
```shell
103+
curl -v --cacert /tmp/cert/ca.crt --cert /tmp/cert/tls.crt --key /tmp/cert/tls.key \
104+
-H "Authorization: Bearer <TOKEN>" \
105+
https://operator-controller-controller-manager-metrics-service.olmv1-system.svc.cluster.local:8443/metrics
106+
```
107+
108+
---
109+
110+
## CatalogD Metrics
111+
112+
### Step 1: Enable Access
113+
114+
To enable access to the CatalogD metrics, create a `ClusterRoleBinding` for the CatalogD service account:
115+
116+
```shell
117+
kubectl create clusterrolebinding catalogd-metrics-binding \
118+
--clusterrole=catalogd-metrics-reader \
119+
--serviceaccount=olmv1-system:catalogd-controller-manager
120+
```
121+
122+
### Step 2: Validate Access Manually
123+
124+
#### Create a Token and Extract Certificates
125+
126+
Generate a token and get the required certificates:
127+
128+
```shell
129+
TOKEN=$(kubectl create token catalogd-controller-manager -n olmv1-system)
130+
echo $TOKEN
131+
```
132+
133+
#### Deploy a Pod to Consume Metrics
134+
135+
From the shell use the `TOKEN` value obtained above to check the metrics:
136+
137+
```shell
138+
OLM_SECRET=$(kubectl get secret -n olmv1-system -o jsonpath="{.items[?(@.metadata.name | startswith('catalogd-service-cert'))].metadata.name}")
139+
```
140+
141+
```shell
142+
kubectl apply -f - <<EOF
143+
apiVersion: v1
144+
kind: Pod
145+
metadata:
146+
name: curl-metrics-catalogd
147+
namespace: olmv1-system
148+
spec:
149+
serviceAccountName: catalogd-controller-manager
150+
containers:
151+
- name: curl
152+
image: curlimages/curl:latest
153+
command:
154+
- sh
155+
- -c
156+
- sleep 3600
157+
securityContext:
158+
runAsNonRoot: true
159+
readOnlyRootFilesystem: true
160+
runAsUser: 1000
161+
runAsGroup: 1000
162+
allowPrivilegeEscalation: false
163+
capabilities:
164+
drop:
165+
- ALL
166+
volumeMounts:
167+
- mountPath: /tmp/cert
168+
name: catalogd-cert
169+
readOnly: true
170+
volumes:
171+
- name: catalogd-cert
172+
secret:
173+
secretName: $OLM_SECRET
174+
securityContext:
175+
runAsNonRoot: true
176+
restartPolicy: Never
177+
EOF
178+
```
179+
180+
#### Access the Pod and Test Metrics
181+
182+
Access the pod:
183+
184+
```shell
185+
kubectl exec -it curl-metrics-catalogd -n olmv1-system -- sh
186+
```
187+
188+
From the shell use the `TOKEN` value obtained above to check the metrics:
189+
190+
```shell
191+
curl -v -k -H "Authorization: Bearer <TOKEN>" \
192+
https://catalogd-service.olmv1-system.svc.cluster.local:7443/metrics
193+
```
194+
195+
Validate using certificates and token:
196+
197+
```shell
198+
curl -v --cacert /tmp/cert/ca.crt --cert /tmp/cert/tls.crt --key /tmp/cert/tls.key \
199+
-H "Authorization: Bearer <TOKEN>" \
200+
https://catalogd-service.olmv1-system.svc.cluster.local:7443/metrics
201+
```
202+
203+
---
204+
205+
## Enabling Integration with Prometheus
206+
207+
If using [Prometheus Operator][prometheus-operator], create a `ServiceMonitor` to scrape metrics:
208+
209+
### For Operator-Controller
210+
211+
```shell
212+
kubectl apply -f - <<EOF
213+
apiVersion: monitoring.coreos.com/v1
214+
kind: ServiceMonitor
215+
metadata:
216+
labels:
217+
control-plane: operator-controller-controller-manager
218+
name: controller-manager-metrics-monitor
219+
namespace: system
220+
spec:
221+
endpoints:
222+
- path: /metrics
223+
port: https
224+
scheme: https
225+
bearerTokenFile: /var/run/secrets/kubernetes.io/serviceaccount/token
226+
tlsConfig:
227+
insecureSkipVerify: false
228+
serverName: operator-controller-controller-manager-metrics-service.olmv1-system.svc
229+
ca:
230+
secret:
231+
name: olmv1-cert
232+
key: ca.crt
233+
cert:
234+
secret:
235+
name: olmv1-cert
236+
key: tls.crt
237+
keySecret:
238+
name: olmv1-cert
239+
key: tls.key
240+
selector:
241+
matchLabels:
242+
control-plane: operator-controller-controller-manager
243+
EOF
244+
```
245+
246+
### For CatalogD
247+
248+
249+
```shell
250+
OLM_SECRET=$(kubectl get secret -n olmv1-system -o jsonpath="{.items[?(@.metadata.name | startswith('catalogd-service-cert'))].metadata.name}")
251+
```
252+
253+
```shell
254+
kubectl apply -f - <<EOF
255+
apiVersion: monitoring.coreos.com/v1
256+
kind: ServiceMonitor
257+
metadata:
258+
labels:
259+
control-plane: catalogd-controller-manager
260+
name: catalogd-metrics-monitor
261+
namespace: system
262+
spec:
263+
endpoints:
264+
- path: /metrics
265+
port: https
266+
scheme: https
267+
bearerTokenFile: /var/run/secrets/kubernetes.io/serviceaccount/token
268+
tlsConfig:
269+
serverName: catalogd-service.olmv1-system.svc
270+
insecureSkipVerify: false
271+
ca:
272+
secret:
273+
name: $OLM_SECRET
274+
key: ca.crt
275+
cert:
276+
secret:
277+
name: $OLM_SECRET
278+
key: tls.crt
279+
keySecret:
280+
name: $OLM_SECRET
281+
key: tls.key
282+
selector:
283+
matchLabels:
284+
control-plane: catalogd-controller-manager
285+
EOF
286+
```
287+
288+
[prometheus-operator]: https://github.com/prometheus-operator/prometheus-operator
289+
[rbac-k8s-docs]: https://kubernetes.io/docs/reference/access-authn-authz/rbac/

0 commit comments

Comments
 (0)