<p>I created kafka service and kafka pod in k8s cluster and deployed my application.
So, I can read\write messages to kafka from my application in the same cluster k8s, but I can't connect to kafka using external tools like kafka-tool or offset-explorer
This is my yml for kafka pod and service:</p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  labels:
    app: kafka-service
  name: kafka-service
spec:
  type: NodePort
  selector:
    app: kafka-broker
  ports:
    - name: kafka-port
      port: 9092
      targetPort: 9092
      nodePort: 30126
---
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: kafka-broker
  name: kafka-broker
spec:
  replicas: 1
  selector:
    matchLabels:
      app: kafka-broker
  template:
    metadata:
      labels:
        app: kafka-broker
    spec:
      hostname: kafka-broker
      containers:
        - image: bitnami/kafka
          imagePullPolicy: IfNotPresent
          name: kafka-broker
          ports:
            - containerPort: 9092
          env:
            - name: ALLOW_PLAINTEXT_LISTENER
              value: &quot;yes&quot;
            - name: KAFKA_LISTENER_SECURITY_PROTOCOL_MAP
              value: INTERNAL:PLAINTEXT,EXTERNAL:PLAINTEXT
            - name: KAFKA_INTER_BROKER_LISTENER_NAME
              value: INTERNAL
            - name: KAFKA_BROKER_ID
              value: &quot;1&quot;
            - name: KAFKA_ZOOKEEPER_CONNECT
              value: &quot;zookeeper-service:2181&quot;
            - name: KAFKA_LISTENERS
              value: INTERNAL://:9092,EXTERNAL://localhost:9093
            - name: KAFKA_ADVERTISED_LISTENERS
              value: INTERNAL://kafka-service:9092,EXTERNAL://localhost:9093
            # Creates a topic with one partition and one replica.
            - name: KAFKA_CFG_AUTO_CREATE_TOPICS_ENABLE
              value: &quot;true&quot;
            - name: KAFKA_CREATE_TOPICS
              value: &quot;PARSEREVENT:1:1&quot;
            - name: MY_POD_IP
              valueFrom:
                fieldRef:
                  fieldPath: status.podIP
</code></pre>
<p>My application success config is</p>
<pre><code>...
    consumer:
      bootstrap-servers: kafka-service:9092
...
</code></pre>
<p>And my failed config for offset explorer like this</p>
<p><a href="https://i.stack.imgur.com/qOqmr.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/qOqmr.png" alt="enter image description here" /></a></p>
<p>I tried to user port-forwarding to:</p>
<pre><code>kubectl port-forward kafka-broker-5787578d7f-bmgc5 9093:9093
</code></pre>
<p>and like this</p>
<pre><code>kubectl port-forward kafka-broker-5787578d7f-bmgc5 9092:9092
</code></pre>
<p>And I tried to set localhost:9092 and localhost:9093 in advinced tab, and tried to set empty value too
All of this cases throws connection timeout errors</p>
<p>What can I try something else for fix issue?</p>

Roberto
<p>Port 9093 will only allow connections <strong>from internal to the Kafka container</strong>. This is what <code>KAFKA_LISTENERS</code> sets; not external connections, despite what you've named the protocol.</p>
<p>You've set <code>nodePort: 30126</code>, which means this is the port you need to define in <code>KAFKA_ADVERTISED_LISTENERS</code>. Then you should be able to connect to <code>localhost:30126</code>, and not need to port forward anything.</p>
<p>Otherwise, as I already linked before, please read each part of <a href="https://strimzi.io/blog/2019/04/17/accessing-kafka-part-1/" rel="nofollow noreferrer">https://strimzi.io/blog/2019/04/17/accessing-kafka-part-1/</a></p>
<p>(and do use Strimzi, or another Operator / Helm Charts, Please don't try to create your own Deployment and Service files)</p>
<hr />
<p>Also, Zookeeper is being removed from Kafka, so I suggest you use a different tool that doesn't need Zookeeper details. These include HTTP-based ones like AKHQ, which you can run and access in Kubernetes without port forwarding Kafka itself.</p>
