<p>I'm new to Kubernetes, and fairly new to Kafka.</p>

<p>My goal is to get my Kafka Connect instance to properly connect to my Broker, so that it can receive messages.</p>

<p>So far, I've created a Zookeeper deployment and wrapped it in a service. (As far as I understand, this is necessary for the Kafka broker to be able to refer to zookeeper as simply "zookeeper:2181".)</p>

<p><a href="https://i.stack.imgur.com/Yx674.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Yx674.png" alt="Minikube diagram"></a></p>

<p>I had hoped that setting up the Kafka Connect instance would be just as simple. I wrapped my broker in a service, and pointed my Connect instance to it by name.</p>

<p><em>worker.properties</em></p>

<pre><code>bootstrap.servers=kafka-broker:9092
</code></pre>

<p>However, Connect crashes with this exception:</p>

<pre><code>java.io.IOException: Can't resolve address: kafka-broker-57b74c6766-d9w5j:9092
    at org.apache.kafka.common.network.Selector.doConnect(Selector.java:235)
    at org.apache.kafka.common.network.Selector.connect(Selector.java:214)
    at org.apache.kafka.clients.NetworkClient.initiateConnect(NetworkClient.java:864)
    at org.apache.kafka.clients.NetworkClient.ready(NetworkClient.java:265)
    at org.apache.kafka.clients.admin.KafkaAdminClient$AdminClientRunnable.sendEligibleCalls(KafkaAdminClient.java:889)
    at org.apache.kafka.clients.admin.KafkaAdminClient$AdminClientRunnable.run(KafkaAdminClient.java:1104)
    at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.nio.channels.UnresolvedAddressException
    at java.base/sun.nio.ch.Net.checkAddress(Net.java:130)
    at java.base/sun.nio.ch.SocketChannelImpl.connect(SocketChannelImpl.java:675)
    at org.apache.kafka.common.network.Selector.doConnect(Selector.java:233)
    ... 6 more
</code></pre>

<p>I've created an alpine-based pod <a href="https://kubernetes.io/docs/tasks/debug-application-cluster/debug-service/#running-commands-in-a-pod" rel="nofollow noreferrer">as described here</a>, and I can successfully <code>curl -v kafka-broker:9092</code>. But this is not the address that Connect is trying to resolve. It's trying to resolve <code>kafka-broker-57b74c6766-d9w5j:9092</code>, which, like Connect, I cannot resolve. I'm not sure why Connect is trying to contact a specific pod, since this is the exact problem that Kubernetes services are supposed to prevent (in my limited understanding, anyway).</p>

<p>How can get Connect to communicate to the broker correctly?</p>

<hr>

<p>Here's the output of <code>kubectl describe svc kafka-broker</code>:</p>

<pre><code>Name:              kafka-broker
Namespace:         default
Labels:            &lt;none&gt;
Annotations:       &lt;none&gt;
Selector:          app=kafka-broker
Type:              ClusterIP
IP:                10.108.61.90
Port:              &lt;unset&gt;  9092/TCP
TargetPort:        9092/TCP
Endpoints:         172.17.0.7:9092
Session Affinity:  None
Events:            &lt;none&gt;
</code></pre>

<p>To resolve my problem, I had to:</p>

<ul>
<li>Change the <code>kafka-broker</code> Deployment to a StatefulSet.</li>
<li>Make the <code>kafka-broker</code> Service headless by setting <code>spec.clusterIP</code> to <code>"None"</code>. </li>
</ul>

<p>Thank you to @Eduardo Baitello  for this guidance!</p>
