webserver-deployment.yaml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. # Licensed to the Apache Software Foundation (ASF) under one
  2. # or more contributor license agreements. See the NOTICE file
  3. # distributed with this work for additional information
  4. # regarding copyright ownership. The ASF licenses this file
  5. # to you under the Apache License, Version 2.0 (the
  6. # "License"); you may not use this file except in compliance
  7. # with the License. You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing,
  12. # software distributed under the License is distributed on an
  13. # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  14. # KIND, either express or implied. See the License for the
  15. # specific language governing permissions and limitations
  16. # under the License.
  17. ################################
  18. ## Airflow Webserver Deployment
  19. #################################
  20. {{- $nodeSelector := or .Values.webserver.nodeSelector .Values.nodeSelector }}
  21. {{- $affinity := or .Values.webserver.affinity .Values.affinity }}
  22. {{- $tolerations := or .Values.webserver.tolerations .Values.tolerations }}
  23. {{- $topologySpreadConstraints := or .Values.webserver.topologySpreadConstraints .Values.topologySpreadConstraints }}
  24. {{- $securityContext := include "airflowSecurityContext" (list . .Values.webserver) }}
  25. kind: Deployment
  26. apiVersion: apps/v1
  27. metadata:
  28. name: {{ .Release.Name }}-webserver
  29. labels:
  30. tier: airflow
  31. component: webserver
  32. release: {{ .Release.Name }}
  33. chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
  34. heritage: {{ .Release.Service }}
  35. {{- with .Values.labels }}
  36. {{ toYaml . | indent 4 }}
  37. {{- end }}
  38. spec:
  39. replicas: {{ .Values.webserver.replicas }}
  40. strategy:
  41. {{- if .Values.webserver.strategy }}
  42. {{- toYaml .Values.webserver.strategy | nindent 4 }}
  43. {{- else }}
  44. {{- if semverCompare ">=2.0.0" .Values.airflowVersion }}
  45. # Here we define the rolling update strategy
  46. # - maxSurge define how many pod we can add at a time
  47. # - maxUnavailable define how many pod can be unavailable
  48. # during the rolling update
  49. # Setting maxUnavailable to 0 would make sure we have the appropriate
  50. # capacity during the rolling update.
  51. # You can also use percentage based value instead of integer.
  52. type: RollingUpdate
  53. rollingUpdate:
  54. maxSurge: 1
  55. maxUnavailable: 0
  56. {{- else }}
  57. type: Recreate
  58. {{- end}}
  59. {{- end}}
  60. selector:
  61. matchLabels:
  62. tier: airflow
  63. component: webserver
  64. release: {{ .Release.Name }}
  65. template:
  66. metadata:
  67. labels:
  68. tier: airflow
  69. component: webserver
  70. release: {{ .Release.Name }}
  71. {{- with .Values.labels }}
  72. {{ toYaml . | indent 8 }}
  73. {{- end }}
  74. annotations:
  75. checksum/metadata-secret: {{ include (print $.Template.BasePath "/secrets/metadata-connection-secret.yaml") . | sha256sum }}
  76. checksum/pgbouncer-config-secret: {{ include (print $.Template.BasePath "/secrets/pgbouncer-config-secret.yaml") . | sha256sum }}
  77. checksum/webserver-secret-key: {{ include (print $.Template.BasePath "/secrets/webserver-secret-key-secret.yaml") . | sha256sum }}
  78. checksum/airflow-config: {{ include (print $.Template.BasePath "/configmaps/configmap.yaml") . | sha256sum }}
  79. checksum/webserver-config: {{ include (print $.Template.BasePath "/configmaps/webserver-configmap.yaml") . | sha256sum }}
  80. checksum/extra-configmaps: {{ include (print $.Template.BasePath "/configmaps/extra-configmaps.yaml") . | sha256sum }}
  81. checksum/extra-secrets: {{ include (print $.Template.BasePath "/secrets/extra-secrets.yaml") . | sha256sum }}
  82. {{- if .Values.airflowPodAnnotations }}
  83. {{- toYaml .Values.airflowPodAnnotations | nindent 8 }}
  84. {{- end }}
  85. {{- if .Values.webserver.podAnnotations }}
  86. {{- toYaml .Values.webserver.podAnnotations | nindent 8 }}
  87. {{- end }}
  88. spec:
  89. serviceAccountName: {{ include "webserver.serviceAccountName" . }}
  90. {{- if .Values.webserver.priorityClassName }}
  91. priorityClassName: {{ .Values.webserver.priorityClassName }}
  92. {{- end }}
  93. nodeSelector:
  94. {{ toYaml $nodeSelector | indent 8 }}
  95. affinity:
  96. {{- if $affinity }}
  97. {{ toYaml $affinity | indent 8 }}
  98. {{- else }}
  99. podAntiAffinity:
  100. preferredDuringSchedulingIgnoredDuringExecution:
  101. - podAffinityTerm:
  102. labelSelector:
  103. matchLabels:
  104. component: webserver
  105. topologyKey: kubernetes.io/hostname
  106. weight: 100
  107. {{- end }}
  108. tolerations:
  109. {{ toYaml $tolerations | indent 8 }}
  110. topologySpreadConstraints:
  111. {{ toYaml $topologySpreadConstraints | indent 8 }}
  112. restartPolicy: Always
  113. securityContext: {{ $securityContext | nindent 8 }}
  114. {{- if or .Values.registry.secretName .Values.registry.connection }}
  115. imagePullSecrets:
  116. - name: {{ template "registry_secret" . }}
  117. {{- end }}
  118. initContainers:
  119. {{- if .Values.webserver.waitForMigrations.enabled }}
  120. - name: wait-for-airflow-migrations
  121. resources:
  122. {{ toYaml .Values.webserver.resources | indent 12 }}
  123. image: {{ template "airflow_image_for_migrations" . }}
  124. imagePullPolicy: {{ .Values.images.airflow.pullPolicy }}
  125. volumeMounts:
  126. - name: config
  127. mountPath: {{ template "airflow_config_path" . }}
  128. subPath: airflow.cfg
  129. readOnly: true
  130. args:
  131. {{- include "wait-for-migrations-command" . | indent 10 }}
  132. envFrom:
  133. {{- include "custom_airflow_environment_from" . | default "\n []" | indent 10 }}
  134. env:
  135. {{- include "custom_airflow_environment" . | indent 10 }}
  136. {{- include "standard_airflow_environment" . | indent 10 }}
  137. {{- end }}
  138. {{- if and (.Values.dags.gitSync.enabled) (not .Values.dags.persistence.enabled) (semverCompare "<2.0.0" .Values.airflowVersion) }}
  139. {{- include "git_sync_container" (dict "Values" .Values "is_init" "true") | nindent 8 }}
  140. {{- end }}
  141. {{- if .Values.webserver.extraInitContainers }}
  142. {{- toYaml .Values.webserver.extraInitContainers | nindent 8 }}
  143. {{- end }}
  144. containers:
  145. - name: webserver
  146. image: {{ template "airflow_image" . }}
  147. imagePullPolicy: {{ .Values.images.airflow.pullPolicy }}
  148. {{- if .Values.webserver.command }}
  149. command: {{ tpl (toYaml .Values.webserver.command) . | nindent 12 }}
  150. {{- end }}
  151. {{- if .Values.webserver.args }}
  152. args: {{ tpl (toYaml .Values.webserver.args) . | nindent 12 }}
  153. {{- end }}
  154. resources:
  155. {{ toYaml .Values.webserver.resources | indent 12 }}
  156. volumeMounts:
  157. {{- if semverCompare ">=1.10.12" .Values.airflowVersion }}
  158. - name: config
  159. mountPath: {{ include "airflow_pod_template_file" . }}/pod_template_file.yaml
  160. subPath: pod_template_file.yaml
  161. readOnly: true
  162. {{- end }}
  163. - name: config
  164. mountPath: {{ template "airflow_config_path" . }}
  165. subPath: airflow.cfg
  166. readOnly: true
  167. {{- if .Values.webserver.webserverConfig }}
  168. - name: webserver-config
  169. mountPath: {{ template "airflow_webserver_config_path" . }}
  170. subPath: webserver_config.py
  171. readOnly: true
  172. {{- end }}
  173. {{- if .Values.airflowLocalSettings }}
  174. - name: config
  175. mountPath: {{ template "airflow_local_setting_path" . }}
  176. subPath: airflow_local_settings.py
  177. readOnly: true
  178. {{- end }}
  179. {{- if and (semverCompare "<2.0.0" .Values.airflowVersion) (or .Values.dags.gitSync.enabled .Values.dags.persistence.enabled) }}
  180. {{- include "airflow_dags_mount" . | nindent 12 }}
  181. {{- end }}
  182. {{- if .Values.logs.persistence.enabled }}
  183. - name: logs
  184. mountPath: {{ template "airflow_logs" . }}
  185. {{- end }}
  186. {{- if .Values.webserver.extraVolumeMounts }}
  187. {{ toYaml .Values.webserver.extraVolumeMounts | indent 12 }}
  188. {{- end }}
  189. ports:
  190. - name: airflow-ui
  191. containerPort: {{ .Values.ports.airflowUI }}
  192. livenessProbe:
  193. httpGet:
  194. path: {{if .Values.config.webserver.base_url }}{{- with urlParse (tpl .Values.config.webserver.base_url .) }}{{ .path }}{{end}}{{end}}/health
  195. port: {{ .Values.ports.airflowUI }}
  196. {{- if .Values.config.webserver.base_url}}
  197. httpHeaders:
  198. - name: Host
  199. value: {{ regexReplaceAll ":\\d+$" (urlParse (tpl .Values.config.webserver.base_url .)).host "" }}
  200. {{- end }}
  201. initialDelaySeconds: {{ .Values.webserver.livenessProbe.initialDelaySeconds | default 15 }}
  202. timeoutSeconds: {{ .Values.webserver.livenessProbe.timeoutSeconds | default 30 }}
  203. failureThreshold: {{ .Values.webserver.livenessProbe.failureThreshold | default 20 }}
  204. periodSeconds: {{ .Values.webserver.livenessProbe.periodSeconds | default 5 }}
  205. readinessProbe:
  206. httpGet:
  207. path: {{if .Values.config.webserver.base_url }}{{- with urlParse (tpl .Values.config.webserver.base_url .) }}{{ .path }}{{end}}{{end}}/health
  208. port: {{ .Values.ports.airflowUI }}
  209. {{- if .Values.config.webserver.base_url}}
  210. httpHeaders:
  211. - name: Host
  212. value: {{ regexReplaceAll ":\\d+$" (urlParse (tpl .Values.config.webserver.base_url .)).host "" }}
  213. {{- end }}
  214. initialDelaySeconds: {{ .Values.webserver.readinessProbe.initialDelaySeconds | default 15 }}
  215. timeoutSeconds: {{ .Values.webserver.readinessProbe.timeoutSeconds | default 30 }}
  216. failureThreshold: {{ .Values.webserver.readinessProbe.failureThreshold | default 20 }}
  217. periodSeconds: {{ .Values.webserver.readinessProbe.periodSeconds | default 5 }}
  218. envFrom:
  219. {{- include "custom_airflow_environment_from" . | default "\n []" | indent 10 }}
  220. env:
  221. {{- include "custom_airflow_environment" . | indent 10 }}
  222. {{- include "standard_airflow_environment" . | indent 10 }}
  223. {{- if and (.Values.dags.gitSync.enabled) (not .Values.dags.persistence.enabled) (semverCompare "<2.0.0" .Values.airflowVersion) }}
  224. {{- include "git_sync_container" . | indent 8 }}
  225. {{- end }}
  226. {{- if .Values.webserver.extraContainers }}
  227. {{- toYaml .Values.webserver.extraContainers | nindent 8 }}
  228. {{- end }}
  229. volumes:
  230. - name: config
  231. configMap:
  232. name: {{ template "airflow_config" . }}
  233. {{- if .Values.webserver.webserverConfig }}
  234. - name: webserver-config
  235. configMap:
  236. name: {{ .Release.Name }}-webserver-config
  237. {{- end }}
  238. {{- if (semverCompare "<2.0.0" .Values.airflowVersion) }}
  239. {{- if .Values.dags.persistence.enabled }}
  240. - name: dags
  241. persistentVolumeClaim:
  242. claimName: {{ template "airflow_dags_volume_claim" . }}
  243. {{- else if .Values.dags.gitSync.enabled }}
  244. - name: dags
  245. emptyDir: {}
  246. {{- if .Values.dags.gitSync.sshKeySecret }}
  247. {{- include "git_sync_ssh_key_volume" . | indent 8 }}
  248. {{- end }}
  249. {{- end }}
  250. {{- end }}
  251. {{- if .Values.logs.persistence.enabled }}
  252. - name: logs
  253. persistentVolumeClaim:
  254. claimName: {{ template "airflow_logs_volume_claim" . }}
  255. {{- end }}
  256. {{- if .Values.webserver.extraVolumes }}
  257. {{ toYaml .Values.webserver.extraVolumes | indent 8 }}
  258. {{- end }}