kafka-metrics-deployment.yaml 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. {{- if .Values.metrics.kafka.enabled }}
  2. {{- $replicaCount := int .Values.replicaCount -}}
  3. {{- $releaseNamespace := .Release.Namespace -}}
  4. {{- $clusterDomain := .Values.clusterDomain -}}
  5. {{- $fullname := include "kafka.fullname" . -}}
  6. {{- $servicePort := int .Values.service.port -}}
  7. apiVersion: {{ include "common.capabilities.deployment.apiVersion" . }}
  8. kind: Deployment
  9. metadata:
  10. name: {{ template "kafka.fullname" . }}-exporter
  11. labels: {{- include "common.labels.standard" . | nindent 4 }}
  12. app.kubernetes.io/component: metrics
  13. {{- if .Values.commonLabels }}
  14. {{- include "common.tplvalues.render" ( dict "value" .Values.commonLabels "context" $ ) | nindent 4 }}
  15. {{- end }}
  16. {{- if .Values.commonAnnotations }}
  17. annotations: {{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }}
  18. {{- end }}
  19. spec:
  20. replicas: 1
  21. selector:
  22. matchLabels: {{- include "common.labels.matchLabels" . | nindent 6 }}
  23. app.kubernetes.io/component: metrics
  24. template:
  25. metadata:
  26. labels: {{- include "common.labels.standard" . | nindent 8 }}
  27. app.kubernetes.io/component: metrics
  28. spec:
  29. {{- include "kafka.imagePullSecrets" . | nindent 6 }}
  30. {{- if .Values.metrics.kafka.schedulerName }}
  31. schedulerName: {{ .Values.metrics.kafka.schedulerName | quote }}
  32. {{- end }}
  33. serviceAccountName: {{ template "kafka.serviceAccountName" . }}
  34. {{- if .Values.metrics.kafka.initContainers }}
  35. initContainers: {{- include "common.tplvalues.render" (dict "value" .Values.metrics.kafka.initContainers "context" $) | nindent 8 }}
  36. {{- end }}
  37. containers:
  38. - name: kafka-exporter
  39. image: {{ include "kafka.metrics.kafka.image" . }}
  40. imagePullPolicy: {{ .Values.metrics.kafka.image.pullPolicy | quote }}
  41. command:
  42. - /bin/bash
  43. - -ec
  44. - |
  45. kafka_exporter \
  46. {{- range $i, $e := until $replicaCount }}
  47. --kafka.server={{ $fullname }}-{{ $i }}.{{ $fullname }}-headless.{{ $releaseNamespace }}.svc.{{ $clusterDomain }}:{{ $servicePort }} \
  48. {{- end }}
  49. {{- if (include "kafka.client.saslAuthentication" .) }}
  50. --sasl.enabled \
  51. --sasl.username="$SASL_USERNAME" \
  52. --sasl.password="${SASL_USER_PASSWORD%%,*}" \
  53. {{- end }}
  54. {{- if (include "kafka.client.tlsEncryption" .) }}
  55. --tls.enabled \
  56. {{- if .Values.metrics.kafka.certificatesSecret }}
  57. --tls.key-file="/opt/bitnami/kafka-exporter/certs/{{ .Values.metrics.kafka.tlsKey }}" \
  58. --tls.cert-file="/opt/bitnami/kafka-exporter/certs/{{ .Values.metrics.kafka.tlsCert }}" \
  59. {{- if .Values.metrics.kafka.tlsCaSecret }}
  60. --tls.ca-file="/opt/bitnami/kafka-exporter/cacert/{{ .Values.metrics.kafka.tlsCaCert }}" \
  61. {{- else}}
  62. --tls.ca-file="/opt/bitnami/kafka-exporter/certs/{{ .Values.metrics.kafka.tlsCaCert }}" \
  63. {{- end }}
  64. {{- end }}
  65. {{- end }}
  66. {{- range $key, $value := .Values.metrics.kafka.extraFlags }}
  67. --{{ $key }}{{ if $value }}={{ $value }}{{ end }} \
  68. {{- end }}
  69. --web.listen-address=:9308
  70. {{- if (include "kafka.client.saslAuthentication" .) }}
  71. {{- $clientUsers := coalesce .Values.auth.sasl.jaas.clientUsers .Values.auth.jaas.clientUsers }}
  72. env:
  73. - name: SASL_USERNAME
  74. value: {{ index $clientUsers 0 | quote }}
  75. - name: SASL_USER_PASSWORD
  76. valueFrom:
  77. secretKeyRef:
  78. name: {{ include "kafka.jaasSecretName" . }}
  79. key: client-passwords
  80. {{- end }}
  81. ports:
  82. - name: metrics
  83. containerPort: 9308
  84. {{- if .Values.metrics.kafka.resources }}
  85. resources: {{ toYaml .Values.metrics.kafka.resources | nindent 12 }}
  86. {{- end }}
  87. {{- if and (include "kafka.client.tlsEncryption" .) .Values.metrics.kafka.certificatesSecret }}
  88. volumeMounts:
  89. - name: kafka-exporter-certificates
  90. mountPath: /opt/bitnami/kafka-exporter/certs/
  91. readOnly: true
  92. {{- if .Values.metrics.kafka.tlsCaSecret }}
  93. - name: kafka-exporter-ca-certificate
  94. mountPath: /opt/bitnami/kafka-exporter/cacert/
  95. readOnly: true
  96. {{- end }}
  97. volumes:
  98. - name: kafka-exporter-certificates
  99. secret:
  100. secretName: {{ .Values.metrics.kafka.certificatesSecret }}
  101. defaultMode: 0440
  102. {{- if .Values.metrics.kafka.tlsCaSecret }}
  103. - name: kafka-exporter-ca-certificate
  104. secret:
  105. secretName: {{ .Values.metrics.kafka.tlsCaSecret }}
  106. defaultMode: 0440
  107. {{- end }}
  108. {{- end }}
  109. {{- if .Values.metrics.kafka.affinity }}
  110. affinity:
  111. {{ toYaml .Values.metrics.kafka.affinity | nindent 8 }}
  112. {{- end }}
  113. {{- if .Values.metrics.kafka.tolerations }}
  114. tolerations:
  115. {{ toYaml .Values.metrics.kafka.tolerations | nindent 8 }}
  116. {{- end }}
  117. {{- if .Values.metrics.kafka.nodeSelector }}
  118. nodeSelector:
  119. {{ toYaml .Values.metrics.kafka.nodeSelector | nindent 8 }}
  120. {{- end }}
  121. {{- end }}