Remotely accessing Kafka running inside kubernetes Remotely accessing Kafka running inside kubernetes docker docker

Remotely accessing Kafka running inside kubernetes


You're bootstrapping to port 30035, and getting the initial connection, then the advertised port of 9093 is being returned for subsequent connections, not 30035.

You need the NodePort and advertised one to be the same, or at least both be externally routable. Then you additionally need to have port forwarding on your VM if your code is running on your host machine

Note: Confluent or Strimzi Helm Charts exist for setting up Kafka in Kubernetes


Simple configuration of Kafka/Zookeeper on Kubernetes in AWS/DigitalOcean/GCE/Azure with external access:

https://github.com/StanislavKo/k8s_digitalocean_kafka

You can connect to Kafka from outside of AWS/DO/GCE by regular binary protocol. Connection is PLAINTEXT or SASL_PLAINTEXT (username/password).

Kafka cluster is StatefulSet, so you can scale cluster easily.


I would also propose Strimzi for Kafka on Kubernetes. For the external access this article saved me https://developers.redhat.com/blog/2019/06/11/accessing-apache-kafka-in-strimzi-part-4-load-balancers/.My config looks like:

apiVersion: kafka.strimzi.io/v1beta1kind: Kafkametadata:  name: my-clusterspec:  kafka:    version: 2.4.0    replicas: 1    listeners:      plain: {}      tls: {}      external:        type: loadbalancer        tls: false    config:      offsets.topic.replication.factor: 1      transaction.state.log.replication.factor: 1      transaction.state.log.min.isr: 1      log.message.format.version: "2.4"    storage:      type: ephemeral  zookeeper:    replicas: 1    storage:      type: ephemeral  entityOperator:    topicOperator: {}    userOperator: {}

and this for retrieving the IP

kubectl get service my-cluster-kafka-external-bootstrap -o=jsonpath='{.status.loadBalancer.ingress[0].ip}{"\n"}'