kafka-metrics-deployment.yaml 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. {{- if .Values.metrics.kafka.enabled }}
  2. {{- $replicaCount := int .Values.replicaCount -}}
  3. {{- $releaseNamespace := .Release.Namespace -}}
  4. {{- $clusterDomain := .Values.clusterDomain -}}
  5. {{- $fullname := include "common.names.fullname" . -}}
  6. {{- $servicePort := int .Values.service.ports.client -}}
  7. apiVersion: {{ include "common.capabilities.deployment.apiVersion" . }}
  8. kind: Deployment
  9. metadata:
  10. name: {{ include "kafka.metrics.kafka.fullname" . }}
  11. namespace: {{ .Release.Namespace | quote }}
  12. labels: {{- include "common.labels.standard" . | nindent 4 }}
  13. app.kubernetes.io/component: cluster-metrics
  14. {{- if .Values.commonLabels }}
  15. {{- include "common.tplvalues.render" ( dict "value" .Values.commonLabels "context" $ ) | nindent 4 }}
  16. {{- end }}
  17. {{- if .Values.commonAnnotations }}
  18. annotations: {{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }}
  19. {{- end }}
  20. spec:
  21. replicas: 1
  22. selector:
  23. matchLabels: {{- include "common.labels.matchLabels" . | nindent 6 }}
  24. app.kubernetes.io/component: cluster-metrics
  25. template:
  26. metadata:
  27. labels: {{- include "common.labels.standard" . | nindent 8 }}
  28. app.kubernetes.io/component: cluster-metrics
  29. {{- if .Values.metrics.kafka.podLabels }}
  30. {{- include "common.tplvalues.render" (dict "value" .Values.metrics.kafka.podLabels "context" $) | nindent 8 }}
  31. {{- end }}
  32. annotations:
  33. {{- if .Values.metrics.kafka.podAnnotations }}
  34. {{- include "common.tplvalues.render" (dict "value" .Values.metrics.kafka.podAnnotations "context" $) | nindent 8 }}
  35. {{- end }}
  36. spec:
  37. {{- include "kafka.imagePullSecrets" . | nindent 6 }}
  38. {{- if .Values.metrics.kafka.hostAliases }}
  39. hostAliases: {{- include "common.tplvalues.render" (dict "value" .Values.metrics.kafka.hostAliases "context" $) | nindent 8 }}
  40. {{- end }}
  41. {{- if .Values.metrics.kafka.affinity }}
  42. affinity: {{- include "common.tplvalues.render" ( dict "value" .Values.metrics.kafka.affinity "context" $) | nindent 8 }}
  43. {{- else }}
  44. affinity:
  45. podAffinity: {{- include "common.affinities.pods" (dict "type" .Values.metrics.kafka.podAffinityPreset "component" "metrics" "context" $) | nindent 10 }}
  46. podAntiAffinity: {{- include "common.affinities.pods" (dict "type" .Values.metrics.kafka.podAntiAffinityPreset "component" "metrics" "context" $) | nindent 10 }}
  47. nodeAffinity: {{- include "common.affinities.nodes" (dict "type" .Values.metrics.kafka.nodeAffinityPreset.type "key" .Values.metrics.kafka.nodeAffinityPreset.key "values" .Values.metrics.kafka.nodeAffinityPreset.values) | nindent 10 }}
  48. {{- end }}
  49. {{- if .Values.metrics.kafka.nodeSelector }}
  50. nodeSelector: {{- include "common.tplvalues.render" ( dict "value" .Values.metrics.kafka.nodeSelector "context" $) | nindent 8 }}
  51. {{- end }}
  52. {{- if .Values.metrics.kafka.tolerations }}
  53. tolerations: {{- include "common.tplvalues.render" (dict "value" .Values.metrics.kafka.tolerations "context" .) | nindent 8 }}
  54. {{- end }}
  55. {{- if .Values.metrics.kafka.topologySpreadConstraints }}
  56. topologySpreadConstraints: {{- include "common.tplvalues.render" (dict "value" .Values.metrics.kafka.topologySpreadConstraints "context" .) | nindent 8 }}
  57. {{- end }}
  58. {{- if .Values.metrics.kafka.priorityClassName }}
  59. priorityClassName: {{ .Values.metrics.kafka.priorityClassName }}
  60. {{- end }}
  61. {{- if .Values.metrics.kafka.schedulerName }}
  62. schedulerName: {{ .Values.metrics.kafka.schedulerName }}
  63. {{- end }}
  64. {{- if .Values.metrics.kafka.podSecurityContext.enabled }}
  65. securityContext: {{- omit .Values.metrics.kafka.podSecurityContext "enabled" | toYaml | nindent 8 }}
  66. {{- end }}
  67. serviceAccountName: {{ template "kafka.metrics.kafka.serviceAccountName" . }}
  68. {{- if .Values.metrics.kafka.initContainers }}
  69. initContainers: {{- include "common.tplvalues.render" (dict "value" .Values.metrics.kafka.initContainers "context" $) | nindent 8 }}
  70. {{- end }}
  71. containers:
  72. - name: kafka-exporter
  73. image: {{ include "kafka.metrics.kafka.image" . }}
  74. imagePullPolicy: {{ .Values.metrics.kafka.image.pullPolicy | quote }}
  75. {{- if .Values.metrics.kafka.containerSecurityContext.enabled }}
  76. securityContext: {{- omit .Values.metrics.kafka.containerSecurityContext "enabled" | toYaml | nindent 12 }}
  77. {{- end }}
  78. {{- if .Values.diagnosticMode.enabled }}
  79. command: {{- include "common.tplvalues.render" (dict "value" .Values.diagnosticMode.command "context" $) | nindent 12 }}
  80. {{- else if .Values.metrics.kafka.command }}
  81. command: {{- include "common.tplvalues.render" (dict "value" .Values.metrics.kafka.command "context" $) | nindent 12 }}
  82. {{- else }}
  83. command:
  84. - bash
  85. {{- end }}
  86. {{- if .Values.diagnosticMode.enabled }}
  87. args: {{- include "common.tplvalues.render" (dict "value" .Values.diagnosticMode.args "context" $) | nindent 12 }}
  88. {{- else if .Values.metrics.kafka.args }}
  89. args: {{- include "common.tplvalues.render" (dict "value" .Values.metrics.kafka.args "context" $) | nindent 12 }}
  90. {{- else }}
  91. args:
  92. - -ce
  93. - |
  94. kafka_exporter \
  95. {{- range $i, $e := until $replicaCount }}
  96. --kafka.server={{ $fullname }}-{{ $i }}.{{ $fullname }}-headless.{{ $releaseNamespace }}.svc.{{ $clusterDomain }}:{{ $servicePort }} \
  97. {{- end }}
  98. {{- if (include "kafka.client.saslAuthentication" .) }}
  99. --sasl.enabled \
  100. --sasl.username=$SASL_USERNAME \
  101. --sasl.password=$SASL_USER_PASSWORD \
  102. --sasl.mechanism={{ include "kafka.metrics.kafka.saslMechanism" . }} \
  103. {{- end }}
  104. {{- if (include "kafka.client.tlsEncryption" .) }}
  105. --tls.enabled \
  106. {{- if .Values.metrics.kafka.certificatesSecret }}
  107. --tls.key-file=/opt/bitnami/kafka-exporter/certs/{{ .Values.metrics.kafka.tlsKey }} \
  108. --tls.cert-file=/opt/bitnami/kafka-exporter/certs/{{ .Values.metrics.kafka.tlsCert }} \
  109. {{- if .Values.metrics.kafka.tlsCaSecret }}
  110. --tls.ca-file=/opt/bitnami/kafka-exporter/cacert/{{ .Values.metrics.kafka.tlsCaCert }} \
  111. {{- else }}
  112. --tls.ca-file=/opt/bitnami/kafka-exporter/certs/{{ .Values.metrics.kafka.tlsCaCert }} \
  113. {{- end }}
  114. {{- end }}
  115. {{- end }}
  116. {{- range $key, $value := .Values.metrics.kafka.extraFlags }}
  117. --{{ $key }}{{ if $value }}={{ $value }}{{ end }} \
  118. {{- end }}
  119. --web.listen-address=:{{ .Values.metrics.kafka.containerPorts.metrics }}
  120. {{- end }}
  121. {{- if (include "kafka.client.saslAuthentication" .) }}
  122. {{- $clientUsers := .Values.auth.sasl.jaas.clientUsers }}
  123. env:
  124. - name: SASL_USERNAME
  125. value: {{ index $clientUsers 0 | quote }}
  126. - name: SASL_USER_PASSWORD
  127. valueFrom:
  128. secretKeyRef:
  129. name: {{ include "kafka.jaasSecretName" . }}
  130. key: system-user-password
  131. {{- end }}
  132. ports:
  133. - name: metrics
  134. containerPort: {{ .Values.metrics.kafka.containerPorts.metrics }}
  135. {{- if .Values.metrics.kafka.resources }}
  136. resources: {{ toYaml .Values.metrics.kafka.resources | nindent 12 }}
  137. {{- end }}
  138. volumeMounts:
  139. {{- if .Values.metrics.kafka.extraVolumeMounts }}
  140. {{- include "common.tplvalues.render" (dict "value" .Values.metrics.kafka.extraVolumeMounts "context" $) | nindent 12 }}
  141. {{- end }}
  142. {{- if and (include "kafka.client.tlsEncryption" .) .Values.metrics.kafka.certificatesSecret }}
  143. - name: kafka-exporter-certificates
  144. mountPath: /opt/bitnami/kafka-exporter/certs/
  145. readOnly: true
  146. {{- if .Values.metrics.kafka.tlsCaSecret }}
  147. - name: kafka-exporter-ca-certificate
  148. mountPath: /opt/bitnami/kafka-exporter/cacert/
  149. readOnly: true
  150. {{- end }}
  151. {{- end }}
  152. {{- if .Values.metrics.kafka.sidecars }}
  153. {{- include "common.tplvalues.render" (dict "value" .Values.metrics.kafka.sidecars "context" $) | nindent 8 }}
  154. {{- end }}
  155. volumes:
  156. {{- if .Values.metrics.kafka.extraVolumes }}
  157. {{- include "common.tplvalues.render" (dict "value" .Values.metrics.kafka.extraVolumes "context" $) | nindent 8 }}
  158. {{- end }}
  159. {{- if and (include "kafka.client.tlsEncryption" .) .Values.metrics.kafka.certificatesSecret }}
  160. - name: kafka-exporter-certificates
  161. secret:
  162. secretName: {{ .Values.metrics.kafka.certificatesSecret }}
  163. defaultMode: 0440
  164. {{- if .Values.metrics.kafka.tlsCaSecret }}
  165. - name: kafka-exporter-ca-certificate
  166. secret:
  167. secretName: {{ .Values.metrics.kafka.tlsCaSecret }}
  168. defaultMode: 0440
  169. {{- end }}
  170. {{- end }}
  171. {{- end }}