Skip to content

Commit e127e72

Browse files
cbandyjkatz
authored andcommitted
Scrape cAdvisor for container-level metrics
This enables the ability to collect metrics similar to what `node_exporter` collects, except these are specific to a particular container (which is what cAdvisor) provides. As such, monitoring tools can now see what resources a specific pod is using. In Kubernetes, each Kubelet can run cAdvisor on its node. This commit allows the Postgres Operator to enable this container. This patch also lets each Kubelet use self-signed certificates during scrape as, by default, a Kubelet generates and self-signs the TLS certificate which serves its metrics API. More complete/advanced Kubernetes configurations manage this certificate and sign it with the Kubernetes CA. We are trusting the Kubernetes CA, which is available to containers at `/var/run/secrets/kubernetes.io/serviceaccount/ca.crt`, but to support simpler configurations we must skip TLS verification of the kubelet API. For more information: - https://github.com/kubernetes/kubernetes/blob/v1.15.4/staging/src/k8s.io/kubelet/config/v1beta1/types.go#L130-L145 - https://kubernetes.io/docs/reference/command-line-tools-reference/kubelet-tls-bootstrapping/#certificate-rotation
1 parent 1042175 commit e127e72

File tree

4 files changed

+71
-0
lines changed

4 files changed

+71
-0
lines changed

ansible/roles/pgo-metrics/tasks/prometheus.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
dest: "{{ prom_output_dir }}/{{ item | replace('.j2', '') }}"
4747
mode: '0600'
4848
with_items:
49+
- prometheus-config.yaml.j2
4950
- prometheus-pvc.json.j2
5051
- prometheus-service.json.j2
5152
- prometheus-deployment.json.j2
@@ -54,6 +55,7 @@
5455
- name: Create Prometheus Objects
5556
command: "{{ kubectl_or_oc }} create -f {{ prom_output_dir }}/{{ item }} -n {{ metrics_namespace }}"
5657
with_items:
58+
- prometheus-config.yaml
5759
- prometheus-pvc.json
5860
- prometheus-service.json
5961
- prometheus-deployment.json
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
apiVersion: v1
2+
kind: ConfigMap
3+
metadata:
4+
name: crunchy-prometheus
5+
data:
6+
prometheus.yml: |-
7+
---
8+
global:
9+
scrape_interval: 10s
10+
scrape_timeout: 10s
11+
evaluation_interval: 5s
12+
13+
scrape_configs:
14+
- job_name: cadvisor
15+
kubernetes_sd_configs:
16+
- role: node
17+
18+
metrics_path: /metrics/cadvisor
19+
scheme: https
20+
tls_config:
21+
ca_file: /var/run/secrets/kubernetes.io/serviceaccount/ca.crt
22+
insecure_skip_verify: true
23+
bearer_token_file: /var/run/secrets/kubernetes.io/serviceaccount/token
24+
25+
metric_relabel_configs:
26+
# Keep only metrics attributed to pods.
27+
- action: keep
28+
source_labels: [pod,pod_name]
29+
separator: ''
30+
regex: '.+'
31+
32+
- job_name: crunchy-collect
33+
kubernetes_sd_configs:
34+
- role: pod
35+
36+
relabel_configs:
37+
- source_labels: [__meta_kubernetes_pod_label_crunchy_collect]
38+
action: keep
39+
regex: true
40+
- source_labels: [__meta_kubernetes_pod_container_port_number]
41+
action: drop
42+
regex: 5432
43+
- source_labels: [__meta_kubernetes_pod_container_port_number]
44+
action: drop
45+
regex: 10000
46+
- source_labels: [__meta_kubernetes_namespace]
47+
action: replace
48+
target_label: kubernetes_namespace
49+
- source_labels: [__meta_kubernetes_pod_name]
50+
regex: (^[^-]*).*
51+
target_label: instance
52+
replacement: '$1'
53+
- source_labels: [__meta_kubernetes_namespace,__meta_kubernetes_pod_label_name]
54+
target_label: job
55+
separator: ': '
56+
replacement: '$1$2'

ansible/roles/pgo-metrics/templates/prometheus-deployment.json.j2

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@
4848
},
4949
"env": [],
5050
"volumeMounts": [
51+
{
52+
"mountPath": "/conf",
53+
"name": "prometheusconf",
54+
"readOnly": true
55+
},
5156
{
5257
"mountPath": "/data",
5358
"name": "prometheusdata",
@@ -57,6 +62,12 @@
5762
}
5863
],
5964
"volumes": [
65+
{
66+
"name": "prometheusconf",
67+
"configMap": {
68+
"name": "crunchy-prometheus"
69+
}
70+
},
6071
{
6172
"name": "prometheusdata",
6273
"persistentVolumeClaim": {

ansible/roles/pgo-metrics/templates/prometheus-rbac.json.j2

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
""
1111
],
1212
"resources": [
13+
"nodes",
14+
"nodes/metrics",
1315
"pods"
1416
],
1517
"verbs": [

0 commit comments

Comments
 (0)