<p>I'm trying to deploy kafka on local k8s, then I need to connect to it by application and using offset explorer</p>
<p>so, using kubectl I created zookeeper service and deployment using this yml file</p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  labels:
    app: zookeeper-service
  name: zookeeper-service
spec:
  type: NodePort
  ports:
    - name: zookeeper-port
      port: 2181
      nodePort: 30091
      targetPort: 2181
  selector:
    app: zookeeper
---
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: zookeeper
  name: zookeeper
spec:
  replicas: 1
  selector:
    matchLabels:
      app: zookeeper
  template:
    metadata:
      labels:
        app: zookeeper
    spec:
      containers:
        - image: bitnami/zookeeper
          imagePullPolicy: IfNotPresent
          name: zookeeper
          ports:
            - containerPort: 2181
          env:
            - name: ALLOW_PLAINTEXT_LISTENER
              value: &quot;yes&quot;
            - name: ALLOW_ANONYMOUS_LOGIN
              value: &quot;yes&quot;
</code></pre>
<p>Then, I created kafka service and deployment using this yml</p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  labels:
    app: kafka-service
  name: kafka-service
spec:
  type: NodePort
  ports:
    - name: kafka-port
      port: 9092
      nodePort: 30092
      targetPort: 9092
  selector:
    app: kafka-broker
---
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: KAFKA_BROKER_ID
              value: &quot;1&quot;
            - name: KAFKA_ZOOKEEPER_CONNECT
              value: &quot;zookeeper-service:2181&quot;
            - name: KAFKA_LISTENERS
              value: PLAINTEXT://localhost:9092
            - name: KAFKA_ADVERTISED_LISTENERS
              value: PLAINTEXT://localhost:9092
            # Creates a topic with one partition and one replica.
            - name: KAFKA_CREATE_TOPICS
              value: &quot;bomc:1:1&quot;
            - name: MY_POD_IP
              valueFrom:
                fieldRef:
                  fieldPath: status.podIP
            - name: ALLOW_PLAINTEXT_LISTENER
              value: &quot;yes&quot;
</code></pre>
<p>And both services and deployment created and running
<a href="https://i.stack.imgur.com/Zh5Rl.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Zh5Rl.png" alt="enter image description here" /></a></p>
<p><a href="https://i.stack.imgur.com/RekR0.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/RekR0.png" alt="enter image description here" /></a></p>
<p>And I have ingress for this services</p>
<pre><code>apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: nginx-ingress
  annotations:
    kubernetes.io/ingress.class: &quot;nginx&quot;
spec:
  rules:
    - http:
        paths:
          - path: /health
            pathType: Prefix
            backend:
              service:
                name: health-app-service
                port:
                  number: 80
          - path: /actuator
            pathType: Prefix
            backend:
              service:
                name: health-app-service
                port:
                  number: 80
          - path: /jsonrpc
            pathType: Prefix
            backend:
              service:
                name: core-service
                port:
                  number: 80
          - path: /
            pathType: Prefix
            backend:
              service:
                name: kafka-service # Название вашего Kafka-сервиса
                port:
                  number: 9092 # Название порта, используемого для Kafka
          - path: /
            pathType: Prefix
            backend:
              service:
                name: kafka-service # Название вашего Kafka-сервиса
                port:
                  number: 30092 # Название порта, используемого для Kafka
          - path: /
            pathType: Prefix
            backend:
              service:
                name: kafka-service # Название вашего Kafka-сервиса
                port:
                  name: kafka-port # Название порта, используемого для Kafka
          - path: /
            pathType: Prefix
            backend:
              service:
                name: zookeeper-service
                port:
                  name: zookeeper-port
