<p>I'm trying to create an external access about confluent-kafka from an AKS cluster. I've been able to connect with control center with an Ingress but i can't create the external access from kafka.
I added this to spec of kafka:</p>
<pre><code>listeners:
    external:
      externalAccess:
        type: loadBalancer
        loadBalancer: 
          domain: lb.example.it
          advertisedPort: 39093
</code></pre>
<p>and it creates two load-balancer services. Then i added the external IPs on my etc/hosts file:</p>
<pre><code>20.31.10.27    kafka.lb.example.it
20.31.9.167    b0.lb.example.it
</code></pre>
<p>But when i ceate a nodejs producer i don't know what to put into broker:</p>
<pre><code>const { Kafka } = require('kafkajs')
const kafka = new Kafka({
  clientId: 'my-app',
  brokers: ['kafka.lb.example.it:39093']
})

const producer = kafka.producer()
console.log(&quot;produced&quot;)


const asyncOperation = async () =&gt; {
  console.log(&quot;connecting&quot;)
await producer.connect()
console.log(&quot;connected&quot;)
let i = 0

try{
  while(true){
  await producer.send({
    topic: 'topic_prova3',
    messages: [
                {
                  key: JSON.stringify(&quot;hello&quot;),
                  value: JSON.stringify({&quot;NUM&quot;:i}),
                },
              ]
            })
  await producer.send({
    topic: 'topic_prova3',
    messages: [
                {
                  value: JSON.stringify({&quot;NUMERO&quot;:i.toString()}),
                },
              ]
            })
  console.log(&quot;sended&quot;)
  i++
await new Promise(resolve =&gt; setTimeout(resolve, 5000));

}
}
catch(err){
  console.error(&quot;error: &quot; + err)
}
await producer.disconnect()
}

asyncOperation();
</code></pre>
<p>This is the log of the error:</p>
<pre><code>{&quot;level&quot;:&quot;ERROR&quot;,&quot;timestamp&quot;:&quot;2023-01-22T08:43:20.761Z&quot;,&quot;logger&quot;:&quot;kafkajs&quot;,&quot;message&quot;:&quot;[Connection] Connection error: connect ECONNREFUSED 127.0.0.2:9092&quot;,&quot;broker&quot;:&quot;kafka-0.kafka.ckafka.svc.cluster.local:9092&quot;,&quot;clientId&quot;:&quot;my-app&quot;,&quot;stack&quot;:&quot;Error: connect ECONNREFUSED 127.0.0.2:9092\n    at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1495:16)&quot;}
</code></pre>
<p>The broker should be <code>kafka.ckafka.svc.cluster.local:9092</code> , instead of <code>kafka-0.kafka.ckafka.svc.cluster.local:9092</code> but it does it automatically</p>

Luana Mantovan
<p>The load balancer appears to be working (it's not throwing unknown host exception), and it returned a cluster local broker address. See above comment that explains why this happens within Kubernetes with Kafka.</p>
<p>You need to modify, or use, the appropriate <code>advertised.listeners</code> port that corresponds to the external LoadBalancer.</p>
<blockquote>
<p>from an AKS cluster.</p>
</blockquote>
<p>You should use Azure services to create a public DNS route rather than specifically target one IP of your cluster for any given service in /etc/hosts; especially when you'd deploy multiple replicas of the Kafka pod.</p>
