prometheus.j2 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. apiVersion: apps/v1beta1
  2. kind: StatefulSet
  3. metadata:
  4. name: prometheus
  5. namespace: {{ namespace }}
  6. labels:
  7. app: prometheus
  8. spec:
  9. updateStrategy:
  10. type: RollingUpdate
  11. podManagementPolicy: Parallel
  12. selector:
  13. provider: openshift
  14. matchLabels:
  15. app: prometheus
  16. template:
  17. metadata:
  18. name: prometheus
  19. labels:
  20. app: prometheus
  21. spec:
  22. serviceAccountName: "{{ openshift_prometheus_service_name }}"
  23. {% if openshift_prometheus_node_selector is iterable and openshift_prometheus_node_selector | length > 0 %}
  24. nodeSelector:
  25. {% for key, value in openshift_prometheus_node_selector.items() %}
  26. {{ key }}: "{{ value }}"
  27. {% endfor %}
  28. {% endif %}
  29. containers:
  30. # Deploy Prometheus behind an oauth proxy
  31. - name: prom-proxy
  32. image: "{{ l_openshift_prometheus_proxy_image_prefix }}oauth-proxy:{{ l_openshift_prometheus_proxy_image_version }}"
  33. imagePullPolicy: IfNotPresent
  34. resources:
  35. requests:
  36. {% if openshift_prometheus_oauth_proxy_memory_requests is defined and openshift_prometheus_oauth_proxy_memory_requests is not none %}
  37. memory: "{{ openshift_prometheus_oauth_proxy_memory_requests }}"
  38. {% endif %}
  39. {% if openshift_prometheus_oauth_proxy_cpu_requests is defined and openshift_prometheus_oauth_proxy_cpu_requests is not none %}
  40. cpu: "{{ openshift_prometheus_oauth_proxy_cpu_requests }}"
  41. {% endif %}
  42. limits:
  43. {% if openshift_prometheus_oauth_proxy_memory_limit is defined and openshift_prometheus_oauth_proxy_memory_limit is not none %}
  44. memory: "{{ openshift_prometheus_oauth_proxy_memory_limit }}"
  45. {% endif %}
  46. {% if openshift_prometheus_oauth_proxy_cpu_limit is defined and openshift_prometheus_oauth_proxy_cpu_limit is not none %}
  47. cpu: "{{ openshift_prometheus_oauth_proxy_cpu_limit }}"
  48. {% endif %}
  49. ports:
  50. - containerPort: {{ openshift_prometheus_service_targetport }}
  51. name: web
  52. args:
  53. - -provider=openshift
  54. - -https-address=:{{ openshift_prometheus_service_targetport }}
  55. - -http-address=
  56. - -email-domain=*
  57. - -upstream=http://localhost:9090
  58. - -client-id=system:serviceaccount:{{ namespace }}:{{ openshift_prometheus_service_name }}
  59. - '-openshift-sar={"resource": "namespaces", "verb": "get", "resourceName": "{{ namespace }}", "namespace": "{{ namespace }}"}'
  60. - '-openshift-delegate-urls={"/": {"resource": "namespaces", "verb": "get", "resourceName": "{{ namespace }}", "namespace": "{{ namespace }}"}}'
  61. - -tls-cert=/etc/tls/private/tls.crt
  62. - -tls-key=/etc/tls/private/tls.key
  63. - -client-secret-file=/var/run/secrets/kubernetes.io/serviceaccount/token
  64. - -cookie-secret-file=/etc/proxy/secrets/session_secret
  65. - -openshift-ca=/etc/pki/tls/cert.pem
  66. - -openshift-ca=/var/run/secrets/kubernetes.io/serviceaccount/ca.crt
  67. - -skip-auth-regex=^/metrics
  68. volumeMounts:
  69. - mountPath: /etc/tls/private
  70. name: prometheus-tls-secret
  71. - mountPath: /etc/proxy/secrets
  72. name: prometheus-proxy-secret
  73. - mountPath: /prometheus
  74. name: prometheus-data
  75. - name: prometheus
  76. args:
  77. {% for arg in openshift_prometheus_args %}
  78. - {{ arg }}
  79. {% endfor %}
  80. - --config.file=/etc/prometheus/prometheus.yml
  81. - --web.listen-address=localhost:9090
  82. image: "{{ l_openshift_prometheus_image_prefix }}prometheus:{{ l_openshift_prometheus_image_version }}"
  83. imagePullPolicy: IfNotPresent
  84. livenessProbe:
  85. exec:
  86. command:
  87. - /bin/bash
  88. - -c
  89. - |-
  90. set -euo pipefail;
  91. touch /tmp/prometheusconfig.hash;
  92. if [[ $(find /etc/prometheus -type f | sort | xargs md5sum | md5sum) != $(cat /tmp/prometheusconfig.hash) ]]; then
  93. find /etc/prometheus -type f | sort | xargs md5sum | md5sum > /tmp/prometheusconfig.hash;
  94. kill -HUP 1;
  95. fi
  96. initialDelaySeconds: 60
  97. periodSeconds: 60
  98. resources:
  99. requests:
  100. {% if openshift_prometheus_memory_requests is defined and openshift_prometheus_memory_requests is not none %}
  101. memory: "{{ openshift_prometheus_memory_requests }}"
  102. {% endif %}
  103. {% if openshift_prometheus_cpu_requests is defined and openshift_prometheus_cpu_requests is not none %}
  104. cpu: "{{ openshift_prometheus_cpu_requests }}"
  105. {% endif %}
  106. limits:
  107. {% if openshift_prometheus_memory_limit is defined and openshift_prometheus_memory_limit is not none %}
  108. memory: "{{ openshift_prometheus_memory_limit }}"
  109. {% endif %}
  110. {% if openshift_prometheus_cpu_limit is defined and openshift_prometheus_cpu_limit is not none %}
  111. cpu: "{{ openshift_prometheus_cpu_limit }}"
  112. {% endif %}
  113. volumeMounts:
  114. - mountPath: /etc/prometheus
  115. name: prometheus-config
  116. - mountPath: /prometheus
  117. name: prometheus-data
  118. # Deploy alert-buffer behind oauth alerts-proxy
  119. - name: alerts-proxy
  120. image: "{{ l_openshift_prometheus_proxy_image_prefix }}oauth-proxy:{{ l_openshift_prometheus_proxy_image_version }}"
  121. imagePullPolicy: IfNotPresent
  122. resources:
  123. requests:
  124. {% if openshift_prometheus_oauth_proxy_memory_requests is defined and openshift_prometheus_oauth_proxy_memory_requests is not none %}
  125. memory: "{{ openshift_prometheus_oauth_proxy_memory_requests }}"
  126. {% endif %}
  127. {% if openshift_prometheus_oauth_proxy_cpu_requests is defined and openshift_prometheus_oauth_proxy_cpu_requests is not none %}
  128. cpu: "{{ openshift_prometheus_oauth_proxy_cpu_requests }}"
  129. {% endif %}
  130. limits:
  131. {% if openshift_prometheus_oauth_proxy_memory_limit is defined and openshift_prometheus_oauth_proxy_memory_limit is not none %}
  132. memory: "{{ openshift_prometheus_oauth_proxy_memory_limit }}"
  133. {% endif %}
  134. {% if openshift_prometheus_oauth_proxy_cpu_limit is defined and openshift_prometheus_oauth_proxy_cpu_limit is not none %}
  135. cpu: "{{ openshift_prometheus_oauth_proxy_cpu_limit }}"
  136. {% endif %}
  137. ports:
  138. - containerPort: {{ openshift_prometheus_alerts_service_targetport }}
  139. name: web
  140. args:
  141. - -provider=openshift
  142. - -https-address=:{{ openshift_prometheus_alerts_service_targetport }}
  143. - -http-address=
  144. - -email-domain=*
  145. - -upstream=http://localhost:9099
  146. - -client-id=system:serviceaccount:{{ namespace }}:{{ openshift_prometheus_service_name }}
  147. - '-openshift-sar={"resource": "namespaces", "verb": "get", "resourceName": "{{ namespace }}", "namespace": "{{ namespace }}"}'
  148. - '-openshift-delegate-urls={"/": {"resource": "namespaces", "verb": "get", "resourceName": "{{ namespace }}", "namespace": "{{ namespace }}"}}'
  149. - -tls-cert=/etc/tls/private/tls.crt
  150. - -tls-key=/etc/tls/private/tls.key
  151. - -client-secret-file=/var/run/secrets/kubernetes.io/serviceaccount/token
  152. - -cookie-secret-file=/etc/proxy/secrets/session_secret
  153. - -openshift-ca=/etc/pki/tls/cert.pem
  154. - -openshift-ca=/var/run/secrets/kubernetes.io/serviceaccount/ca.crt
  155. volumeMounts:
  156. - mountPath: /etc/tls/private
  157. name: alerts-tls-secret
  158. - mountPath: /etc/proxy/secrets
  159. name: alerts-proxy-secret
  160. - name: alert-buffer
  161. args:
  162. - --storage-path=/alert-buffer/messages.db
  163. image: "{{ l_openshift_prometheus_alertbuffer_image_prefix }}prometheus-alert-buffer:{{ l_openshift_prometheus_alertbuffer_image_version }}"
  164. imagePullPolicy: IfNotPresent
  165. resources:
  166. requests:
  167. {% if openshift_prometheus_alertbuffer_memory_requests is defined and openshift_prometheus_alertbuffer_memory_requests is not none %}
  168. memory: "{{ openshift_prometheus_alertbuffer_memory_requests }}"
  169. {% endif %}
  170. {% if openshift_prometheus_alertbuffer_cpu_requests is defined and openshift_prometheus_alertbuffer_cpu_requests is not none %}
  171. cpu: "{{ openshift_prometheus_alertbuffer_cpu_requests }}"
  172. {% endif %}
  173. limits:
  174. {% if openshift_prometheus_alertbuffer_memory_limit is defined and openshift_prometheus_alertbuffer_memory_limit is not none %}
  175. memory: "{{ openshift_prometheus_alertbuffer_memory_limit }}"
  176. {% endif %}
  177. {% if openshift_prometheus_alertbuffer_cpu_limit is defined and openshift_prometheus_alertbuffer_cpu_limit is not none %}
  178. cpu: "{{ openshift_prometheus_alertbuffer_cpu_limit }}"
  179. {% endif %}
  180. volumeMounts:
  181. - mountPath: /alert-buffer
  182. name: alerts-data
  183. ports:
  184. - containerPort: 9099
  185. name: alert-buf
  186. # Deploy alertmanager behind oauth alertmanager-proxy
  187. - name: alertmanager-proxy
  188. image: "{{ l_openshift_prometheus_proxy_image_prefix }}oauth-proxy:{{ l_openshift_prometheus_proxy_image_version }}"
  189. imagePullPolicy: IfNotPresent
  190. requests:
  191. {% if openshift_prometheus_oauth_proxy_memory_requests is defined and openshift_prometheus_oauth_proxy_memory_requests is not none %}
  192. memory: "{{ openshift_prometheus_oauth_proxy_memory_requests }}"
  193. {% endif %}
  194. {% if openshift_prometheus_oauth_proxy_cpu_requests is defined and openshift_prometheus_oauth_proxy_cpu_requests is not none %}
  195. cpu: "{{ openshift_prometheus_oauth_proxy_cpu_requests }}"
  196. {% endif %}
  197. limits:
  198. {% if openshift_prometheus_oauth_proxy_memory_limit is defined and openshift_prometheus_oauth_proxy_memory_limit is not none %}
  199. memory: "{{ openshift_prometheus_oauth_proxy_memory_limit }}"
  200. {% endif %}
  201. {% if openshift_prometheus_oauth_proxy_cpu_limit is defined and openshift_prometheus_oauth_proxy_cpu_limit is not none %}
  202. cpu: "{{ openshift_prometheus_oauth_proxy_cpu_limit }}"
  203. {% endif %}
  204. ports:
  205. - containerPort: {{ openshift_prometheus_alertmanager_service_targetport }}
  206. name: web
  207. args:
  208. - -provider=openshift
  209. - -https-address=:{{ openshift_prometheus_alertmanager_service_targetport }}
  210. - -http-address=
  211. - -email-domain=*
  212. - -upstream=http://localhost:9093
  213. - -client-id=system:serviceaccount:{{ namespace }}:{{ openshift_prometheus_service_name }}
  214. - -openshift-ca=/etc/pki/tls/cert.pem
  215. - -openshift-ca=/var/run/secrets/kubernetes.io/serviceaccount/ca.crt
  216. - '-openshift-sar={"resource": "namespaces", "verb": "get", "resourceName": "{{ namespace }}", "namespace": "{{ namespace }}"}'
  217. - '-openshift-delegate-urls={"/": {"resource": "namespaces", "verb": "get", "resourceName": "{{ namespace }}", "namespace": "{{ namespace }}"}}'
  218. - -tls-cert=/etc/tls/private/tls.crt
  219. - -tls-key=/etc/tls/private/tls.key
  220. - -client-secret-file=/var/run/secrets/kubernetes.io/serviceaccount/token
  221. - -cookie-secret-file=/etc/proxy/secrets/session_secret
  222. - -skip-auth-regex=^/metrics
  223. volumeMounts:
  224. - mountPath: /etc/tls/private
  225. name: alertmanager-tls-secret
  226. - mountPath: /etc/proxy/secrets
  227. name: alertmanager-proxy-secret
  228. - name: alertmanager
  229. args:
  230. - --config.file=/etc/alertmanager/alertmanager.yml
  231. image: "{{ l_openshift_prometheus_alertmanager_image_prefix }}prometheus-alertmanager:{{ l_openshift_prometheus_alertmanager_image_version }}"
  232. imagePullPolicy: IfNotPresent
  233. resources:
  234. requests:
  235. {% if openshift_prometheus_alertmanager_memory_requests is defined and openshift_prometheus_alertmanager_memory_requests is not none %}
  236. memory: "{{ openshift_prometheus_alertmanager_memory_requests }}"
  237. {% endif %}
  238. {% if openshift_prometheus_alertmanager_cpu_requests is defined and openshift_prometheus_alertmanager_cpu_requests is not none %}
  239. cpu: "{{ openshift_prometheus_alertmanager_cpu_requests }}"
  240. {% endif %}
  241. limits:
  242. {% if openshift_prometheus_alertmanager_memory_limit is defined and openshift_prometheus_alertmanager_memory_limit is not none %}
  243. memory: "{{ openshift_prometheus_alertmanager_memory_limit }}"
  244. {% endif %}
  245. {% if openshift_prometheus_alertmanager_cpu_limit is defined and openshift_prometheus_alertmanager_cpu_limit is not none %}
  246. cpu: "{{ openshift_prometheus_alertmanager_cpu_limit }}"
  247. {% endif %}
  248. ports:
  249. - containerPort: 9093
  250. name: web
  251. volumeMounts:
  252. - mountPath: /etc/alertmanager
  253. name: alertmanager-config
  254. - mountPath: /alertmanager
  255. name: alertmanager-data
  256. restartPolicy: Always
  257. volumes:
  258. - name: prometheus-config
  259. configMap:
  260. defaultMode: 420
  261. name: prometheus
  262. - name: prometheus-proxy-secret
  263. secret:
  264. secretName: prometheus-proxy
  265. - name: prometheus-tls-secret
  266. secret:
  267. secretName: prometheus-tls
  268. - name: prometheus-data
  269. {% if openshift_prometheus_storage_type == 'pvc' %}
  270. persistentVolumeClaim:
  271. claimName: {{ openshift_prometheus_pvc_name }}
  272. {% else %}
  273. emptydir: {}
  274. {% endif %}
  275. - name: alertmanager-config
  276. configMap:
  277. defaultMode: 420
  278. name: alertmanager
  279. - name: alertmanager-proxy-secret
  280. secret:
  281. secretName: alertmanager-proxy
  282. - name: alertmanager-tls-secret
  283. secret:
  284. secretName: alertmanager-tls
  285. - name: alerts-tls-secret
  286. secret:
  287. secretName: alerts-tls
  288. - name: alerts-proxy-secret
  289. secret:
  290. secretName: alerts-proxy
  291. - name: alertmanager-data
  292. {% if openshift_prometheus_alertmanager_storage_type == 'pvc' %}
  293. persistentVolumeClaim:
  294. claimName: {{ openshift_prometheus_alertmanager_pvc_name }}
  295. {% else %}
  296. emptydir: {}
  297. {% endif %}
  298. - name: alerts-data
  299. {% if openshift_prometheus_alertbuffer_storage_type == 'pvc' %}
  300. persistentVolumeClaim:
  301. claimName: {{ openshift_prometheus_alertbuffer_pvc_name }}
  302. {% else %}
  303. emptydir: {}
  304. {% endif %}