prometheus.j2 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  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: "{{ openshift_prometheus_proxy_image }}"
  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. - --web.external-url=https://{{ openshift_prometheus_hostname }}
  83. image: "{{ openshift_prometheus_image }}"
  84. imagePullPolicy: IfNotPresent
  85. livenessProbe:
  86. exec:
  87. command:
  88. - /bin/bash
  89. - -c
  90. - |-
  91. set -euo pipefail;
  92. touch /tmp/prometheusconfig.hash;
  93. if [[ $(find /etc/prometheus -type f | sort | xargs md5sum | md5sum) != $(cat /tmp/prometheusconfig.hash) ]]; then
  94. find /etc/prometheus -type f | sort | xargs md5sum | md5sum > /tmp/prometheusconfig.hash;
  95. kill -HUP 1;
  96. fi
  97. initialDelaySeconds: 60
  98. periodSeconds: 60
  99. resources:
  100. requests:
  101. {% if openshift_prometheus_memory_requests is defined and openshift_prometheus_memory_requests is not none %}
  102. memory: "{{ openshift_prometheus_memory_requests }}"
  103. {% endif %}
  104. {% if openshift_prometheus_cpu_requests is defined and openshift_prometheus_cpu_requests is not none %}
  105. cpu: "{{ openshift_prometheus_cpu_requests }}"
  106. {% endif %}
  107. limits:
  108. {% if openshift_prometheus_memory_limit is defined and openshift_prometheus_memory_limit is not none %}
  109. memory: "{{ openshift_prometheus_memory_limit }}"
  110. {% endif %}
  111. {% if openshift_prometheus_cpu_limit is defined and openshift_prometheus_cpu_limit is not none %}
  112. cpu: "{{ openshift_prometheus_cpu_limit }}"
  113. {% endif %}
  114. volumeMounts:
  115. - mountPath: /etc/prometheus
  116. name: prometheus-config
  117. - mountPath: /prometheus
  118. name: prometheus-data
  119. # Deploy alert-buffer behind oauth alerts-proxy
  120. - name: alerts-proxy
  121. image: "{{ openshift_prometheus_proxy_image }}"
  122. imagePullPolicy: IfNotPresent
  123. resources:
  124. requests:
  125. {% if openshift_prometheus_oauth_proxy_memory_requests is defined and openshift_prometheus_oauth_proxy_memory_requests is not none %}
  126. memory: "{{ openshift_prometheus_oauth_proxy_memory_requests }}"
  127. {% endif %}
  128. {% if openshift_prometheus_oauth_proxy_cpu_requests is defined and openshift_prometheus_oauth_proxy_cpu_requests is not none %}
  129. cpu: "{{ openshift_prometheus_oauth_proxy_cpu_requests }}"
  130. {% endif %}
  131. limits:
  132. {% if openshift_prometheus_oauth_proxy_memory_limit is defined and openshift_prometheus_oauth_proxy_memory_limit is not none %}
  133. memory: "{{ openshift_prometheus_oauth_proxy_memory_limit }}"
  134. {% endif %}
  135. {% if openshift_prometheus_oauth_proxy_cpu_limit is defined and openshift_prometheus_oauth_proxy_cpu_limit is not none %}
  136. cpu: "{{ openshift_prometheus_oauth_proxy_cpu_limit }}"
  137. {% endif %}
  138. ports:
  139. - containerPort: {{ openshift_prometheus_alerts_service_targetport }}
  140. name: web
  141. args:
  142. - -provider=openshift
  143. - -https-address=:{{ openshift_prometheus_alerts_service_targetport }}
  144. - -http-address=
  145. - -email-domain=*
  146. - -upstream=http://localhost:9099
  147. - -client-id=system:serviceaccount:{{ namespace }}:{{ openshift_prometheus_service_name }}
  148. - '-openshift-sar={"resource": "namespaces", "verb": "get", "resourceName": "{{ namespace }}", "namespace": "{{ namespace }}"}'
  149. - '-openshift-delegate-urls={"/": {"resource": "namespaces", "verb": "get", "resourceName": "{{ namespace }}", "namespace": "{{ namespace }}"}}'
  150. - -tls-cert=/etc/tls/private/tls.crt
  151. - -tls-key=/etc/tls/private/tls.key
  152. - -client-secret-file=/var/run/secrets/kubernetes.io/serviceaccount/token
  153. - -cookie-secret-file=/etc/proxy/secrets/session_secret
  154. - -openshift-ca=/etc/pki/tls/cert.pem
  155. - -openshift-ca=/var/run/secrets/kubernetes.io/serviceaccount/ca.crt
  156. - -skip-auth-regex=^/metrics
  157. volumeMounts:
  158. - mountPath: /etc/tls/private
  159. name: alerts-tls-secret
  160. - mountPath: /etc/proxy/secrets
  161. name: alerts-proxy-secret
  162. - name: alert-buffer
  163. args:
  164. - --storage-path=/alert-buffer/messages.db
  165. image: "{{ openshift_prometheus_alertbuffer_image }}"
  166. imagePullPolicy: IfNotPresent
  167. resources:
  168. requests:
  169. {% if openshift_prometheus_alertbuffer_memory_requests is defined and openshift_prometheus_alertbuffer_memory_requests is not none %}
  170. memory: "{{ openshift_prometheus_alertbuffer_memory_requests }}"
  171. {% endif %}
  172. {% if openshift_prometheus_alertbuffer_cpu_requests is defined and openshift_prometheus_alertbuffer_cpu_requests is not none %}
  173. cpu: "{{ openshift_prometheus_alertbuffer_cpu_requests }}"
  174. {% endif %}
  175. limits:
  176. {% if openshift_prometheus_alertbuffer_memory_limit is defined and openshift_prometheus_alertbuffer_memory_limit is not none %}
  177. memory: "{{ openshift_prometheus_alertbuffer_memory_limit }}"
  178. {% endif %}
  179. {% if openshift_prometheus_alertbuffer_cpu_limit is defined and openshift_prometheus_alertbuffer_cpu_limit is not none %}
  180. cpu: "{{ openshift_prometheus_alertbuffer_cpu_limit }}"
  181. {% endif %}
  182. volumeMounts:
  183. - mountPath: /alert-buffer
  184. name: alerts-data
  185. # Deploy alertmanager behind oauth alertmanager-proxy
  186. - name: alertmanager-proxy
  187. image: "{{ openshift_prometheus_proxy_image }}"
  188. imagePullPolicy: IfNotPresent
  189. requests:
  190. {% if openshift_prometheus_oauth_proxy_memory_requests is defined and openshift_prometheus_oauth_proxy_memory_requests is not none %}
  191. memory: "{{ openshift_prometheus_oauth_proxy_memory_requests }}"
  192. {% endif %}
  193. {% if openshift_prometheus_oauth_proxy_cpu_requests is defined and openshift_prometheus_oauth_proxy_cpu_requests is not none %}
  194. cpu: "{{ openshift_prometheus_oauth_proxy_cpu_requests }}"
  195. {% endif %}
  196. limits:
  197. {% if openshift_prometheus_oauth_proxy_memory_limit is defined and openshift_prometheus_oauth_proxy_memory_limit is not none %}
  198. memory: "{{ openshift_prometheus_oauth_proxy_memory_limit }}"
  199. {% endif %}
  200. {% if openshift_prometheus_oauth_proxy_cpu_limit is defined and openshift_prometheus_oauth_proxy_cpu_limit is not none %}
  201. cpu: "{{ openshift_prometheus_oauth_proxy_cpu_limit }}"
  202. {% endif %}
  203. ports:
  204. - containerPort: {{ openshift_prometheus_alertmanager_service_targetport }}
  205. name: web
  206. args:
  207. - -provider=openshift
  208. - -https-address=:{{ openshift_prometheus_alertmanager_service_targetport }}
  209. - -http-address=
  210. - -email-domain=*
  211. - -upstream=http://localhost:9093
  212. - -client-id=system:serviceaccount:{{ namespace }}:{{ openshift_prometheus_service_name }}
  213. - -openshift-ca=/etc/pki/tls/cert.pem
  214. - -openshift-ca=/var/run/secrets/kubernetes.io/serviceaccount/ca.crt
  215. - '-openshift-sar={"resource": "namespaces", "verb": "get", "resourceName": "{{ namespace }}", "namespace": "{{ namespace }}"}'
  216. - '-openshift-delegate-urls={"/": {"resource": "namespaces", "verb": "get", "resourceName": "{{ namespace }}", "namespace": "{{ namespace }}"}}'
  217. - -tls-cert=/etc/tls/private/tls.crt
  218. - -tls-key=/etc/tls/private/tls.key
  219. - -client-secret-file=/var/run/secrets/kubernetes.io/serviceaccount/token
  220. - -cookie-secret-file=/etc/proxy/secrets/session_secret
  221. - -skip-auth-regex=^/metrics
  222. volumeMounts:
  223. - mountPath: /etc/tls/private
  224. name: alertmanager-tls-secret
  225. - mountPath: /etc/proxy/secrets
  226. name: alertmanager-proxy-secret
  227. - name: alertmanager
  228. args:
  229. - --config.file=/etc/alertmanager/alertmanager.yml
  230. - --web.external-url=https://{{ openshift_prometheus_alertmanager_hostname }}
  231. image: "{{ openshift_prometheus_alertmanager_image }}"
  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. volumeMounts:
  249. - mountPath: /etc/alertmanager
  250. name: alertmanager-config
  251. - mountPath: /alertmanager
  252. name: alertmanager-data
  253. restartPolicy: Always
  254. volumes:
  255. - name: prometheus-config
  256. configMap:
  257. defaultMode: 420
  258. name: prometheus
  259. - name: prometheus-proxy-secret
  260. secret:
  261. secretName: prometheus-proxy
  262. - name: prometheus-tls-secret
  263. secret:
  264. secretName: prometheus-tls
  265. - name: prometheus-data
  266. {% if openshift_prometheus_storage_type == 'pvc' %}
  267. persistentVolumeClaim:
  268. claimName: {{ openshift_prometheus_pvc_name }}
  269. {% else %}
  270. emptydir: {}
  271. {% endif %}
  272. - name: alertmanager-config
  273. configMap:
  274. defaultMode: 420
  275. name: alertmanager
  276. - name: alertmanager-proxy-secret
  277. secret:
  278. secretName: alertmanager-proxy
  279. - name: alertmanager-tls-secret
  280. secret:
  281. secretName: alertmanager-tls
  282. - name: alerts-tls-secret
  283. secret:
  284. secretName: alerts-tls
  285. - name: alerts-proxy-secret
  286. secret:
  287. secretName: alerts-proxy
  288. - name: alertmanager-data
  289. {% if openshift_prometheus_alertmanager_storage_type == 'pvc' %}
  290. persistentVolumeClaim:
  291. claimName: {{ openshift_prometheus_alertmanager_pvc_name }}
  292. {% else %}
  293. emptydir: {}
  294. {% endif %}
  295. - name: alerts-data
  296. {% if openshift_prometheus_alertbuffer_storage_type == 'pvc' %}
  297. persistentVolumeClaim:
  298. claimName: {{ openshift_prometheus_alertbuffer_pvc_name }}
  299. {% else %}
  300. emptydir: {}
  301. {% endif %}