Accessing kafka from spring boot application running on kubernetes
The bootstrap-servers
property expects a list of Kafka server addresses. By putting quotation marks around the value you signaled that the value is a string and therefore create a type conflict.
To solve this issue you should either remove the quotation marks or put the value explicitly in a list form. e.g:
spring: kafka: consumer: bootstrap-servers: ["bootstrap.kafka.svc.cluster.local:9092"]
Sometimes, it will actually be your Kafka Kubernetes deployment that is at fault.
Can I see your deployment YAML/JSON file for the Kafka deployment, please?
It should look like this:
apiVersion: apps/v1kind: Deploymentmetadata: name: api-kafkaspec: replicas: 1 selector: matchLabels: app: kafka id: "0" template: metadata: labels: app: kafka id: "0" spec: containers: - name: kafka image: wurstmeister/kafka:latest ports: - containerPort: 30035 env: - name: KAFKA_ADVERTISED_HOST_NAME valueFrom: fieldRef: fieldPath: status.podIP - name: KAFKA_ADVERTISED_PORT value: "9092" - name: KAFKA_HEAP_OPTS value: -Xms320m - name: KAFKA_ZOOKEEPER_CONNECT value: "zookeeper:2181"---apiVersion: v1kind: Servicemetadata: name: api-kafka namespace: default labels: name: kafkaspec: ports: - port: 9092 name: kafka-port protocol: TCP selector: app: kafka id: "0" type: NodePort
With an emphasis on the:
- name: KAFKA_ADVERTISED_HOST_NAME valueFrom: fieldRef: fieldPath: status.podIP
Make sure your profiles are right and that'll fix all of your problems to do with the connections and the advertised hostnames within a Kubernetes Deployment