<ol>
<li>I have Kafka deployed and running in Kubernetes cluster. I am using this image from docker hub - <a href="https://hub.docker.com/r/cloudtrackinc/kubernetes-kafka/" rel="nofollow noreferrer">https://hub.docker.com/r/cloudtrackinc/kubernetes-kafka/</a></li>
<li>I have 3 kube-nodes in my kubernetes cluster. I have 3 Kafka and 3 zookeeper applications running and I have services zoo1,zoo2,zoo3 and kafka-1, kafka-2 and kafka-3 running corresponding to them. I am able to publish/consume from inside kubernetes cluster but I am not able to publish/consume from outside of kubernetes cluster i.e., from external machine not part of kubernetes cluster. </li>
<li>I am able to reach the kube-nodes from external machine - basically I can ping them using name/ip. </li>
<li>I am not using any external load balancer but I have a DNS that can resolve both my external machine and kube-nodes. </li>
<li>Using NodePort or ExternalIP to expose the Kafka service does not work in this case.</li>
<li>Setting <code>KAFKA_ADVERTISED_HOST_NAME</code> or <code>KAFKA_ADVERTISED_LISTENERS</code> in Kafka RC YML that ultimately set <code>ADVERTISED_HOST_NAME</code>/<code>ADVERTISED_LISTENERS</code> properties in <code>server.properties</code> either does not help accessing kafka from outside of kubernetes cluster. </li>
</ol>

<p>Please suggest how can I publish/consume from outside of kubernetes cluster. Thanks much!  </p>

<p>I had the same problem with accessing kafka from outside of k8s cluster on AWS. I manage to solve this issue by using kafka listeners feature which from version 0.10.2 supports multiple interfaces. </p>

<p>here is how I configured kafka container.</p>

<pre><code>    ports:
    - containerPort: 9092
    - containerPort: 9093
    env:
    - name: KAFKA_ZOOKEEPER_CONNECT
      value: "zookeeper:2181"
    - name: KAFKA_LISTENER_SECURITY_PROTOCOL_MAP
      value: "INTERNAL_PLAINTEXT:PLAINTEXT,EXTERNAL_PLAINTEXT:PLAINTEXT"
    - name: KAFKA_ADVERTISED_LISTENERS
      value: "INTERNAL_PLAINTEXT://kafka-internal-service:9092,EXTERNAL_PLAINTEXT://123.us-east-2.elb.amazonaws.com:9093"
    - name: KAFKA_LISTENERS
      value: "INTERNAL_PLAINTEXT://0.0.0.0:9092,EXTERNAL_PLAINTEXT://0.0.0.0:9093"
    - name: KAFKA_INTER_BROKER_LISTENER_NAME
      value: "INTERNAL_PLAINTEXT"
</code></pre>

<p>Apart from that I configured two Services. One for internal(Headless) &amp; one for external(LoadBalancer) communication.</p>

<p>Hopefully this will save people's time.</p>
