Kafka not able to connect with zookeeper with error "Timed out waiting for connection while in state: CONNECTING"

In my case I was trying to start Kafka server before starting the Zookeeper.

So correct order is to start Zookeeper and then Kafka server.


What could be the reason for this ? and solutions ?

The reason is hidden behind following log line:

INFO Connecting to zookeeper on zookeeper:2181 (kafka.server.KafkaServer)

Kafka is searching for zookeeper while it should search for your service name which is zookeeper-svc.

The solution is then straightforward: to either rename your zookeeper service from zookeeper-svc to zookeeper in your zookeeper-service.yaml like so:

apiVersion: v1
kind: Service
metadata:
  annotations:
    kompose.cmd: kompose convert
    kompose.version: 1.1.0 (36652f6)
  creationTimestamp: null
  labels:
    io.kompose.service: zookeeper
  name: zookeeper
spec:
  ports:
  - name: "2181"
    port: 2181
    targetPort: 2181
  selector:
    io.kompose.service: zookeeper
status:
  loadBalancer: {}

or, more clean, to keep service name as it is and reconfigure Kafka to search for zookeeper-svc instead of zookeeper.

Note: since your minimal example was enough to reproduce the issue (thank you, it is nice to see working minimal example!), although pod is up and running (not in error state) it still shows: java.io.IOException: Can't resolve address: kafka:9092 which is tied to another issue (service not covering Kafka deployment) and is out of the scope of this question, just to let you know.