<p>I build kafka cluster on kubernetes following this guilde <a href="https://github.com/kubernetes/contrib/tree/master/statefulsets/kafka" rel="nofollow noreferrer">https://github.com/kubernetes/contrib/tree/master/statefulsets/kafka</a>, it works well for sending/producing message from kubernetes. when I try to expose the kafka cluster using NodePort as follows, kafka clients try to consumer/produce the message from the address <strong><em>10.xx.xx.xx:30092</em></strong></p>

<p>will be failed:</p>

<pre><code>apiVersion: v1
kind: Service
metadata:
  name: kafka-nodeport
  labels:
    app: kafka
spec:
  type: NodePort
  ports:
  - port: 9092
    nodePort: 30092
    name: server
  selector:
    app: kafka
</code></pre>

<p>Why that happened and How to expose the kafka service?</p>

zulv
<p>You have to do two things :</p>

<p>1) create either a service resource of type NodePort (like you did) or an Ingress resource.</p>

<p>2) Set the two properties below in Kafka :
<code>ADVERTISED_HOST</code> and <code>ADVERTISED_PORT</code>.</p>

<p>Kafka will register to Zookeeper with the ip adress of the node, inside containers network it's the internal ip adress that it used so we have to set thoses properties to tell Kafka to register them instead.</p>

<p>Hopes that's help! </p>
