master-statefulset.yaml 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. {{- if .Values.master.enabled }}
  2. apiVersion: apps/v1
  3. kind: StatefulSet
  4. metadata:
  5. name: {{ template "seaweedfs.name" . }}-master
  6. namespace: {{ .Release.Namespace }}
  7. labels:
  8. app.kubernetes.io/name: {{ template "seaweedfs.name" . }}
  9. helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
  10. app.kubernetes.io/managed-by: {{ .Release.Service }}
  11. app.kubernetes.io/instance: {{ .Release.Name }}
  12. app.kubernetes.io/component: master
  13. {{- if .Values.master.annotations }}
  14. annotations:
  15. {{- toYaml .Values.master.annotations | nindent 4 }}
  16. {{- end }}
  17. spec:
  18. serviceName: {{ template "seaweedfs.name" . }}-master
  19. podManagementPolicy: {{ .Values.master.podManagementPolicy }}
  20. replicas: {{ .Values.master.replicas }}
  21. {{- if (gt (int .Values.master.updatePartition) 0) }}
  22. updateStrategy:
  23. type: RollingUpdate
  24. rollingUpdate:
  25. partition: {{ .Values.master.updatePartition }}
  26. {{- end }}
  27. selector:
  28. matchLabels:
  29. app.kubernetes.io/name: {{ template "seaweedfs.name" . }}
  30. app.kubernetes.io/instance: {{ .Release.Name }}
  31. app.kubernetes.io/component: master
  32. template:
  33. metadata:
  34. labels:
  35. app.kubernetes.io/name: {{ template "seaweedfs.name" . }}
  36. helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
  37. app.kubernetes.io/instance: {{ .Release.Name }}
  38. app.kubernetes.io/component: master
  39. {{ with .Values.podLabels }}
  40. {{- toYaml . | nindent 8 }}
  41. {{- end }}
  42. {{- with .Values.master.podLabels }}
  43. {{- toYaml . | nindent 8 }}
  44. {{- end }}
  45. annotations:
  46. {{ with .Values.podAnnotations }}
  47. {{- toYaml . | nindent 8 }}
  48. {{- end }}
  49. {{- with .Values.master.podAnnotations }}
  50. {{- toYaml . | nindent 8 }}
  51. {{- end }}
  52. spec:
  53. restartPolicy: {{ default .Values.global.restartPolicy .Values.master.restartPolicy }}
  54. {{- if .Values.master.affinity }}
  55. affinity:
  56. {{ tpl .Values.master.affinity . | nindent 8 | trim }}
  57. {{- end }}
  58. {{- if .Values.master.topologySpreadConstraints }}
  59. topologySpreadConstraints:
  60. {{ tpl .Values.master.topologySpreadConstraints . | nindent 8 | trim }}
  61. {{- end }}
  62. {{- if .Values.master.tolerations }}
  63. tolerations:
  64. {{ tpl .Values.master.tolerations . | nindent 8 | trim }}
  65. {{- end }}
  66. {{- include "seaweedfs.imagePullSecrets" . | nindent 6 }}
  67. terminationGracePeriodSeconds: 60
  68. {{- if .Values.master.priorityClassName }}
  69. priorityClassName: {{ .Values.master.priorityClassName | quote }}
  70. {{- end }}
  71. enableServiceLinks: false
  72. {{- if .Values.global.createClusterRole }}
  73. serviceAccountName: {{ .Values.master.serviceAccountName | default .Values.global.serviceAccountName | quote }} # for deleting statefulset pods after migration
  74. {{- end }}
  75. {{- if .Values.master.initContainers }}
  76. initContainers:
  77. {{ tpl .Values.master.initContainers . | nindent 8 | trim }}
  78. {{- end }}
  79. {{- if .Values.master.podSecurityContext.enabled }}
  80. securityContext: {{- omit .Values.master.podSecurityContext "enabled" | toYaml | nindent 8 }}
  81. {{- end }}
  82. containers:
  83. - name: seaweedfs
  84. image: {{ template "master.image" . }}
  85. imagePullPolicy: {{ default "IfNotPresent" .Values.global.imagePullPolicy }}
  86. env:
  87. - name: POD_IP
  88. valueFrom:
  89. fieldRef:
  90. fieldPath: status.podIP
  91. - name: POD_NAME
  92. valueFrom:
  93. fieldRef:
  94. fieldPath: metadata.name
  95. - name: NAMESPACE
  96. valueFrom:
  97. fieldRef:
  98. fieldPath: metadata.namespace
  99. - name: SEAWEEDFS_FULLNAME
  100. value: "{{ template "seaweedfs.name" . }}"
  101. {{- if .Values.master.extraEnvironmentVars }}
  102. {{- range $key, $value := .Values.master.extraEnvironmentVars }}
  103. - name: {{ $key }}
  104. {{- if kindIs "string" $value }}
  105. value: {{ $value | quote }}
  106. {{- else }}
  107. valueFrom:
  108. {{ toYaml $value | nindent 16 | trim }}
  109. {{- end -}}
  110. {{- end }}
  111. {{- end }}
  112. {{- if .Values.global.extraEnvironmentVars }}
  113. {{- range $key, $value := .Values.global.extraEnvironmentVars }}
  114. - name: {{ $key }}
  115. {{- if kindIs "string" $value }}
  116. value: {{ $value | quote }}
  117. {{- else }}
  118. valueFrom:
  119. {{ toYaml $value | nindent 16 | trim }}
  120. {{- end -}}
  121. {{- end }}
  122. {{- end }}
  123. command:
  124. - "/bin/sh"
  125. - "-ec"
  126. - |
  127. exec /usr/bin/weed \
  128. {{- if or (eq .Values.master.logs.type "hostPath") (eq .Values.master.logs.type "persistentVolumeClaim") (eq .Values.master.logs.type "emptyDir") }}
  129. -logdir=/logs \
  130. {{- else }}
  131. -logtostderr=true \
  132. {{- end }}
  133. {{- if .Values.master.loggingOverrideLevel }}
  134. -v={{ .Values.master.loggingOverrideLevel }} \
  135. {{- else }}
  136. -v={{ .Values.global.loggingLevel }} \
  137. {{- end }}
  138. master \
  139. -port={{ .Values.master.port }} \
  140. -mdir=/data \
  141. -ip.bind={{ .Values.master.ipBind }} \
  142. {{- if .Values.global.enableReplication }}
  143. -defaultReplication={{ .Values.global.replicationPlacement }} \
  144. {{- else }}
  145. -defaultReplication={{ .Values.master.defaultReplication }} \
  146. {{- end }}
  147. {{- if .Values.master.volumePreallocate }}
  148. -volumePreallocate \
  149. {{- end }}
  150. {{- if .Values.global.monitoring.enabled }}
  151. {{- if and .Values.global.monitoring.gatewayHost .Values.global.monitoring.gatewayPort }}
  152. -metrics.address="{{ .Values.global.monitoring.gatewayHost }}:{{ .Values.global.monitoring.gatewayPort }}" \
  153. {{- if .Values.master.metricsIntervalSec }}
  154. -metrics.intervalSeconds={{ .Values.master.metricsIntervalSec }} \
  155. {{- end }}
  156. {{- end }}
  157. {{- end }}
  158. {{- if .Values.master.metricsPort }}
  159. -metricsPort={{ .Values.master.metricsPort }} \
  160. {{- end }}
  161. {{- if .Values.master.metricsIp }}
  162. -metricsIp={{ .Values.master.metricsIp }} \
  163. {{- end }}
  164. -volumeSizeLimitMB={{ .Values.master.volumeSizeLimitMB }} \
  165. {{- if .Values.master.disableHttp }}
  166. -disableHttp \
  167. {{- end }}
  168. {{- if .Values.master.resumeState }}
  169. -resumeState \
  170. {{- end }}
  171. {{- if .Values.master.raftHashicorp }}
  172. -raftHashicorp \
  173. {{- end }}
  174. {{- if .Values.master.raftBootstrap }}
  175. -raftBootstrap \
  176. {{- end }}
  177. {{- if .Values.master.electionTimeout }}
  178. -electionTimeout={{ .Values.master.electionTimeout }} \
  179. {{- end }}
  180. {{- if .Values.master.heartbeatInterval }}
  181. -heartbeatInterval={{ .Values.master.heartbeatInterval }} \
  182. {{- end }}
  183. {{- if .Values.master.garbageThreshold }}
  184. -garbageThreshold={{ .Values.master.garbageThreshold }} \
  185. {{- end }}
  186. -ip=${POD_NAME}.${SEAWEEDFS_FULLNAME}-master.{{ .Release.Namespace }} \
  187. -peers={{ range $index := until (.Values.master.replicas | int) }}${SEAWEEDFS_FULLNAME}-master-{{ $index }}.${SEAWEEDFS_FULLNAME}-master.{{ $.Release.Namespace }}:{{ $.Values.master.port }}{{ if lt $index (sub ($.Values.master.replicas | int) 1) }},{{ end }}{{ end }} \
  188. {{- range .Values.master.extraArgs }}
  189. {{ . }} \
  190. {{- end }}
  191. volumeMounts:
  192. - name : data-{{ .Release.Namespace }}
  193. mountPath: /data
  194. {{- if or (eq .Values.master.logs.type "hostPath") (eq .Values.master.logs.type "persistentVolumeClaim") (eq .Values.master.logs.type "emptyDir") }}
  195. - name: seaweedfs-master-log-volume
  196. mountPath: "/logs/"
  197. {{- end }}
  198. - name: master-config
  199. readOnly: true
  200. mountPath: /etc/seaweedfs/master.toml
  201. subPath: master.toml
  202. {{- if .Values.global.enableSecurity }}
  203. - name: security-config
  204. readOnly: true
  205. mountPath: /etc/seaweedfs/security.toml
  206. subPath: security.toml
  207. - name: ca-cert
  208. readOnly: true
  209. mountPath: /usr/local/share/ca-certificates/ca/
  210. - name: master-cert
  211. readOnly: true
  212. mountPath: /usr/local/share/ca-certificates/master/
  213. - name: volume-cert
  214. readOnly: true
  215. mountPath: /usr/local/share/ca-certificates/volume/
  216. - name: filer-cert
  217. readOnly: true
  218. mountPath: /usr/local/share/ca-certificates/filer/
  219. - name: client-cert
  220. readOnly: true
  221. mountPath: /usr/local/share/ca-certificates/client/
  222. {{- end }}
  223. {{ tpl .Values.master.extraVolumeMounts . | nindent 12 | trim }}
  224. ports:
  225. - containerPort: {{ .Values.master.port }}
  226. name: swfs-master
  227. {{- if and .Values.global.monitoring.enabled .Values.master.metricsPort }}
  228. - containerPort: {{ .Values.master.metricsPort }}
  229. name: metrics
  230. {{- end }}
  231. - containerPort: {{ .Values.master.grpcPort }}
  232. #name: swfs-master-grpc
  233. {{- if .Values.master.readinessProbe.enabled }}
  234. readinessProbe:
  235. httpGet:
  236. path: {{ .Values.master.readinessProbe.httpGet.path }}
  237. port: {{ .Values.master.port }}
  238. scheme: {{ .Values.master.readinessProbe.scheme }}
  239. initialDelaySeconds: {{ .Values.master.readinessProbe.initialDelaySeconds }}
  240. periodSeconds: {{ .Values.master.readinessProbe.periodSeconds }}
  241. successThreshold: {{ .Values.master.readinessProbe.successThreshold }}
  242. failureThreshold: {{ .Values.master.readinessProbe.failureThreshold }}
  243. timeoutSeconds: {{ .Values.master.readinessProbe.timeoutSeconds }}
  244. {{- end }}
  245. {{- if .Values.master.livenessProbe.enabled }}
  246. livenessProbe:
  247. httpGet:
  248. path: {{ .Values.master.livenessProbe.httpGet.path }}
  249. port: {{ .Values.master.port }}
  250. scheme: {{ .Values.master.livenessProbe.scheme }}
  251. initialDelaySeconds: {{ .Values.master.livenessProbe.initialDelaySeconds }}
  252. periodSeconds: {{ .Values.master.livenessProbe.periodSeconds }}
  253. successThreshold: {{ .Values.master.livenessProbe.successThreshold }}
  254. failureThreshold: {{ .Values.master.livenessProbe.failureThreshold }}
  255. timeoutSeconds: {{ .Values.master.livenessProbe.timeoutSeconds }}
  256. {{- end }}
  257. {{- with .Values.master.resources }}
  258. resources:
  259. {{- toYaml . | nindent 12 }}
  260. {{- end }}
  261. {{- if .Values.master.containerSecurityContext.enabled }}
  262. securityContext: {{- omit .Values.master.containerSecurityContext "enabled" | toYaml | nindent 12 }}
  263. {{- end }}
  264. {{- if .Values.master.sidecars }}
  265. {{- include "common.tplvalues.render" (dict "value" .Values.master.sidecars "context" $) | nindent 8 }}
  266. {{- end }}
  267. volumes:
  268. {{- if eq .Values.master.logs.type "hostPath" }}
  269. - name: seaweedfs-master-log-volume
  270. hostPath:
  271. path: {{ .Values.master.logs.hostPathPrefix }}/logs/seaweedfs/master
  272. type: DirectoryOrCreate
  273. {{- end }}
  274. {{- if eq .Values.master.logs.type "existingClaim" }}
  275. - name: seaweedfs-master-log-volume
  276. persistentVolumeClaim:
  277. claimName: {{ .Values.master.logs.claimName }}
  278. {{- end }}
  279. {{- if eq .Values.master.logs.type "emptyDir" }}
  280. - name: seaweedfs-master-log-volume
  281. emptyDir: {}
  282. {{- end }}
  283. {{- if eq .Values.master.data.type "hostPath" }}
  284. - name: data-{{ .Release.Namespace }}
  285. hostPath:
  286. path: {{ .Values.master.data.hostPathPrefix }}/seaweed-master/
  287. type: DirectoryOrCreate
  288. {{- end }}
  289. {{- if eq .Values.master.data.type "existingClaim" }}
  290. - name: data-{{ .Release.Namespace }}
  291. persistentVolumeClaim:
  292. claimName: {{ .Values.master.data.claimName }}
  293. {{- end }}
  294. {{- if eq .Values.master.data.type "emptyDir" }}
  295. - name: data-{{ .Release.Namespace }}
  296. emptyDir: {}
  297. {{- end }}
  298. - name: master-config
  299. configMap:
  300. name: {{ template "seaweedfs.name" . }}-master-config
  301. {{- if .Values.global.enableSecurity }}
  302. - name: security-config
  303. configMap:
  304. name: {{ template "seaweedfs.name" . }}-security-config
  305. - name: ca-cert
  306. secret:
  307. secretName: {{ template "seaweedfs.name" . }}-ca-cert
  308. - name: master-cert
  309. secret:
  310. secretName: {{ template "seaweedfs.name" . }}-master-cert
  311. - name: volume-cert
  312. secret:
  313. secretName: {{ template "seaweedfs.name" . }}-volume-cert
  314. - name: filer-cert
  315. secret:
  316. secretName: {{ template "seaweedfs.name" . }}-filer-cert
  317. - name: client-cert
  318. secret:
  319. secretName: {{ template "seaweedfs.name" . }}-client-cert
  320. {{- end }}
  321. {{ tpl .Values.master.extraVolumes . | indent 8 | trim }}
  322. {{- if .Values.master.nodeSelector }}
  323. nodeSelector:
  324. {{ tpl .Values.master.nodeSelector . | indent 8 | trim }}
  325. {{- end }}
  326. {{- $pvc_exists := include "master.pvc_exists" . -}}
  327. {{- if $pvc_exists }}
  328. volumeClaimTemplates:
  329. {{- if eq .Values.master.data.type "persistentVolumeClaim"}}
  330. - metadata:
  331. name: data-{{ .Release.Namespace }}
  332. {{- with .Values.master.data.annotations }}
  333. annotations:
  334. {{- toYaml . | nindent 10 }}
  335. {{- end }}
  336. spec:
  337. accessModes: [ "ReadWriteOnce" ]
  338. storageClassName: {{ .Values.master.data.storageClass }}
  339. resources:
  340. requests:
  341. storage: {{ .Values.master.data.size }}
  342. {{- end }}
  343. {{- if eq .Values.master.logs.type "persistentVolumeClaim"}}
  344. - metadata:
  345. name: seaweedfs-master-log-volume
  346. {{- with .Values.master.logs.annotations }}
  347. annotations:
  348. {{- toYaml . | nindent 10 }}
  349. {{- end }}
  350. spec:
  351. accessModes: [ "ReadWriteOnce" ]
  352. storageClassName: {{ .Values.master.logs.storageClass }}
  353. resources:
  354. requests:
  355. storage: {{ .Values.master.logs.size }}
  356. {{- end }}
  357. {{- end }}
  358. {{- end }}