I have a question that I cannot get past. I cannot connect from an External machine to the Kafka Cluster. I can only locally from the Docker host.
#SUCCESS On the docker host (192.168.2.14) where the docker-compose file below is run.
/opt/kafka/bin/kafka-topics.sh --list --bootstrap-server 192.168.2.14:9092
message_shown_topic
#FAIL On another machine (192.168.2.13) I can see it connects because it wouldn’t be able to see that 9094 is also there.
/opt/kafka/bin/kafka-topics.sh --list --bootstrap-server 192.168.2.14:9092,192.168.2.14:9093
[2024-05-15 14:59:11,657] WARN [AdminClient clientId=adminclient-1] Connection to node 1 (/127.0.0.1:9092) could not be established. Broker may not be available. (org.apache.kafka.clients.NetworkClient)
[2024-05-15 14:59:11,662] WARN [AdminClient clientId=adminclient-1] Connection to node 2 (/127.0.0.1:9093) could not be established. Broker may not be available. (org.apache.kafka.clients.NetworkClient)
[2024-05-15 14:59:11,662] WARN [AdminClient clientId=adminclient-1] Connection to node 3 (/127.0.0.1:9094) could not be established. Broker may not be available. (org.apache.kafka.clients.NetworkClient)
Of course, all comes up perfectly when the docker-compose.yaml file below is run as I can list the topics
(https://medium.com/@erkndmrl/kafka-cluster-with-docker-compose-5864d50f677e)
kafka-1:
image: confluentinc/cp-kafka:latest
...
environment:
KAFKA_ADVERTISED_LISTENERS: INTERNAL://kafka-1:19092,EXTERNAL://${DOCKER_HOST_IP:-127.0.0.1}:9092,DOCKER://host.docker.internal:29092
KAFKA_LISTENERS: INTERNAL://0.0.0.0:19092,EXTERNAL://0.0.0.0:9092,DOCKER://0.0.0.0:29092
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: INTERNAL:PLAINTEXT,EXTERNAL:PLAINTEXT,DOCKER:PLAINTEXT
...
kafka-2:
image: confluentinc/cp-kafka:latest
...
environment:
KAFKA_ADVERTISED_LISTENERS: INTERNAL://kafka-2:19093,EXTERNAL://${DOCKER_HOST_IP:-127.0.0.1}:9093,DOCKER://host.docker.internal:29093
KAFKA_LISTENERS: INTERNAL://0.0.0.0:19093,EXTERNAL://0.0.0.0:9093,DOCKER://0.0.0.0:29093
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: INTERNAL:PLAINTEXT,EXTERNAL:PLAINTEXT,DOCKER:PLAINTEXT
...
kafka-3:
image: confluentinc/cp-kafka:latest
...
environment:
KAFKA_ADVERTISED_LISTENERS: INTERNAL://kafka-3:19094,EXTERNAL://${DOCKER_HOST_IP:-127.0.0.1}:9094,DOCKER://host.docker.internal:29094
KAFKA_LISTENERS: INTERNAL://0.0.0.0:19094,EXTERNAL://0.0.0.0:9094,DOCKER://0.0.0.0:29094
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: INTERNAL:PLAINTEXT,EXTERNAL:PLAINTEXT,DOCKER:PLAINTEXT