</code></pre>
<p><a href="https://i.stack.imgur.com/KZVw1.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/KZVw1.png" alt="enter image description here" /></a></p>
<p>but, when I try to connect to this kafka using offset key tool, there is error connection.</p>
<p><a href="https://i.stack.imgur.com/KK2zV.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/KK2zV.png" alt="enter image description here" /></a></p>
<p><a href="https://i.stack.imgur.com/1y7bk.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1y7bk.png" alt="enter image description here" /></a></p>
<p><a href="https://i.stack.imgur.com/D73lC.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/D73lC.png" alt="enter image description here" /></a></p>
<p>When I use localhost:30092 like a bootstrap server - error with logs:</p>
<pre><code> 12/мар/2023 22:32:46.111 INFO  com.kafkatool.ui.MainApp - Starting application : Offset Explorer
12/мар/2023 22:32:46.111 INFO  com.kafkatool.ui.MainApp - Version : 2.3
12/мар/2023 22:32:46.111 INFO  com.kafkatool.ui.MainApp - Built : Jun 30, 2022
12/мар/2023 22:32:46.111 INFO  com.kafkatool.ui.MainApp - user.home : C:\Users\Roberto
12/мар/2023 22:32:46.111 INFO  com.kafkatool.ui.MainApp - user.dir : C:\Program Files\OffsetExplorer2
12/мар/2023 22:32:46.111 INFO  com.kafkatool.ui.MainApp - os.name : Windows 10
12/мар/2023 22:32:46.111 INFO  com.kafkatool.ui.MainApp - java.runtime.version : 1.8.0_232-b09
12/мар/2023 22:32:46.111 INFO  com.kafkatool.ui.MainApp - max memory=3586 MB
12/мар/2023 22:32:46.111 INFO  com.kafkatool.ui.MainApp - available processors=8
12/мар/2023 22:32:46.111 INFO  com.kafkatool.ui.MainApp - java.security.auth.login.config=null
12/мар/2023 22:32:46.121 INFO  com.kafkatool.common.ExternalDecoderManager - Finding plugins in directory C:\Program Files\OffsetExplorer2\plugins
12/мар/2023 22:32:46.121 INFO  com.kafkatool.common.ExternalDecoderManager - Found files in plugin directory, count=1
12/мар/2023 22:32:46.121 INFO  com.kafkatool.ui.MainApp - Loading user settings
12/мар/2023 22:32:46.153 INFO  com.kafkatool.ui.MainApp - Loading server group settings
12/мар/2023 22:32:46.153 INFO  com.kafkatool.ui.MainApp - Loading server connection settings
12/мар/2023 22:32:50.103 INFO  org.apache.kafka.clients.admin.AdminClientConfig - AdminClientConfig values: 
    bootstrap.servers = [localhost:30092]
    client.dns.lookup = default
    client.id = 
    connections.max.idle.ms = 300000
    metadata.max.age.ms = 300000
    metric.reporters = []
    metrics.num.samples = 2
    metrics.recording.level = INFO
    metrics.sample.window.ms = 30000
    receive.buffer.bytes = 65536
    reconnect.backoff.max.ms = 1000
    reconnect.backoff.ms = 50
    request.timeout.ms = 120000
    retries = 5
    retry.backoff.ms = 100
    sasl.client.callback.handler.class = null
    sasl.jaas.config = null
    sasl.kerberos.kinit.cmd = /usr/bin/kinit
    sasl.kerberos.min.time.before.relogin = 60000
    sasl.kerberos.service.name = null
    sasl.kerberos.ticket.renew.jitter = 0.05
    sasl.kerberos.ticket.renew.window.factor = 0.8
    sasl.login.callback.handler.class = null
    sasl.login.class = null
    sasl.login.refresh.buffer.seconds = 300
    sasl.login.refresh.min.period.seconds = 60
    sasl.login.refresh.window.factor = 0.8
    sasl.login.refresh.window.jitter = 0.05
    sasl.mechanism = GSSAPI
    security.protocol = PLAINTEXT
    security.providers = null
    send.buffer.bytes = 131072
    ssl.cipher.suites = null
    ssl.enabled.protocols = [TLSv1.2, TLSv1.1, TLSv1]
    ssl.endpoint.identification.algorithm = https
    ssl.key.password = null
    ssl.keymanager.algorithm = SunX509
    ssl.keystore.location = null
    ssl.keystore.password = null
    ssl.keystore.type = JKS
    ssl.protocol = TLS
    ssl.provider = null
    ssl.secure.random.implementation = null
    ssl.trustmanager.algorithm = PKIX
    ssl.truststore.location = null
    ssl.truststore.password = null
    ssl.truststore.type = JKS

