-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathprometheus.yaml
More file actions
251 lines (247 loc) · 6.44 KB
/
prometheus.yaml
File metadata and controls
251 lines (247 loc) · 6.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
apiVersion: v1
kind: Namespace
metadata:
name: ${KUBE_NAMESPACE}
---
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRole
metadata:
name: prometheus
rules:
- apiGroups: [""]
resources:
- nodes
- nodes/proxy
- services
- endpoints
- pods
verbs: ["get", "list", "watch"]
- apiGroups:
- extensions
resources:
- ingresses
verbs: ["get", "list", "watch"]
- nonResourceURLs: ["/metrics"]
verbs: ["get"]
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: prometheus
namespace: ${KUBE_NAMESPACE}
---
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRoleBinding
metadata:
name: prometheus
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: prometheus
subjects:
- kind: ServiceAccount
name: prometheus
namespace: ${KUBE_NAMESPACE}
---
apiVersion: v1
kind: Service
metadata:
labels:
app: prometheus-k8s
annotations:
prometheus.io/scrape: 'true'
prometheus.io/port: '9090'
prometheus.io/port2: '9091'
name: prometheus-k8s
namespace: ${KUBE_NAMESPACE}
spec:
type: LoadBalancer
externalTrafficPolicy: Cluster
ports:
- name: prometheus
nodePort: 32387
port: 9090
protocol: TCP
targetPort: 9090
- name: sidecar
nodePort: 30182
port: 9091
protocol: TCP
targetPort: 9091
selector:
app: prometheus
prometheus: k8s
sessionAffinity: None
---
apiVersion: apps/v1beta2
kind: Deployment
metadata:
name: prometheus-k8s
namespace: ${KUBE_NAMESPACE}
labels:
app: prometheus
prometheus: k8s
spec:
replicas: 1
selector:
matchLabels:
app: prometheus
prometheus: k8s
template:
metadata:
labels:
app: prometheus
prometheus: k8s
spec:
serviceAccount: prometheus
securityContext:
runAsUser: 0
containers:
- name: prometheus
image: quay.io/prometheus/prometheus:v2.6.0
imagePullPolicy: Always
args:
- "--config.file=/etc/prometheus/config/prometheus.yaml"
- "--storage.tsdb.path=/data"
- "--storage.tsdb.min-block-duration=15m"
- "--storage.tsdb.max-block-duration=4h"
- "--storage.tsdb.retention=48h"
ports:
- name: prometheus
containerPort: 9090
volumeMounts:
- name: config-volume
mountPath: /etc/prometheus/config
- name: data-volume
mountPath: /data
volumes:
- name: config-volume
configMap:
name: prometheus-k8s
- name: data-volume
emptyDir: {}
terminationGracePeriodSeconds: 300
---
apiVersion: v1
kind: ConfigMap
metadata:
name: prometheus-k8s
namespace: ${KUBE_NAMESPACE}
data:
prometheus.yaml: |
scrape_configs:
- job_name: kubernetes-apiservers
kubernetes_sd_configs:
- role: endpoints
relabel_configs:
- action: keep
regex: default;kubernetes;https
source_labels:
- __meta_kubernetes_namespace
- __meta_kubernetes_service_name
- __meta_kubernetes_endpoint_port_name
scheme: https
tls_config:
ca_file: /var/run/secrets/kubernetes.io/serviceaccount/ca.crt
insecure_skip_verify: true
bearer_token_file: /var/run/secrets/kubernetes.io/serviceaccount/token
- job_name: kubernetes-nodes-kubelet
kubernetes_sd_configs:
- role: node
relabel_configs:
- target_label: __address__
regex: "(.+):10250"
source_labels: [__address__]
replacement: "${1}:10255"
- job_name: kubernetes-nodes-cadvisor
kubernetes_sd_configs:
- role: node
relabel_configs:
- target_label: __metrics_path__
replacement: /metrics/cadvisor
- target_label: __address__
regex: "(.+):10250"
source_labels: [__address__]
replacement: "${1}:10255"
# Configuration for the first port (prometheus.io/port) that service
# endpoints are annotated with.
- job_name: kubernetes-service-endpoints1
kubernetes_sd_configs:
- role: endpoints
relabel_configs:
- action: keep
regex: true
source_labels:
- __meta_kubernetes_service_annotation_prometheus_io_scrape
- action: replace
regex: (https?)
source_labels:
- __meta_kubernetes_service_annotation_prometheus_io_scheme
target_label: __scheme__
- action: replace
regex: (.+)
source_labels:
- __meta_kubernetes_service_annotation_prometheus_io_path
target_label: __metrics_path__
- action: replace
regex: ([^:]+)(?::\d+)?;(\d+)
replacement: $1:$2
source_labels:
- __address__
- __meta_kubernetes_service_annotation_prometheus_io_port
target_label: __address__
- action: replace
source_labels:
- __meta_kubernetes_namespace
target_label: k8s_namespace
- action: replace
source_labels:
- __meta_kubernetes_service_name
target_label: k8s_service
- action: replace
source_labels:
- __meta_kubernetes_pod_name
target_label: k8s_pod
# Configuration for the seocnd port (prometheus.io/port2) that service
# endpoints are annotated with.
- job_name: kubernetes-service-endpoints2
kubernetes_sd_configs:
- role: endpoints
relabel_configs:
- action: keep
regex: true
source_labels:
- __meta_kubernetes_service_annotation_prometheus_io_scrape
- action: replace
regex: (https?)
source_labels:
- __meta_kubernetes_service_annotation_prometheus_io_scheme
target_label: __scheme__
- action: replace
regex: (.+)
source_labels:
- __meta_kubernetes_service_annotation_prometheus_io_path
target_label: __metrics_path__
- action: keep
source_labels:
- __meta_kubernetes_service_annotation_prometheus_io_port2
regex: .+
- action: replace
regex: ([^:]+)(?::\d+)?;(\d+)
replacement: $1:$2
source_labels:
- __address__
- __meta_kubernetes_service_annotation_prometheus_io_port2
target_label: __address__
- action: replace
source_labels:
- __meta_kubernetes_namespace
target_label: k8s_namespace
- action: replace
source_labels:
- __meta_kubernetes_service_name
target_label: k8s_service
- action: replace
source_labels:
- __meta_kubernetes_pod_name
target_label: k8s_pod