### Connecting to Kafka from inside Kubernetes

You can connect to Kafka by running a simple pod in the K8s cluster like this with a configuration like this:

  apiVersion: v1
  kind: Pod
  metadata:
    name: testclient
    namespace: {{ .Release.Namespace }}
  spec:
    containers:
    - name: kafka
      image: {{ .Values.image }}:{{ .Values.imageTag }}
      command:
        - sh
        - -c
        - "exec tail -f /dev/null"

Once you have the testclient pod above running, you can list all kafka
topics with:

  kubectl -n {{ .Release.Namespace }} exec testclient -- /usr/bin/kafka-topics --zookeeper {{ .Release.Name }}-zookeeper:2181 --list

To create a new topic:

  kubectl -n {{ .Release.Namespace }} exec testclient -- /usr/bin/kafka-topics --zookeeper {{ .Release.Name }}-zookeeper:2181 --topic test1 --create --partitions 1 --replication-factor 1

To listen for messages on a topic:

  kubectl -n {{ .Release.Namespace }} exec -ti testclient -- /usr/bin/kafka-console-consumer --bootstrap-server {{ .Release.Name }}-kafka:9092 --topic test1 --from-beginning

To stop the listener session above press: Ctrl+C

To start an interactive message producer session:
  kubectl -n {{ .Release.Namespace }} exec -ti testclient -- /usr/bin/kafka-console-producer --broker-list {{ .Release.Name }}-kafka-headless:9092 --topic test1

To create a message in the above session, simply type the message and press "enter"
To end the producer session try: Ctrl+C
{{ if .Values.external.enabled }}
### Connecting to Kafka from outside Kubernetes

You have enabled the external access feature of this chart.

**WARNING:** By default this feature allows Kafka clients outside Kubernetes to
connect to Kafka via NodePort(s) in `PLAINTEXT`.

Please see this chart's README.md for more details and guidance.

If you wish to connect to Kafka from outside please configure your external Kafka
clients to point at the following brokers. Please allow a few minutes for all
associated resources to become healthy.
  {{  $fullName := include "kafka.fullname" . }}
  {{- $replicas := .Values.replicas | int }}
  {{- $servicePort := .Values.external.servicePort }}
  {{- $externalFqdn := printf "%s.%s" .Release.Name .Values.external.domain }}
  {{- $root := . }}
  {{- range $i, $e := until $replicas }}
    {{- $externalListenerPort := add $root.Values.external.firstListenerPort $i }}
{{ printf "%s:%d" $externalFqdn $externalListenerPort | indent 2 }}
  {{- end }}
{{- end }}

{{ if .Values.prometheus.jmx.enabled }}
To view JMX configuration (pull request/updates to improve defaults are encouraged):
  {{ if .Values.jmx.configMap.overrideName }}
  kubectl -n {{ .Release.Namespace }} describe configmap {{ .Values.jmx.configMap.overrideName }}
  {{ else }}
  kubectl -n {{ .Release.Namespace }} describe configmap {{ include "kafka.fullname" . }}-metrics
  {{- end }}
{{- end }}
