statefulset-dolphinscheduler-worker.yaml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. #
  2. # Licensed to the Apache Software Foundation (ASF) under one or more
  3. # contributor license agreements. See the NOTICE file distributed with
  4. # this work for additional information regarding copyright ownership.
  5. # The ASF licenses this file to You under the Apache License, Version 2.0
  6. # (the "License"); you may not use this file except in compliance with
  7. # 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, software
  12. # distributed under the License is distributed on an "AS IS" BASIS,
  13. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. # See the License for the specific language governing permissions and
  15. # limitations under the License.
  16. #
  17. apiVersion: apps/v1
  18. kind: StatefulSet
  19. metadata:
  20. name: {{ include "dolphinscheduler.fullname" . }}-worker
  21. labels:
  22. app.kubernetes.io/name: {{ include "dolphinscheduler.fullname" . }}-worker
  23. app.kubernetes.io/instance: {{ .Release.Name }}
  24. app.kubernetes.io/managed-by: {{ .Release.Service }}
  25. app.kubernetes.io/component: worker
  26. spec:
  27. podManagementPolicy: {{ .Values.worker.podManagementPolicy }}
  28. replicas: {{ .Values.worker.replicas }}
  29. selector:
  30. matchLabels:
  31. app.kubernetes.io/name: {{ include "dolphinscheduler.fullname" . }}-worker
  32. app.kubernetes.io/instance: {{ .Release.Name }}
  33. app.kubernetes.io/managed-by: {{ .Release.Service }}
  34. app.kubernetes.io/component: worker
  35. serviceName: {{ template "dolphinscheduler.fullname" . }}-worker-headless
  36. template:
  37. metadata:
  38. labels:
  39. app.kubernetes.io/name: {{ include "dolphinscheduler.fullname" . }}-worker
  40. app.kubernetes.io/instance: {{ .Release.Name }}
  41. app.kubernetes.io/managed-by: {{ .Release.Service }}
  42. app.kubernetes.io/component: worker
  43. spec:
  44. {{- if .Values.worker.affinity }}
  45. affinity: {{- toYaml .Values.worker.affinity | nindent 8 }}
  46. {{- end }}
  47. {{- if .Values.worker.nodeSelector }}
  48. nodeSelector: {{- toYaml .Values.worker.nodeSelector | nindent 8 }}
  49. {{- end }}
  50. {{- if .Values.worker.tolerations }}
  51. tolerations: {{- toYaml . | nindent 8 }}
  52. {{- end }}
  53. initContainers:
  54. - name: init-zookeeper
  55. image: busybox:1.31.0
  56. command:
  57. - /bin/sh
  58. - -ec
  59. - |
  60. echo "${ZOOKEEPER_QUORUM}" | awk -F ',' 'BEGIN{ i=1 }{ while( i <= NF ){ print $i; i++ } }' | while read line; do
  61. while ! nc -z ${line%:*} ${line#*:}; do
  62. counter=$((counter+1))
  63. if [ $counter == 5 ]; then
  64. echo "Error: Couldn't connect to zookeeper."
  65. exit 1
  66. fi
  67. echo "Trying to connect to zookeeper at ${line}. Attempt $counter."
  68. sleep 60
  69. done
  70. done
  71. env:
  72. - name: ZOOKEEPER_QUORUM
  73. {{- if .Values.zookeeper.enabled }}
  74. value: "{{ template "dolphinscheduler.zookeeper.quorum" . }}"
  75. {{- else }}
  76. value: {{ .Values.externalZookeeper.zookeeperQuorum }}
  77. {{- end }}
  78. - name: init-postgresql
  79. image: busybox:1.31.0
  80. command:
  81. - /bin/sh
  82. - -ec
  83. - |
  84. while ! nc -z ${POSTGRESQL_HOST} ${POSTGRESQL_PORT}; do
  85. counter=$((counter+1))
  86. if [ $counter == 5 ]; then
  87. echo "Error: Couldn't connect to postgresql."
  88. exit 1
  89. fi
  90. echo "Trying to connect to postgresql at ${POSTGRESQL_HOST}:${POSTGRESQL_PORT}. Attempt $counter."
  91. sleep 60
  92. done
  93. env:
  94. - name: POSTGRESQL_HOST
  95. {{- if .Values.postgresql.enabled }}
  96. value: {{ template "dolphinscheduler.postgresql.fullname" . }}
  97. {{- else }}
  98. value: {{ .Values.externalDatabase.host | quote }}
  99. {{- end }}
  100. - name: POSTGRESQL_PORT
  101. {{- if .Values.postgresql.enabled }}
  102. value: "5432"
  103. {{- else }}
  104. value: {{ .Values.externalDatabase.port }}
  105. {{- end }}
  106. containers:
  107. - name: {{ include "dolphinscheduler.fullname" . }}-worker
  108. image: {{ include "dolphinscheduler.image.repository" . | quote }}
  109. args:
  110. - "worker-server"
  111. ports:
  112. - containerPort: 50051
  113. name: "logs-port"
  114. imagePullPolicy: {{ .Values.image.pullPolicy }}
  115. env:
  116. - name: TZ
  117. value: {{ .Values.timezone }}
  118. - name: WORKER_EXEC_THREADS
  119. valueFrom:
  120. configMapKeyRef:
  121. name: {{ include "dolphinscheduler.fullname" . }}-worker
  122. key: WORKER_EXEC_THREADS
  123. - name: WORKER_FETCH_TASK_NUM
  124. valueFrom:
  125. configMapKeyRef:
  126. name: {{ include "dolphinscheduler.fullname" . }}-worker
  127. key: WORKER_FETCH_TASK_NUM
  128. - name: WORKER_HEARTBEAT_INTERVAL
  129. valueFrom:
  130. configMapKeyRef:
  131. name: {{ include "dolphinscheduler.fullname" . }}-worker
  132. key: WORKER_HEARTBEAT_INTERVAL
  133. - name: WORKER_MAX_CPULOAD_AVG
  134. valueFrom:
  135. configMapKeyRef:
  136. name: {{ include "dolphinscheduler.fullname" . }}-worker
  137. key: WORKER_MAX_CPULOAD_AVG
  138. - name: WORKER_RESERVED_MEMORY
  139. valueFrom:
  140. configMapKeyRef:
  141. name: {{ include "dolphinscheduler.fullname" . }}-worker
  142. key: WORKER_RESERVED_MEMORY
  143. - name: POSTGRESQL_HOST
  144. {{- if .Values.postgresql.enabled }}
  145. value: {{ template "dolphinscheduler.postgresql.fullname" . }}
  146. {{- else }}
  147. value: {{ .Values.externalDatabase.host | quote }}
  148. {{- end }}
  149. - name: POSTGRESQL_PORT
  150. {{- if .Values.postgresql.enabled }}
  151. value: "5432"
  152. {{- else }}
  153. value: {{ .Values.externalDatabase.port }}
  154. {{- end }}
  155. - name: POSTGRESQL_USERNAME
  156. {{- if .Values.postgresql.enabled }}
  157. value: {{ .Values.postgresql.postgresqlUsername }}
  158. {{- else }}
  159. value: {{ .Values.externalDatabase.username | quote }}
  160. {{- end }}
  161. - name: POSTGRESQL_PASSWORD
  162. valueFrom:
  163. secretKeyRef:
  164. {{- if .Values.postgresql.enabled }}
  165. name: {{ template "dolphinscheduler.postgresql.fullname" . }}
  166. key: postgresql-password
  167. {{- else }}
  168. name: {{ printf "%s-%s" .Release.Name "externaldb" }}
  169. key: db-password
  170. {{- end }}
  171. - name: TASK_QUEUE
  172. {{- if .Values.zookeeper.enabled }}
  173. value: {{ .Values.zookeeper.taskQueue }}
  174. {{- else }}
  175. value: {{ .Values.externalZookeeper.taskQueue }}
  176. {{- end }}
  177. - name: ZOOKEEPER_QUORUM
  178. {{- if .Values.zookeeper.enabled }}
  179. value: "{{ template "dolphinscheduler.zookeeper.quorum" . }}"
  180. {{- else }}
  181. value: {{ .Values.externalZookeeper.zookeeperQuorum }}
  182. {{- end }}
  183. {{- if .Values.worker.livenessProbe.enabled }}
  184. livenessProbe:
  185. exec:
  186. command:
  187. - sh
  188. - /root/checkpoint.sh
  189. - worker-server
  190. initialDelaySeconds: {{ .Values.worker.livenessProbe.initialDelaySeconds }}
  191. periodSeconds: {{ .Values.worker.livenessProbe.periodSeconds }}
  192. timeoutSeconds: {{ .Values.worker.livenessProbe.timeoutSeconds }}
  193. successThreshold: {{ .Values.worker.livenessProbe.successThreshold }}
  194. failureThreshold: {{ .Values.worker.livenessProbe.failureThreshold }}
  195. {{- end }}
  196. {{- if .Values.worker.readinessProbe.enabled }}
  197. readinessProbe:
  198. exec:
  199. command:
  200. - sh
  201. - /root/checkpoint.sh
  202. - worker-server
  203. initialDelaySeconds: {{ .Values.worker.readinessProbe.initialDelaySeconds }}
  204. periodSeconds: {{ .Values.worker.readinessProbe.periodSeconds }}
  205. timeoutSeconds: {{ .Values.worker.readinessProbe.timeoutSeconds }}
  206. successThreshold: {{ .Values.worker.readinessProbe.successThreshold }}
  207. failureThreshold: {{ .Values.worker.readinessProbe.failureThreshold }}
  208. {{- end }}
  209. volumeMounts:
  210. - mountPath: {{ include "dolphinscheduler.worker.base.dir" . | quote }}
  211. name: {{ include "dolphinscheduler.fullname" . }}-worker-data
  212. - mountPath: "/opt/dolphinscheduler/logs"
  213. name: {{ include "dolphinscheduler.fullname" . }}-worker-logs
  214. - mountPath: "/opt/dolphinscheduler/conf/env/dolphinscheduler_env.sh"
  215. subPath: "dolphinscheduler_env.sh"
  216. name: {{ include "dolphinscheduler.fullname" . }}-worker-configmap
  217. volumes:
  218. - name: {{ include "dolphinscheduler.fullname" . }}-worker-data
  219. {{- if .Values.worker.persistentVolumeClaim.dataPersistentVolume.enabled }}
  220. persistentVolumeClaim:
  221. claimName: {{ include "dolphinscheduler.fullname" . }}-worker-data
  222. {{- else }}
  223. emptyDir: {}
  224. {{- end }}
  225. - name: {{ include "dolphinscheduler.fullname" . }}-worker-logs
  226. {{- if .Values.worker.persistentVolumeClaim.logsPersistentVolume.enabled }}
  227. persistentVolumeClaim:
  228. claimName: {{ include "dolphinscheduler.fullname" . }}-worker-logs
  229. {{- else }}
  230. emptyDir: {}
  231. {{- end }}
  232. - name: {{ include "dolphinscheduler.fullname" . }}-worker-configmap
  233. configMap:
  234. defaultMode: 0777
  235. name: {{ include "dolphinscheduler.fullname" . }}-worker
  236. items:
  237. - key: dolphinscheduler_env.sh
  238. path: dolphinscheduler_env.sh
  239. {{- if .Values.worker.persistentVolumeClaim.enabled }}
  240. volumeClaimTemplates:
  241. {{- if .Values.worker.persistentVolumeClaim.dataPersistentVolume.enabled }}
  242. - metadata:
  243. name: {{ include "dolphinscheduler.fullname" . }}-worker-data
  244. labels:
  245. app.kubernetes.io/name: {{ include "dolphinscheduler.fullname" . }}-worker-data
  246. app.kubernetes.io/instance: {{ .Release.Name }}
  247. app.kubernetes.io/managed-by: {{ .Release.Service }}
  248. spec:
  249. accessModes:
  250. {{- range .Values.worker.persistentVolumeClaim.dataPersistentVolume.accessModes }}
  251. - {{ . | quote }}
  252. {{- end }}
  253. storageClassName: {{ .Values.worker.persistentVolumeClaim.dataPersistentVolume.storageClassName | quote }}
  254. resources:
  255. requests:
  256. storage: {{ .Values.worker.persistentVolumeClaim.dataPersistentVolume.storage | quote }}
  257. {{- end }}
  258. {{- if .Values.worker.persistentVolumeClaim.logsPersistentVolume.enabled }}
  259. - metadata:
  260. name: {{ include "dolphinscheduler.fullname" . }}-worker-logs
  261. labels:
  262. app.kubernetes.io/name: {{ include "dolphinscheduler.fullname" . }}-worker-logs
  263. app.kubernetes.io/instance: {{ .Release.Name }}
  264. app.kubernetes.io/managed-by: {{ .Release.Service }}
  265. spec:
  266. accessModes:
  267. {{- range .Values.worker.persistentVolumeClaim.logsPersistentVolume.accessModes }}
  268. - {{ . | quote }}
  269. {{- end }}
  270. storageClassName: {{ .Values.worker.persistentVolumeClaim.logsPersistentVolume.storageClassName | quote }}
  271. resources:
  272. requests:
  273. storage: {{ .Values.worker.persistentVolumeClaim.logsPersistentVolume.storage | quote }}
  274. {{- end }}
  275. {{- end }}