2

I am trying to connect my springboot app (running inside minikube) to kafka on my localhost (ie, laptop).

I have tried many things, including headless services, services without selectors, updating minikube \etc\hosts, but nothing works yet.

I get error from spring boot saying No resolvable bootstrap urls given in bootstrap.servers

Can someone please point me to what I am doing wrong?

My Headless Service

apiVersion: v1
kind: Service
metadata:
  name: es-local-kafka
  namespace: demo
spec:
  clusterIP: None
---
apiVersion: v1
kind: Endpoints
metadata:
  name: es-local-kafka
subsets:
  - addresses:
      - ip: "10.0.2.2"
    ports:
      - name: "kafkabroker1"
        port: 9191
      - name: "kafkabroker2"
        port: 9192
      - name: "kafkabroker3"
        port: 9193

My application properties for kafka:

kafka.bootstrap-servers=${LOCALHOST}:9191,${LOCALHOST}:9192,${LOCALHOST}:9193

My Config Map:

apiVersion: v1
kind: ConfigMap
metadata:
  creationTimestamp: null
  name: rr-config
  namespace: demo
data:
  LOCALHOST: es-local-kafka.demo.svc
Somjit
  • 2,503
  • 5
  • 33
  • 60
  • Hi Somjit, what version of minikube are you using, on what operating system? Which driver minikube uses (minikube profile list)? – mozello Feb 04 '22 at 12:20

2 Answers2

0

I eventually got a fix, and doesn't need all the crazy stuff I was referring to in my question:

  1. You need to make sure your kafka broker is bound to 0.0.0.0 instead of 127.0.0.0 (localhost) . By default, in the single node kafka broker setup, this is what is used. I went with this, due to both time constraint, and the fact that this was just for a POC in my local (prod will have a specific dns-able kafka URL anyway, and no such localhost shenanigans needed)

  2. In the kafka URL in your application properties file, instead of localhost, you need to give ip as as the minikube ip. This is the same ip that you will get if you do the command minikube ip :)

Read more about how this works here: https://minikube.sigs.k8s.io/docs/handbook/host-access/

Somjit
  • 2,503
  • 5
  • 33
  • 60
-1

Not sure how you are trying to connect service running on Minikube or on the local system and want to leverage kafka on minikube.

If your application running on local system and Kafka on minikube

you can connect the application to Kafka cluster with the IP of minikube also.

Here is good example : https://github.com/d1egoaz/minikube-kafka-cluster

Git clone : https://github.com/d1egoaz/minikube-kafka-cluster

cd minikube-kafka-cluster

kubectl apply -f 00-namespace/

kubectl apply -f 01-zookeeper/

kubectl apply -f 02-kafka/

kubectl apply -f 03-yahoo-kafka-manager/

kubectl get svc -n kafka-ca1 (Note the port of kafka 31445)

list the Ip of minikube

minikube ip 

Now from your local system to minikube kafka you can connect with, http://minikube-ip:port you will see UI of kafka manager in browser

If you are running sprint boot application on the minikube

If both services are running in same namespace you just have to use the service name only to connect

Only service name in sprint boot, if port required you can also pass it

es-local-kafka

try with passing full service also

<servicename>.<namespace>.svc.cluster.local

Headless service is for different purposes and service without a selector is weird in that case your service wont be able to connect to PODs.

Harsh Manvar
  • 27,020
  • 6
  • 48
  • 102
  • Hi Harsh, I am running spring boot inside minikube, and kafka outside minikube. Sorry for the confusion. can you help given this situation? – Somjit Feb 03 '22 at 05:38
  • in this situation, you should have to use the host machine ip into endpoint `10.0.2.2` is it that mentioned ? did you tried from host machine kafka is running on that address ? – Harsh Manvar Feb 03 '22 at 19:29
  • what does use the host machine ip into endpoint `10.0.2.2` look like in config? and yes, kafka is running, and bound to 0.0.0.0 also – Somjit Feb 03 '22 at 19:34
  • hope your kafka is running on `0.0.0.0` check out this : https://minikube.sigs.k8s.io/docs/handbook/host-access/ – Harsh Manvar Feb 03 '22 at 19:38