statefulset.yaml 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. {{- if (eq (include "kafka.combinedMode" .) "false") }}
  2. {{- $thisValues := .Values.controller }}
  3. {{- $thisFullName := include "kafka.controller.fullname" . }}
  4. {{- $controllerFullName := include "kafka.controller.fullname" . }}
  5. {{- $componet := "controller" }}
  6. {{- $antiAffinityTopologyKey := default "kubernetes.io/hostname" $thisValues.antiAffinityTopologyKey }}
  7. ---
  8. apiVersion: apps/v1
  9. kind: StatefulSet
  10. metadata:
  11. name: {{ $thisFullName }}
  12. labels:
  13. {{- include "kafka.labels" . | nindent 4 }}
  14. component: {{ $componet | quote }}
  15. spec:
  16. {{- if $thisValues.replicaCount }}
  17. replicas: {{ $thisValues.replicaCount }}
  18. {{- end }}
  19. selector:
  20. matchLabels:
  21. {{- include "kafka.selectorLabels" . | nindent 6 }}
  22. component: {{ $componet | quote }}
  23. serviceName: {{ include "kafka.controller.headless.serviceName" . }}
  24. updateStrategy:
  25. type: {{ ( $thisValues.updateStrategy | default dict ).type | default "RollingUpdate" }}
  26. template:
  27. metadata:
  28. {{- if or $.Values.podAnnotations $thisValues.podAnnotations }}
  29. annotations:
  30. {{- with $.Values.podAnnotations }}
  31. {{- toYaml . | nindent 8 }}
  32. {{- end }}
  33. {{- with $thisValues.podAnnotations }}
  34. {{- toYaml . | nindent 8 }}
  35. {{- end }}
  36. {{- end }}
  37. labels:
  38. {{- include "kafka.selectorLabels" . | nindent 8 }}
  39. component: {{ $componet | quote }}
  40. {{- with $thisValues.podLabels }}
  41. {{- toYaml . | nindent 8 }}
  42. {{- end }}
  43. spec:
  44. {{- with .Values.imagePullSecrets }}
  45. imagePullSecrets:
  46. {{- toYaml . | nindent 8 }}
  47. {{- end }}
  48. serviceAccountName: {{ include "kafka.serviceAccountName" . }}
  49. {{- with $thisValues.podSecurityContext }}
  50. securityContext:
  51. {{- toYaml $thisValues.podSecurityContext | nindent 8 }}
  52. {{- end }}
  53. {{- if or $.Values.nodeSelector $thisValues.nodeSelector }}
  54. nodeSelector:
  55. {{- if $thisValues.nodeSelector }}
  56. {{- toYaml $thisValues.nodeSelector | nindent 8 }}
  57. {{- else if $.Values.nodeSelector }}
  58. {{- toYaml $.Values.nodeSelector | nindent 8 }}
  59. {{- end }}
  60. {{- end }}
  61. {{- if or (eq $thisValues.antiAffinity "hard") (eq $thisValues.antiAffinity "soft") $thisValues.nodeAffinity }}
  62. affinity:
  63. {{- end }}
  64. {{- if eq $thisValues.antiAffinity "hard" }}
  65. podAntiAffinity:
  66. requiredDuringSchedulingIgnoredDuringExecution:
  67. - labelSelector:
  68. matchLabels:
  69. {{- include "kafka.selectorLabels" . | nindent 18 }}
  70. component: {{ $componet | quote }}
  71. topologyKey: {{ $antiAffinityTopologyKey | quote }}
  72. {{- else if eq $thisValues.antiAffinity "soft" }}
  73. podAntiAffinity:
  74. preferredDuringSchedulingIgnoredDuringExecution:
  75. - weight: 5
  76. podAffinityTerm:
  77. labelSelector:
  78. matchLabels:
  79. {{- include "kafka.selectorLabels" . | nindent 18 }}
  80. component: {{ $componet | quote }}
  81. topologyKey: {{ $antiAffinityTopologyKey | quote }}
  82. {{- end }}
  83. {{- with $thisValues.podAffinity }}
  84. podAffinity:
  85. {{ toYaml . | indent 10 }}
  86. {{- end }}
  87. {{- with $thisValues.nodeAffinity }}
  88. nodeAffinity:
  89. {{ toYaml . | indent 10 }}
  90. {{- end }}
  91. containers:
  92. - name: kafka
  93. image: {{ include "kafka.kafkaImage" . | quote }}
  94. {{- if .Values.image.pullPolicy }}
  95. imagePullPolicy: {{ .Values.image.pullPolicy | quote }}
  96. {{- end }}
  97. env:
  98. {{- include "kafka.controller.containerEnv" . | nindent 8 }}
  99. ports:
  100. - containerPort: {{ .Values.containerPort.controller }}
  101. name: controller
  102. protocol: TCP
  103. {{- with $thisValues.livenessProbe }}
  104. livenessProbe:
  105. {{- toYaml . | nindent 10 }}
  106. {{- end }}
  107. {{- with $thisValues.readinessProbe }}
  108. readinessProbe:
  109. {{- toYaml . | nindent 10 }}
  110. {{- end }}
  111. {{- with $thisValues.resources }}
  112. resources:
  113. {{- toYaml . | nindent 10 }}
  114. {{- end }}
  115. volumeMounts:
  116. - mountPath: /opt/kafka/data
  117. name: data
  118. subPath: data
  119. - mountPath: /opt/kafka/logs
  120. name: data
  121. subPath: logs
  122. - mountPath: /entrypoint.sh
  123. name: entrypoint-sh
  124. subPath: entrypoint.sh
  125. lifecycle:
  126. preStop:
  127. exec:
  128. command: ["sh", "-c", "sleep 10; bin/kafka-server-stop.sh"]
  129. terminationGracePeriodSeconds: {{ $thisValues.terminationGracePeriodSeconds }}
  130. volumes:
  131. - name: entrypoint-sh
  132. configMap:
  133. items:
  134. - key: entrypoint.sh
  135. path: entrypoint.sh
  136. name: {{ include "kafka.entrypoint.configmapName" . }}
  137. defaultMode: 0744
  138. {{- if not $thisValues.persistence.enabled }}
  139. - name: data
  140. emptyDir: {}
  141. {{- else }}
  142. volumeClaimTemplates:
  143. - metadata:
  144. name: data
  145. {{- with $thisValues.persistence.annotations }}
  146. annotations:
  147. {{- . | toYaml | nindent 10 }}
  148. {{- end }}
  149. spec:
  150. accessModes:
  151. - ReadWriteOnce
  152. {{- with $thisValues.persistence.storageClass }}
  153. storageClassName: {{ if (eq "-" .) }}""{{ else }}{{ . }}{{ end }}
  154. {{- end }}
  155. resources:
  156. requests:
  157. storage: {{ $thisValues.persistence.size | quote }}
  158. {{- end }}
  159. {{- end }}