NOTES.txt 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. {{- $replicaCount := int .Values.replicaCount -}}
  2. {{- $releaseNamespace := .Release.Namespace -}}
  3. {{- $clusterDomain := .Values.clusterDomain -}}
  4. {{- $fullname := include "kafka.fullname" . -}}
  5. {{- $clientProtocol := include "kafka.listenerType" (dict "protocol" .Values.auth.clientProtocol) -}}
  6. {{- $saslMechanisms := coalesce .Values.auth.sasl.mechanisms .Values.auth.saslMechanisms -}}
  7. {{- $tlsEndpointIdentificationAlgorithm := default "" (coalesce .Values.auth.tls.endpointIdentificationAlgorithm .Values.auth.tlsEndpointIdentificationAlgorithm) -}}
  8. {{- $tlsPassword := coalesce .Values.auth.tls.password .Values.auth.jksPassword -}}
  9. {{- $servicePort := int .Values.service.port -}}
  10. {{- $loadBalancerIPListLength := len .Values.externalAccess.service.loadBalancerIPs -}}
  11. {{- if and .Values.externalAccess.enabled (not .Values.externalAccess.autoDiscovery.enabled) (not (eq $replicaCount $loadBalancerIPListLength )) (eq .Values.externalAccess.service.type "LoadBalancer") }}
  12. ###############################################################################
  13. ### ERROR: You enabled external access to Kafka brokers without specifying ###
  14. ### the array of load balancer IPs for Kafka brokers. ###
  15. ###############################################################################
  16. This deployment will be incomplete until you configure the array of load balancer
  17. IPs for Kafka brokers. To complete your deployment follow the steps below:
  18. 1. Wait for the load balancer IPs (it may take a few minutes for them to be available):
  19. kubectl get svc --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ template "kafka.name" . }},app.kubernetes.io/instance={{ .Release.Name }},app.kubernetes.io/component=kafka,pod" -w
  20. 2. Obtain the load balancer IPs and upgrade your chart:
  21. {{- range $i, $e := until $replicaCount }}
  22. LOAD_BALANCER_IP_{{ add $i 1 }}="$(kubectl get svc --namespace {{ $releaseNamespace }} {{ $fullname }}-{{ $i }}-external -o jsonpath='{.status.loadBalancer.ingress[0].ip}')"
  23. {{- end }}
  24. 3. Upgrade you chart:
  25. helm upgrade --namespace {{ .Release.Namespace }} {{ .Release.Name }} bitnami/{{ .Chart.Name }} \
  26. --set replicaCount={{ $replicaCount }} \
  27. --set externalAccess.enabled=true \
  28. {{- range $i, $e := until $replicaCount }}
  29. --set externalAccess.service.loadBalancerIPs[{{ $i }}]=$LOAD_BALANCER_IP_{{ add $i 1 }} \
  30. {{- end }}
  31. --set externalAccess.service.type=LoadBalancer
  32. {{- else }}
  33. {{- if and (or (eq .Values.service.type "LoadBalancer") .Values.externalAccess.enabled) (eq $clientProtocol "PLAINTEXT") }}
  34. ---------------------------------------------------------------------------------------------
  35. WARNING
  36. By specifying "serviceType=LoadBalancer" and not configuring the authentication
  37. you have most likely exposed the Kafka service externally without any
  38. authentication mechanism.
  39. For security reasons, we strongly suggest that you switch to "ClusterIP" or
  40. "NodePort". As alternative, you can also configure the Kafka authentication.
  41. ---------------------------------------------------------------------------------------------
  42. {{- end }}
  43. ** Please be patient while the chart is being deployed **
  44. Kafka can be accessed by consumers via port {{ $servicePort }} on the following DNS name from within your cluster:
  45. {{ $fullname }}.{{ $releaseNamespace }}.svc.{{ $clusterDomain }}
  46. Each Kafka broker can be accessed by producers via port {{ $servicePort }} on the following DNS name(s) from within your cluster:
  47. {{- $brokerList := list }}
  48. {{- range $e, $i := until $replicaCount }}
  49. {{- $brokerList = append $brokerList (printf "%s-%d.%s-headless.%s.svc.%s:%d" $fullname $i $fullname $releaseNamespace $clusterDomain $servicePort) }}
  50. {{- end }}
  51. {{ join "\n" $brokerList | nindent 4 }}
  52. {{- if (include "kafka.client.saslAuthentication" .) }}
  53. You need to configure your Kafka client to access using SASL authentication. To do so, you need to create the 'kafka_jaas.conf' and 'client.properties' configuration files with the content below:
  54. - kafka_jaas.conf:
  55. KafkaClient {
  56. {{- if $saslMechanisms | regexFind "scram" }}
  57. org.apache.kafka.common.security.scram.ScramLoginModule required
  58. {{- else }}
  59. org.apache.kafka.common.security.plain.PlainLoginModule required
  60. {{- end }}
  61. username="{{ index (coalesce .Values.auth.sasl.jaas.clientUsers .Values.auth.jaas.clientUsers) 0 }}"
  62. password="$(kubectl get secret {{ $fullname }}-jaas --namespace {{ $releaseNamespace }} -o jsonpath='{.data.client-passwords}' | base64 --decode | cut -d , -f 1)";
  63. };
  64. - client.properties:
  65. security.protocol={{ $clientProtocol }}
  66. {{- if $saslMechanisms | regexFind "scram-sha-256" }}
  67. sasl.mechanism=SCRAM-SHA-256
  68. {{- else if $saslMechanisms | regexFind "scram-sha-512" }}
  69. sasl.mechanism=SCRAM-SHA-512
  70. {{- else }}
  71. sasl.mechanism=PLAIN
  72. {{- end }}
  73. {{- if eq $clientProtocol "SASL_SSL" }}
  74. ssl.truststore.type={{ upper .Values.auth.tls.type }}
  75. {{- if eq .Values.auth.tls.type "jks" }}
  76. ssl.truststore.location=/tmp/kafka.truststore.jks
  77. {{- if not (empty $tlsPassword) }}
  78. ssl.truststore.password={{ $tlsPassword }}
  79. {{- end }}
  80. {{- else if eq .Values.auth.tls.type "pem" }}
  81. ssl.truststore.certificates=-----BEGIN CERTIFICATE----- \
  82. ... \
  83. -----END CERTIFICATE-----
  84. {{- end }}
  85. {{- if eq $tlsEndpointIdentificationAlgorithm "" }}
  86. ssl.endpoint.identification.algorithm=
  87. {{- end }}
  88. {{- end }}
  89. {{- else if (include "kafka.client.tlsEncryption" .) }}
  90. You need to configure your Kafka client to access using TLS authentication. To do so, you need to create the 'client.properties' configuration file with the content below:
  91. security.protocol={{ $clientProtocol }}
  92. ssl.truststore.type={{ upper .Values.auth.tls.type }}
  93. {{- if eq .Values.auth.tls.type "jks" }}
  94. ssl.truststore.location=/tmp/kafka.truststore.{{ .Values.auth.tls.type }}
  95. {{- if not (empty $tlsPassword) }}
  96. ssl.truststore.password={{ $tlsPassword }}
  97. {{- end }}
  98. {{- else if eq .Values.auth.tls.type "pem" }}
  99. ssl.truststore.certificates=-----BEGIN CERTIFICATE----- \
  100. ... \
  101. -----END CERTIFICATE-----
  102. {{- end }}
  103. {{- if eq .Values.auth.clientProtocol "mtls" }}
  104. ssl.keystore.type={{ upper .Values.auth.tls.type }}
  105. {{- if eq .Values.auth.tls.type "jks" }}
  106. ssl.keystore.location=/tmp/client.keystore.jks
  107. {{- if not (empty $tlsPassword) }}
  108. ssl.keystore.password={{ $tlsPassword }}
  109. {{- end }}
  110. {{- else if eq .Values.auth.tls.type "pem" }}
  111. ssl.keystore.certificate.chain=-----BEGIN CERTIFICATE----- \
  112. ... \
  113. -----END CERTIFICATE-----
  114. ssl.keystore.key=-----BEGIN ENCRYPTED PRIVATE KEY----- \
  115. ... \
  116. -----END ENCRYPTED PRIVATE KEY-----
  117. {{- end }}
  118. {{- end }}
  119. {{- if eq $tlsEndpointIdentificationAlgorithm "" }}
  120. ssl.endpoint.identification.algorithm=
  121. {{- end }}
  122. {{- end }}
  123. To create a pod that you can use as a Kafka client run the following commands:
  124. kubectl run {{ $fullname }}-client --restart='Never' --image {{ template "kafka.image" . }} --namespace {{ $releaseNamespace }} --command -- sleep infinity
  125. {{- if or (include "kafka.client.saslAuthentication" .) (include "kafka.client.tlsEncryption" .) }}
  126. kubectl cp --namespace {{ $releaseNamespace }} /path/to/client.properties {{ $fullname }}-client:/tmp/client.properties
  127. {{- end }}
  128. {{- if (include "kafka.client.saslAuthentication" .) }}
  129. kubectl cp --namespace {{ $releaseNamespace }} /path/to/kafka_jaas.conf {{ $fullname }}-client:/tmp/kafka_jaas.conf
  130. {{- end }}
  131. {{- if and (include "kafka.client.tlsEncryption" .) (eq .Values.auth.tls.type "jks") }}
  132. kubectl cp --namespace {{ $releaseNamespace }} ./kafka.truststore.jks {{ $fullname }}-client:/tmp/kafka.truststore.jks
  133. {{- if eq .Values.auth.clientProtocol "mtls" }}
  134. kubectl cp --namespace {{ $releaseNamespace }} ./client.keystore.jks {{ $fullname }}-client:/tmp/client.keystore.jks
  135. {{- end }}
  136. {{- end }}
  137. kubectl exec --tty -i {{ $fullname }}-client --namespace {{ $releaseNamespace }} -- bash
  138. {{- if (include "kafka.client.saslAuthentication" .) }}
  139. export KAFKA_OPTS="-Djava.security.auth.login.config=/tmp/kafka_jaas.conf"
  140. {{- end }}
  141. PRODUCER:
  142. kafka-console-producer.sh \
  143. {{ if or (include "kafka.client.saslAuthentication" .) (include "kafka.client.tlsEncryption" .) }}--producer.config /tmp/client.properties \{{ end }}
  144. --broker-list {{ join "," $brokerList }} \
  145. --topic test
  146. CONSUMER:
  147. kafka-console-consumer.sh \
  148. {{ if or (include "kafka.client.saslAuthentication" .) (include "kafka.client.tlsEncryption" .) }}--consumer.config /tmp/client.properties \{{ end }}
  149. --bootstrap-server {{ $fullname }}.{{ $releaseNamespace }}.svc.{{ $clusterDomain }}:{{ .Values.service.port }} \
  150. --topic test \
  151. --from-beginning
  152. {{- if .Values.externalAccess.enabled }}
  153. To connect to your Kafka server from outside the cluster, follow the instructions below:
  154. {{- if eq "NodePort" .Values.externalAccess.service.type }}
  155. {{- if .Values.externalAccess.service.domain }}
  156. Kafka brokers domain: Use your provided hostname to reach Kafka brokers, {{ .Values.externalAccess.service.domain }}
  157. {{- else }}
  158. Kafka brokers domain: You can get the external node IP from the Kafka configuration file with the following commands (Check the EXTERNAL listener)
  159. 1. Obtain the pod name:
  160. kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ template "kafka.name" . }},app.kubernetes.io/instance={{ .Release.Name }},app.kubernetes.io/component=kafka"
  161. 2. Obtain pod configuration:
  162. kubectl exec -it KAFKA_POD -- cat /opt/bitnami/kafka/config/server.properties | grep advertised.listeners
  163. {{- end }}
  164. Kafka brokers port: You will have a different node port for each Kafka broker. You can get the list of configured node ports using the command below:
  165. echo "$(kubectl get svc --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ template "kafka.name" . }},app.kubernetes.io/instance={{ .Release.Name }},app.kubernetes.io/component=kafka,pod" -o jsonpath='{.items[*].spec.ports[0].nodePort}' | tr ' ' '\n')"
  166. {{- else if contains "LoadBalancer" .Values.externalAccess.service.type }}
  167. NOTE: It may take a few minutes for the LoadBalancer IPs to be available.
  168. Watch the status with: 'kubectl get svc --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ template "kafka.name" . }},app.kubernetes.io/instance={{ .Release.Name }},app.kubernetes.io/component=kafka,pod" -w'
  169. Kafka Brokers domain: You will have a different external IP for each Kafka broker. You can get the list of external IPs using the command below:
  170. echo "$(kubectl get svc --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ template "kafka.name" . }},app.kubernetes.io/instance={{ .Release.Name }},app.kubernetes.io/component=kafka,pod" -o jsonpath='{.items[*].status.loadBalancer.ingress[0].ip}' | tr ' ' '\n')"
  171. Kafka Brokers port: {{ .Values.externalAccess.service.port }}
  172. {{- end }}
  173. {{- end }}
  174. {{- end }}
  175. {{- include "common.warnings.rollingTag" .Values.image }}
  176. {{- include "common.warnings.rollingTag" .Values.externalAccess.autoDiscovery.image }}
  177. {{- include "common.warnings.rollingTag" .Values.metrics.kafka.image }}
  178. {{- include "common.warnings.rollingTag" .Values.metrics.jmx.image }}
  179. {{- include "kafka.validateValues" . }}