prometheus_deployment.j2 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. apiVersion: extensions/v1beta1
  2. kind: Deployment
  3. metadata:
  4. name: prometheus
  5. namespace: {{ namespace }}
  6. labels:
  7. app: prometheus
  8. spec:
  9. replicas: {{ prom_replicas|default(1) }}
  10. selector:
  11. provider: openshift
  12. matchLabels:
  13. app: prometheus
  14. template:
  15. metadata:
  16. name: prometheus
  17. labels:
  18. app: prometheus
  19. spec:
  20. serviceAccountName: prometheus
  21. {% if openshift_prometheus_node_selector is iterable and openshift_prometheus_node_selector | length > 0 %}
  22. nodeSelector:
  23. {% for key, value in openshift_prometheus_node_selector.iteritems() %}
  24. {{key}}: "{{value}}"
  25. {% endfor %}
  26. {% endif %}
  27. containers:
  28. # Deploy Prometheus behind an oauth proxy
  29. - name: prom-proxy
  30. image: "{{ openshift_prometheus_image_proxy }}"
  31. imagePullPolicy: IfNotPresent
  32. resources:
  33. requests:
  34. {% if openshift_prometheus_oauth_proxy_memory_requests is defined and openshift_prometheus_oauth_proxy_memory_requests is not none %}
  35. memory: "{{openshift_prometheus_oauth_proxy_memory_requests}}"
  36. {% endif %}
  37. {% if openshift_prometheus_oauth_proxy_cpu_requests is defined and openshift_prometheus_oauth_proxy_cpu_requests is not none %}
  38. cpu: "{{openshift_prometheus_oauth_proxy_cpu_requests}}"
  39. {% endif %}
  40. limits:
  41. {% if openshift_prometheus_memory_requests_limit_proxy is defined and openshift_prometheus_oauth_proxy_memory_limit is not none %}
  42. memory: "{{openshift_prometheus_oauth_proxy_memory_limit}}"
  43. {% endif %}
  44. {% if openshift_prometheus_oauth_proxy_cpu_limit is defined and openshift_prometheus_oauth_proxy_cpu_limit is not none %}
  45. cpu: "{{openshift_prometheus_oauth_proxy_cpu_limit}}"
  46. {% endif %}
  47. ports:
  48. - containerPort: 8443
  49. name: web
  50. args:
  51. - -provider=openshift
  52. - -https-address=:8443
  53. - -http-address=
  54. - -email-domain=*
  55. - -upstream=http://localhost:9090
  56. - -client-id=system:serviceaccount:{{ namespace }}:prometheus
  57. - '-openshift-sar={"resource": "namespaces", "verb": "get", "resourceName": "{{ namespace }}", "namespace": "{{ namespace }}"}'
  58. - '-openshift-delegate-urls={"/": {"resource": "namespaces", "verb": "get", "resourceName": "{{ namespace }}", "namespace": "{{ namespace }}"}}'
  59. - -tls-cert=/etc/tls/private/tls.crt
  60. - -tls-key=/etc/tls/private/tls.key
  61. - -client-secret-file=/var/run/secrets/kubernetes.io/serviceaccount/token
  62. - -cookie-secret-file=/etc/proxy/secrets/session_secret
  63. - -skip-auth-regex=^/metrics
  64. volumeMounts:
  65. - mountPath: /etc/tls/private
  66. name: prometheus-tls
  67. - mountPath: /etc/proxy/secrets
  68. name: prometheus-secrets
  69. - mountPath: /prometheus
  70. name: prometheus-data
  71. - name: prometheus
  72. args:
  73. - --storage.tsdb.retention=6h
  74. - --config.file=/etc/prometheus/prometheus.yml
  75. - --web.listen-address=localhost:9090
  76. image: "{{ openshift_prometheus_image_prometheus }}"
  77. imagePullPolicy: IfNotPresent
  78. resources:
  79. requests:
  80. {% if openshift_prometheus_memory_requests is defined and openshift_prometheus_memory_requests is not none %}
  81. memory: "{{openshift_prometheus_memory_requests}}"
  82. {% endif %}
  83. {% if openshift_prometheus_cpu_requests is defined and openshift_prometheus_cpu_requests is not none %}
  84. cpu: "{{openshift_prometheus_cpu_requests}}"
  85. {% endif %}
  86. limits:
  87. {% if openshift_prometheus_memory_limit is defined and openshift_prometheus_memory_limit is not none %}
  88. memory: "{{ openshift_prometheus_memory_limit }}"
  89. {% endif %}
  90. {% if openshift_prometheus_cpu_limit is defined and openshift_prometheus_cpu_limit is not none %}
  91. cpu: "{{openshift_prometheus_cpu_limit}}"
  92. {% endif %}
  93. volumeMounts:
  94. - mountPath: /etc/prometheus
  95. name: prometheus-config
  96. - mountPath: /prometheus
  97. name: prometheus-data
  98. # Deploy alertmanager behind prometheus-alert-buffer behind an oauth proxy
  99. - name: alerts-proxy
  100. image: "{{ openshift_prometheus_image_proxy }}"
  101. imagePullPolicy: IfNotPresent
  102. resources:
  103. requests:
  104. {% if openshift_prometheus_oauth_proxy_memory_requests is defined and openshift_prometheus_oauth_proxy_memory_requests is not none %}
  105. memory: "{{openshift_prometheus_oauth_proxy_memory_requests}}"
  106. {% endif %}
  107. {% if openshift_prometheus_oauth_proxy_cpu_requests is defined and openshift_prometheus_oauth_proxy_cpu_requests is not none %}
  108. cpu: "{{openshift_prometheus_oauth_proxy_cpu_requests}}"
  109. {% endif %}
  110. limits:
  111. {% if openshift_prometheus_oauth_proxy_memory_limit is defined and openshift_prometheus_oauth_proxy_memory_limit is not none %}
  112. memory: "{{openshift_prometheus_oauth_proxy_memory_limit}}"
  113. {% endif %}
  114. {% if openshift_prometheus_oauth_proxy_cpu_limit is defined and openshift_prometheus_oauth_proxy_cpu_limit is not none %}
  115. cpu: "{{openshift_prometheus_oauth_proxy_cpu_limit}}"
  116. {% endif %}
  117. ports:
  118. - containerPort: 9443
  119. name: web
  120. args:
  121. - -provider=openshift
  122. - -https-address=:9443
  123. - -http-address=
  124. - -email-domain=*
  125. - -upstream=http://localhost:9099
  126. - -client-id=system:serviceaccount:{{ namespace }}:prometheus
  127. - '-openshift-sar={"resource": "namespaces", "verb": "get", "resourceName": "{{ namespace }}", "namespace": "{{ namespace }}"}'
  128. - '-openshift-delegate-urls={"/": {"resource": "namespaces", "verb": "get", "resourceName": "{{ namespace }}", "namespace": "{{ namespace }}"}}'
  129. - -tls-cert=/etc/tls/private/tls.crt
  130. - -tls-key=/etc/tls/private/tls.key
  131. - -client-secret-file=/var/run/secrets/kubernetes.io/serviceaccount/token
  132. - -cookie-secret-file=/etc/proxy/secrets/session_secret
  133. volumeMounts:
  134. - mountPath: /etc/tls/private
  135. name: alerts-tls
  136. - mountPath: /etc/proxy/secrets
  137. name: alerts-secrets
  138. - name: alert-buffer
  139. args:
  140. - --storage-path=/alert-buffer/messages.db
  141. image: "{{ openshift_prometheus_image_alertbuffer }}"
  142. imagePullPolicy: IfNotPresent
  143. resources:
  144. requests:
  145. {% if openshift_prometheus_alertbuffer_memory_requests is defined and openshift_prometheus_alertbuffer_memory_requests is not none %}
  146. memory: "{{openshift_prometheus_alertbuffer_memory_requests}}"
  147. {% endif %}
  148. {% if openshift_prometheus_alertbuffer_cpu_requests is defined and openshift_prometheus_alertbuffer_cpu_requests is not none %}
  149. cpu: "{{openshift_prometheus_alertbuffer_cpu_requests}}"
  150. {% endif %}
  151. limits:
  152. {% if openshift_prometheus_alertbuffer_memory_limit is defined and openshift_prometheus_alertbuffer_memory_limit is not none %}
  153. memory: "{{openshift_prometheus_alertbuffer_memory_limit}}"
  154. {% endif %}
  155. {% if openshift_prometheus_alertbuffer_cpu_limit is defined and openshift_prometheus_alertbuffer_cpu_limit is not none %}
  156. cpu: "{{openshift_prometheus_alertbuffer_cpu_limit}}"
  157. {% endif %}
  158. volumeMounts:
  159. - mountPath: /alert-buffer
  160. name: alert-buffer-data
  161. ports:
  162. - containerPort: 9099
  163. name: alert-buf
  164. - name: alertmanager
  165. args:
  166. - -config.file=/etc/alertmanager/alertmanager.yml
  167. image: "{{ openshift_prometheus_image_alertmanager }}"
  168. imagePullPolicy: IfNotPresent
  169. resources:
  170. requests:
  171. {% if openshift_prometheus_alertmanager_memory_requests is defined and openshift_prometheus_alertmanager_memory_requests is not none %}
  172. memory: "{{openshift_prometheus_alertmanager_memory_requests}}"
  173. {% endif %}
  174. {% if openshift_prometheus_alertmanager_cpu_requests is defined and openshift_prometheus_alertmanager_cpu_requests is not none %}
  175. cpu: "{{openshift_prometheus_alertmanager_cpu_requests}}"
  176. {% endif %}
  177. limits:
  178. {% if openshift_prometheus_alertmanager_memory_limit is defined and openshift_prometheus_alertmanager_memory_limit is not none %}
  179. memory: "{{openshift_prometheus_alertmanager_memory_limit}}"
  180. {% endif %}
  181. {% if openshift_prometheus_alertmanager_cpu_limit is defined and openshift_prometheus_alertmanager_cpu_limit is not none %}
  182. cpu: "{{openshift_prometheus_alertmanager_cpu_limit}}"
  183. {% endif %}
  184. ports:
  185. - containerPort: 9093
  186. name: web
  187. volumeMounts:
  188. - mountPath: /etc/alertmanager
  189. name: alertmanager-config
  190. - mountPath: /alertmanager
  191. name: alertmanager-data
  192. restartPolicy: Always
  193. volumes:
  194. - name: prometheus-config
  195. configMap:
  196. defaultMode: 420
  197. name: prometheus
  198. - name: prometheus-secrets
  199. secret:
  200. secretName: prometheus-proxy
  201. - name: prometheus-tls
  202. secret:
  203. secretName: prometheus-tls
  204. - name: prometheus-data
  205. {% if openshift_prometheus_storage_type == 'pvc' %}
  206. persistentVolumeClaim:
  207. claimName: {{ openshift_prometheus_pvc_name }}
  208. {% else %}
  209. emptydir: {}
  210. {% endif %}
  211. - name: alertmanager-config
  212. configMap:
  213. defaultMode: 420
  214. name: prometheus-alerts
  215. - name: alerts-secrets
  216. secret:
  217. secretName: alerts-proxy
  218. - name: alerts-tls
  219. secret:
  220. secretName: prometheus-alerts-tls
  221. - name: alertmanager-data
  222. {% if openshift_prometheus_alertmanager_storage_type == 'pvc' %}
  223. persistentVolumeClaim:
  224. claimName: {{ openshift_prometheus_alertmanager_pvc_name }}
  225. {% else %}
  226. emptydir: {}
  227. {% endif %}
  228. - name: alert-buffer-data
  229. {% if openshift_prometheus_alertbuffer_storage_type == 'pvc' %}
  230. persistentVolumeClaim:
  231. claimName: {{ openshift_prometheus_alertbuffer_pvc_name }}
  232. {% else %}
  233. emptydir: {}
  234. {% endif %}