statefulset.yaml 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. {{- $thisValues := .Values.broker }}
  2. {{- $thisFullName := include "kafka.broker.fullname" . }}
  3. {{- $componet := include "kafka.broker.componet" . }}
  4. {{- $brokerFullName := $thisFullName }}
  5. {{- $brokerPort := .Values.containerPort.broker }}
  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.broker.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. securityContext:
  50. {{- toYaml $thisValues.podSecurityContext | nindent 8 }}
  51. {{- if or $.Values.nodeSelector $thisValues.nodeSelector }}
  52. nodeSelector:
  53. {{- if $thisValues.nodeSelector }}
  54. {{- toYaml $thisValues.nodeSelector | nindent 8 }}
  55. {{- else if $.Values.nodeSelector }}
  56. {{- toYaml $.Values.nodeSelector | nindent 8 }}
  57. {{- end }}
  58. {{- end }}
  59. affinity:
  60. {{- if eq ($thisValues.antiAffinity | lower) "hard" }}
  61. podAntiAffinity:
  62. requiredDuringSchedulingIgnoredDuringExecution:
  63. - labelSelector:
  64. matchLabels:
  65. {{- include "kafka.selectorLabels" . | nindent 18 }}
  66. component: {{ $componet | quote }}
  67. topologyKey: {{ $antiAffinityTopologyKey | quote }}
  68. {{- else }}
  69. podAntiAffinity:
  70. preferredDuringSchedulingIgnoredDuringExecution:
  71. - weight: 5
  72. podAffinityTerm:
  73. labelSelector:
  74. matchLabels:
  75. {{- include "kafka.selectorLabels" . | nindent 18 }}
  76. component: {{ $componet | quote }}
  77. topologyKey: {{ $antiAffinityTopologyKey | quote }}
  78. {{- end }}
  79. {{- with $thisValues.podAffinity }}
  80. podAffinity:
  81. {{ toYaml . | indent 10 }}
  82. {{- end }}
  83. {{- with $thisValues.nodeAffinity }}
  84. nodeAffinity:
  85. {{ toYaml . | indent 10 }}
  86. {{- end }}
  87. containers:
  88. - name: kafka
  89. image: {{ include "kafka.kafkaImage" . | quote }}
  90. {{- if .Values.image.pullPolicy }}
  91. imagePullPolicy: {{ .Values.image.pullPolicy | quote }}
  92. {{- end }}
  93. env:
  94. {{- include "kafka.broker.containerEnv" . | nindent 8 }}
  95. ports:
  96. {{- include "kafka.broker.containerPorts" . | nindent 8 }}
  97. {{- with $thisValues.livenessProbe }}
  98. livenessProbe:
  99. {{- toYaml . | nindent 10 }}
  100. {{- end }}
  101. readinessProbe:
  102. exec:
  103. command:
  104. - sh
  105. - -c
  106. - bin/kafka-broker-api-versions.sh --bootstrap-server=127.0.0.1:{{ $brokerPort }}
  107. {{- with $thisValues.readinessProbe }}
  108. {{- toYaml . | nindent 10 }}
  109. {{- end }}
  110. {{- with $thisValues.resources }}
  111. resources:
  112. {{- toYaml . | nindent 10 }}
  113. {{- end }}
  114. volumeMounts:
  115. - mountPath: /opt/kafka/data
  116. name: data
  117. subPath: data
  118. - mountPath: /opt/kafka/logs
  119. name: data
  120. subPath: logs
  121. - mountPath: {{ include "kafka.broker.baseConfigFile" . }}
  122. name: base-config
  123. subPath: server.properties
  124. - mountPath: /entrypoint.sh
  125. name: entrypoint-sh
  126. subPath: entrypoint.sh
  127. lifecycle:
  128. preStop:
  129. exec:
  130. command: ["sh", "-c", "sleep 10; bin/kafka-server-stop.sh"]
  131. terminationGracePeriodSeconds: {{ $thisValues.terminationGracePeriodSeconds }}
  132. volumes:
  133. - name: base-config
  134. configMap:
  135. items:
  136. - key: server.properties
  137. path: server.properties
  138. name: {{ include "kafka.broker.fullname" . }}
  139. - name: entrypoint-sh
  140. configMap:
  141. items:
  142. - key: entrypoint.sh
  143. path: entrypoint.sh
  144. name: {{ include "kafka.entrypoint.configmapName" . }}
  145. defaultMode: 0744
  146. {{- if not $thisValues.persistence.enabled }}
  147. - name: data
  148. emptyDir: {}
  149. {{- else }}
  150. volumeClaimTemplates:
  151. - metadata:
  152. name: data
  153. {{- with $thisValues.persistence.annotations }}
  154. annotations:
  155. {{- . | toYaml | nindent 10 }}
  156. {{- end }}
  157. spec:
  158. accessModes:
  159. - ReadWriteOnce
  160. {{- with $thisValues.persistence.storageClass }}
  161. storageClassName: {{ if (eq "-" .) }}""{{ else }}{{ . }}{{ end }}
  162. {{- end }}
  163. resources:
  164. requests:
  165. storage: {{ $thisValues.persistence.size | quote }}
  166. {{- end }}