12/мар/2023 22:32:50.126 DEBUG org.apache.kafka.clients.admin.internals.AdminMetadataManager - [AdminClient clientId=adminclient-1] Setting bootstrap cluster metadata Cluster(id = null, nodes = [localhost:30092 (id: -1 rack: null)], partitions = [], controller = null).
12/мар/2023 22:32:50.188 DEBUG org.apache.kafka.common.metrics.Metrics - Added sensor with name connections-closed:
12/мар/2023 22:32:50.188 DEBUG org.apache.kafka.common.metrics.Metrics - Added sensor with name connections-created:
12/мар/2023 22:32:50.188 DEBUG org.apache.kafka.common.metrics.Metrics - Added sensor with name successful-authentication:
12/мар/2023 22:32:50.188 DEBUG org.apache.kafka.common.metrics.Metrics - Added sensor with name successful-reauthentication:
12/мар/2023 22:32:50.188 DEBUG org.apache.kafka.common.metrics.Metrics - Added sensor with name successful-authentication-no-reauth:
12/мар/2023 22:32:50.188 DEBUG org.apache.kafka.common.metrics.Metrics - Added sensor with name failed-authentication:
12/мар/2023 22:32:50.188 DEBUG org.apache.kafka.common.metrics.Metrics - Added sensor with name failed-reauthentication:
12/мар/2023 22:32:50.198 DEBUG org.apache.kafka.common.metrics.Metrics - Added sensor with name reauthentication-latency:
12/мар/2023 22:32:50.199 DEBUG org.apache.kafka.common.metrics.Metrics - Added sensor with name bytes-sent-received:
12/мар/2023 22:32:50.199 DEBUG org.apache.kafka.common.metrics.Metrics - Added sensor with name bytes-sent:
12/мар/2023 22:32:50.199 DEBUG org.apache.kafka.common.metrics.Metrics - Added sensor with name bytes-received:
12/мар/2023 22:32:50.199 DEBUG org.apache.kafka.common.metrics.Metrics - Added sensor with name select-time:
12/мар/2023 22:32:50.199 DEBUG org.apache.kafka.common.metrics.Metrics - Added sensor with name io-time:
12/мар/2023 22:32:50.204 WARN  org.apache.kafka.clients.admin.AdminClientConfig - The configuration 'group.id' was supplied but isn't a known config.
12/мар/2023 22:32:50.204 INFO  org.apache.kafka.common.utils.AppInfoParser - Kafka version: 2.4.0
12/мар/2023 22:32:50.204 INFO  org.apache.kafka.common.utils.AppInfoParser - Kafka commitId: 77a89fcf8d7fa018
12/мар/2023 22:32:50.204 INFO  org.apache.kafka.common.utils.AppInfoParser - Kafka startTimeMs: 1678649570204
12/мар/2023 22:32:50.214 DEBUG org.apache.kafka.clients.admin.KafkaAdminClient - [AdminClient clientId=adminclient-1] Kafka admin client initialized
12/мар/2023 22:32:50.215 DEBUG org.apache.kafka.clients.admin.KafkaAdminClient - [AdminClient clientId=adminclient-1] Queueing Call(callName=listNodes, deadlineMs=1678649690215) with a timeout 120000 ms from now.
12/мар/2023 22:32:50.215 DEBUG org.apache.kafka.clients.NetworkClient - [AdminClient clientId=adminclient-1] Initiating connection to node localhost:30092 (id: -1 rack: null) using address localhost/127.0.0.1
12/мар/2023 22:32:50.228 DEBUG org.apache.kafka.common.metrics.Metrics - Added sensor with name node--1.bytes-sent
12/мар/2023 22:32:50.230 DEBUG org.apache.kafka.common.metrics.Metrics - Added sensor with name node--1.bytes-received
12/мар/2023 22:32:50.232 DEBUG org.apache.kafka.common.metrics.Metrics - Added sensor with name node--1.latency
12/мар/2023 22:32:50.232 DEBUG org.apache.kafka.common.network.Selector - [AdminClient clientId=adminclient-1] Created socket with SO_RCVBUF = 65536, SO_SNDBUF = 131072, SO_TIMEOUT = 0 to node -1
12/мар/2023 22:32:50.320 DEBUG org.apache.kafka.clients.NetworkClient - [AdminClient clientId=adminclient-1] Completed connection to node -1. Fetching API versions.
12/мар/2023 22:32:50.320 DEBUG org.apache.kafka.clients.NetworkClient - [AdminClient clientId=adminclient-1] Initiating API versions fetch from node -1.
12/мар/2023 22:32:50.376 DEBUG org.apache.kafka.common.network.Selector - [AdminClient clientId=adminclient-1] Connection with localhost/127.0.0.1 disconnected
java.io.EOFException
    at org.apache.kafka.common.network.NetworkReceive.readFrom(NetworkReceive.java:96)
    at org.apache.kafka.common.network.KafkaChannel.receive(KafkaChannel.java:424)
    at org.apache.kafka.common.network.KafkaChannel.read(KafkaChannel.java:385)
    at org.apache.kafka.common.network.Selector.attemptRead(Selector.java:651)
    at org.apache.kafka.common.network.Selector.pollSelectionKeys(Selector.java:572)
    at org.apache.kafka.common.network.Selector.poll(Selector.java:483)
    at org.apache.kafka.clients.NetworkClient.poll(NetworkClient.java:540)
    at org.apache.kafka.clients.admin.KafkaAdminClient$AdminClientRunnable.run(KafkaAdminClient.java:1196)
    at java.lang.Thread.run(Thread.java:748)
