statefulset.yaml 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. apiVersion: apps/v1
  2. kind: StatefulSet
  3. metadata:
  4. name: {{ include "kafka.fullname" . }}
  5. labels:
  6. {{- include "kafka.labels" . | nindent 4 }}
  7. spec:
  8. selector:
  9. matchLabels:
  10. {{- include "kafka.selectorLabels" . | nindent 6 }}
  11. serviceName: {{ include "kafka.fullname" . }}-headless
  12. replicas: {{ .Values.replicaCount }}
  13. updateStrategy:
  14. type: RollingUpdate
  15. podManagementPolicy: Parallel
  16. template:
  17. metadata:
  18. labels:
  19. {{- include "kafka.selectorLabels" . | nindent 8 }}
  20. spec:
  21. serviceAccountName: {{ include "kafka.fullname" . }}-sa
  22. securityContext:
  23. {{- toYaml .Values.podSecurityContext | nindent 8 }}
  24. affinity:
  25. {{- if .Values.affinity }}
  26. {{ toYaml .Values.affinity | indent 8 }}
  27. {{- else }}
  28. podAntiAffinity:
  29. preferredDuringSchedulingIgnoredDuringExecution:
  30. - podAffinityTerm:
  31. labelSelector:
  32. matchExpressions:
  33. - key: app
  34. operator: In
  35. values:
  36. - {{ include "kafka.name" . }}
  37. topologyKey: kubernetes.io/hostname
  38. weight: 1
  39. {{- end }}
  40. containers:
  41. - name: {{ .Chart.Name }}
  42. {{- with .Values.imagePullSecrets }}
  43. imagePullSecrets:
  44. {{- toYaml . | nindent 8 }}
  45. {{- end }}
  46. imagePullPolicy: {{ .Values.image.pullPolicy }}
  47. image: "{{ .Values.image.registry }}/{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
  48. env:
  49. - name: POD_IP
  50. valueFrom:
  51. fieldRef:
  52. apiVersion: v1
  53. fieldPath: status.podIP
  54. - name: HOST_IP
  55. valueFrom:
  56. fieldRef:
  57. apiVersion: v1
  58. fieldPath: status.hostIP
  59. - name: POD_NAME
  60. valueFrom:
  61. fieldRef:
  62. apiVersion: v1
  63. fieldPath: metadata.name
  64. - name: POD_NAMESPACE
  65. valueFrom:
  66. fieldRef:
  67. apiVersion: v1
  68. fieldPath: metadata.namespace
  69. - name: KAFKA_ZOOKEEPER_CONNECT
  70. value: {{ include "kafka.zookeeper.ensemble" . | quote }}
  71. - name: KAFKA_HEAP_OPTS
  72. value: {{ .Values.heapOpts | quote }}
  73. - name: KAFKA_CONFLUENT_SUPPORT_METRICS_ENABLE
  74. value: {{ .Values.confluentSupportMetricsEnable | quote }}
  75. - name: KAFKA_LOG_DIRS
  76. value: "/var/lib/kafka/data"
  77. - name: KAFKA_AUTO_CREATE_TOPICS_ENABLE
  78. value: {{ .Values.autoCreateTopicsEnable | quote }}
  79. - name: KAFKA_DELETE_TOPIC_ENABLE
  80. value: {{ .Values.deleteTopicEnable | quote }}
  81. - name: KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR
  82. value: {{ .Values.offsetsTopicReplicationFactor | int | quote }}
  83. - name: KAFKA_NUM_PARTITIONS
  84. value: {{ .Values.numPartitions | int | quote }}
  85. - name: KAFKA_DEFAULT_REPLICATION_FACTOR
  86. value: {{ .Values.defaultReplicationFactor | int | quote }}
  87. - name: KAFKA_MIN_INSYNC_REPLICAS
  88. value: {{ .Values.minInsyncReplicas | int | quote }}
  89. - name: KAFKA_UNCLEAN_LEADER_ELECTION.ENABLE
  90. value: {{ .Values.uncleanLeaderElectionEnable | quote }}
  91. - name: KAFKA_LOG_FLUSH_INTERVAL_MESSAGES
  92. value: {{ .Values.logFlushIntervalMessages | int | quote }}
  93. - name: KAFKA_LOG_FLUSH_INTERVAL_MS
  94. value: {{ .Values.logFlushIntervalMs | int | quote }}
  95. - name: KAFKA_LOG_RETENTION_BYTES
  96. value: {{ .Values.logRetentionBytes | int | quote }}
  97. - name: KAFKA_LOG_RETENTION_CHECK_INTERVAL_MS
  98. value: {{ .Values.logRetentionCheckIntervalMs | int | quote }}
  99. - name: KAFKA_LOG_RETENTION_HOURS
  100. value: {{ .Values.logRetentionHours | int | quote }}
  101. - name: KAFKA_LOG_SEGMENT_BYTES
  102. value: {{ .Values.logSegmentBytes | int | quote }}
  103. - name: KAFKA_MESSAGE_MAX_BYTES
  104. value: {{ .Values.messageMaxBytes | int | quote }}
  105. - name: KAFKA_LOG4J_ROOT_LOGLEVEL
  106. value: {{ .Values.log4jRootLoglevel | quote }}
  107. - name: KAFKA_LOG4J_LOGGERS
  108. value: {{ .Values.log4jLoggers | quote }}
  109. {{- if .Values.kerberos.enabled }}
  110. - name: KAFKA_SECURITY_INTER_BROKER_PROTOCOL
  111. value: SASL_PLAINTEXT
  112. - name: KAFKA_SASL_KERBEROS_SERVICE_NAME
  113. value: "kafka"
  114. - name: KAFKA_LISTENERS
  115. value: "SASL_PLAINTEXT://:{{ .Values.port.kafkaInternal }},EXTERNAL://:{{ .Values.port.kafkaExternal }}"
  116. - name: KAFKA_LISTENER_SECURITY_PROTOCOL_MAP
  117. value: "SASL_PLAINTEXT:SASL_PLAINTEXT,EXTERNAL:SASL_PLAINTEXT"
  118. {{- else }}
  119. - name: KAFKA_LISTENERS
  120. value: "PLAINTEXT://:{{ .Values.port.kafkaInternal }},EXTERNAL://:{{ .Values.port.kafkaExternal }}"
  121. - name: KAFKA_LISTENER_SECURITY_PROTOCOL_MAP
  122. value: "PLAINTEXT:PLAINTEXT,EXTERNAL:PLAINTEXT"
  123. {{- end }}
  124. - name: ZOOKEEPER_SASL_ENABLED
  125. value: {{ .Values.zookeeper.kerberos.enabled | quote }}
  126. {{- if .Values.acls.enabled }}
  127. - name: KAFKA_ZOOKEEPER_SET_ACL
  128. value: "true"
  129. - name: KAFKA_SUPER_USERS
  130. value: "User:kafka"
  131. - name: KAFKA_ALLOW_EVERYONE_IF_NO_ACL_FOUND
  132. value: "false"
  133. - name: KAFKA_AUTHORIZER_CLASS_NAME
  134. value: "kafka.security.authorizer.AclAuthorizer"
  135. {{- end }}
  136. command:
  137. - "sh"
  138. - "-exc"
  139. - |
  140. export KAFKA_BROKER_ID=${HOSTNAME##*-} && \
  141. {{- if .Values.isDocker }}
  142. export KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://{{ include "kafka.listener" . }}:{{ .Values.port.kafkaInternal }},EXTERNAL://172.24.100.101:$(({{ .Values.externalAccess.initNodePort }} + ${KAFKA_BROKER_ID})) && \
  143. {{- else if .Values.kerberos.enabled }}
  144. export KAFKA_ADVERTISED_LISTENERS=SASL_PLAINTEXT://{{ include "kafka.listener" . }}:{{ .Values.port.kafkaInternal }},EXTERNAL://{{ include "kafka.listener" . }}:$(({{ .Values.externalAccess.initNodePort }} + ${KAFKA_BROKER_ID})) && \
  145. export KAFKA_OPTS="-Djava.security.krb5.conf=/etc/krb5.conf -Djava.security.auth.login.config=/jaas/${POD_NAME}_jaas.conf -Dsun.security.krb5.debug=false" && \
  146. {{- else }}
  147. export KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://{{ include "kafka.listener" . }}:{{ .Values.port.kafkaInternal }},EXTERNAL://${HOST_IP}:$(({{ .Values.externalAccess.initNodePort }} + ${KAFKA_BROKER_ID})) && \
  148. {{- end }}
  149. exec /etc/confluent/docker/run
  150. ports:
  151. - name: tcp-kafka-int
  152. containerPort: {{ .Values.port.kafkaInternal }}
  153. - name: tcp-kafka-ext
  154. containerPort: {{ .Values.port.kafkaExternal }}
  155. {{- if .Values.livenessProbe.enabled }}
  156. livenessProbe:
  157. tcpSocket:
  158. port: tcp-kafka-int
  159. initialDelaySeconds: {{ .Values.livenessProbe.initialDelaySeconds }}
  160. periodSeconds: {{ .Values.livenessProbe.periodSeconds }}
  161. timeoutSeconds: {{ .Values.livenessProbe.timeoutSeconds }}
  162. successThreshold: {{ .Values.livenessProbe.successThreshold }}
  163. failureThreshold: {{ .Values.livenessProbe.failureThreshold }}
  164. {{- end }}
  165. {{- if .Values.readinessProbe.enabled }}
  166. readinessProbe:
  167. tcpSocket:
  168. port: tcp-kafka-int
  169. initialDelaySeconds: {{ .Values.readinessProbe.initialDelaySeconds }}
  170. periodSeconds: {{ .Values.readinessProbe.periodSeconds }}
  171. timeoutSeconds: {{ .Values.readinessProbe.timeoutSeconds }}
  172. successThreshold: {{ .Values.readinessProbe.successThreshold }}
  173. failureThreshold: {{ .Values.readinessProbe.failureThreshold }}
  174. {{- end }}
  175. volumeMounts:
  176. - name: data
  177. mountPath: /var/lib/kafka/data
  178. - name: config
  179. mountPath: /etc/kafka
  180. - name: logs
  181. mountPath: /var/log
  182. {{- if or .Values.kerberos.enabled .Values.zookeeper.kerberos.enabled }}
  183. - name: krb5
  184. mountPath: /etc/krb5.conf
  185. subPath: krb5.conf
  186. - name: keytabs
  187. mountPath: /keytabs
  188. readOnly: true
  189. - name: jaas
  190. mountPath: /jaas
  191. readOnly: true
  192. {{- end }}
  193. securityContext:
  194. {{- toYaml .Values.securityContext | nindent 12 }}
  195. resources:
  196. {{- toYaml .Values.resources | nindent 12 }}
  197. volumes:
  198. - name: config
  199. emptyDir: {}
  200. - name: logs
  201. emptyDir: {}
  202. {{- if .Values.kerberos.enabled }}
  203. - name: krb5
  204. configMap:
  205. name: {{ required "The .Values.kerberos.krb5Conf is required when kerberos enabled!" .Values.kerberos.krb5Conf }}
  206. - name: keytabs
  207. secret:
  208. secretName: {{ required "The .Values.kerberos.keyTabSecret is required when kerberos enabled!" .Values.kerberos.keyTabSecret }}
  209. - name: jaas
  210. configMap:
  211. name: {{ required "The .Values.kerberos.jaasConf is required when kerberos enabled!" .Values.kerberos.jaasConf }}
  212. {{- end }}
  213. volumeClaimTemplates:
  214. - metadata:
  215. name: data
  216. spec:
  217. storageClassName: {{ .Values.data.storageClass | quote }}
  218. accessModes: [ "ReadWriteOnce" ]
  219. resources:
  220. requests:
  221. storage: {{ .Values.data.storageSize | quote }}