12/мар/2023 22:33:11.787 DEBUG org.apache.kafka.clients.NetworkClient - [AdminClient clientId=adminclient-1] Node -1 disconnected.
12/мар/2023 22:33:12.766 DEBUG org.apache.kafka.clients.NetworkClient - [AdminClient clientId=adminclient-1] Initiating connection to node localhost:30092 (id: -1 rack: null) using address localhost/127.0.0.1
12/мар/2023 22:33:12.767 DEBUG org.apache.kafka.common.network.Selector - [AdminClient clientId=adminclient-1] Created socket with SO_RCVBUF = 65536, SO_SNDBUF = 131072, SO_TIMEOUT = 0 to node -1
12/мар/2023 22:33:12.767 DEBUG org.apache.kafka.clients.NetworkClient - [AdminClient clientId=adminclient-1] Completed connection to node -1. Fetching API versions.
12/мар/2023 22:33:12.767 DEBUG org.apache.kafka.clients.NetworkClient - [AdminClient clientId=adminclient-1] Initiating API versions fetch from node -1.
12/мар/2023 22:33:12.768 DEBUG org.apache.kafka.common.network.Selector - [AdminClient clientId=adminclient-1] Connection with localhost/127.0.0.1 disconnected
java.io.EOFException
    at org.apache.kafka.common.network.NetworkReceive.readFrom(NetworkReceive.java:96)
    at org.apache.kafka.common.network.KafkaChannel.receive(KafkaChannel.java:424)
    at org.apache.kafka.common.network.KafkaChannel.read(KafkaChannel.java:385)
    at org.apache.kafka.common.network.Selector.attemptRead(Selector.java:651)
    at org.apache.kafka.common.network.Selector.pollSelectionKeys(Selector.java:572)
    at org.apache.kafka.common.network.Selector.poll(Selector.java:483)
    at org.apache.kafka.clients.NetworkClient.poll(NetworkClient.java:540)
    at org.apache.kafka.clients.admin.KafkaAdminClient$AdminClientRunnable.run(KafkaAdminClient.java:1196)
    at java.lang.Thread.run(Thread.java:748)
</code></pre>

Roberto
<p>It seems you have missing broker config, usually I have below config exposed from my docker compose when I run Kafka on my CI</p>
<pre><code>      KAFKA_LISTENERS: 'LISTENER_INTERNAL://kafka:29092,LISTENER_HOST://:9092'
      KAFKA_ADVERTISED_LISTENERS: LISTENER_INTERNAL://kafka:29092,LISTENER_HOST://localhost:9092
      KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: LISTENER_INTERNAL:PLAINTEXT,LISTENER_HOST:PLAINTEXT
      KAFKA_INTER_BROKER_LISTENER_NAME: LISTENER_INTERNAL
</code></pre>
<p>And when some other service tries to internally connect within the docker compose cluster it uses below config</p>
<pre><code>      KAFKA_CLUSTERS_0_BOOTSTRAPSERVERS: kafka:29092
      KAFKA_CLUSTERS_0_ZOOKEEPER: zookeeper-kafka:2181
</code></pre>
<p>This is also explained <a href="https://www.confluent.io/blog/kafka-listeners-explained/" rel="nofollow noreferrer">https://www.confluent.io/blog/kafka-listeners-explained/</a> I hope this helps</p>
