I am having spring boot app where in application.property
we are specifying below properties. kafka is installed on remote machine with self-signed certificate (outside the kubernete cluster).
camel.component.kafka.configuration.brokers=kafka-worker1.abc.com:9092,kafka-worker2.abc.com:9092,kafka-worker3.abc.com:9092
at startup of application it will try to look for kafka broker. now if i add hostaliases to deployment it will work fine like below
hostAliases:
- ip: 10.76.XX.XX
hostnames:
- kafka-worker1.abc.com
- ip: 10.76.XX.XX
hostnames:
- kafka-worker2.abc.com
- ip: 10.76.XX.XX
hostnames:
- kafka-worker3.abc.com
it will work fine but i dont want this as its not good practice to have hostaliases , we may need to restart the pod if IP changes. we want that hostname resolution to be happen on coredns, or to resolve without adding ip to host file of pod.
how to achieve this. followed this Cannot connecto to external database from inside kubernetes pod service endpoint like below created for kafka-worker2 & kafka-worker3 with respective IP
kind: Service
apiVersion: v1
metadata:
name: kafka-worker1
spec:
clusterIP: None
ports:
- port: 9092
targetPort: 9092
externalIPs:
- 10.76.XX.XX
and added this in property file
camel.component.kafka.configuration.brokers=kafka-worker1.default:9092,kafka-worker2.default:9092,kafka-worker3.default:9092
still getting same WARN
2020-05-13T11:57:12.004+0000 Etc/UTC docker-desktop WARN [main] org.apache.kafka.clients.ClientUtils(:74) - Couldn't resolve server hal18-coworker2.default:9092 from bootstrap.servers as DNS resolution failed for kafka-worker1.default
2020-05-13T11:57:12.318+0000 Etc/UTC docker-desktop WARN [main] org.apache.kafka.clients.ClientUtils(:74) - Couldn't resolve server hal18-coworker1.default:9092 from bootstrap.servers as DNS resolution failed for kafka-worker2.default
2020-05-13T11:57:12.567+0000 Etc/UTC docker-desktop WARN [main] org.apache.kafka.clients.ClientUtils(:74) - Couldn't resolve server hal18-coworker3.default:9092 from bootstrap.servers as DNS resolution failed for kafka-worker3.default
Update Section
Used "Services without selectors" as below still getting same error
2020-05-18T14:47:10.865+0000 Etc/UTC docker-desktop WARN [Camel (SMP-Proactive-Camel) thread #1 - KafkaConsumer[recommendations-topic]] org.apache.kafka.clients.NetworkClient(:750) - [Consumer clientId=consumer-hal-tr69-streaming-1, groupId=hal-tr69-streaming] Connection to node -1 (kafka-worker.default.svc.cluster.local/10.100.153.152:9092) could not be established. Broker may not be available.
2020-05-18T14:47:12.271+0000 Etc/UTC docker-desktop WARN [Camel (SMP-Proactive-Camel) thread #1 - KafkaConsumer[recommendations-topic]] org.apache.kafka.clients.NetworkClient(:750) - [Consumer clientId=consumer-hal-tr69-streaming-1, groupId=hal-tr69-streaming] Connection to node -1 (kafka-worker.default.svc.cluster.local/10.100.153.152:9092) could not be established. Broker may not be available.
2020-05-18T14:47:14.191+0000 Etc/UTC docker-desktop WARN [Camel (SMP-Proactive-Camel) thread #1 - KafkaConsumer[recommendations-topic]] org.apache.kafka.clients.NetworkClient(:750) - [Consumer clientId=consumer-hal-tr69-streaming-1, groupId=hal-tr69-streaming] Connection to node -1 (kafka-worker.default.svc.cluster.local/10.100.153.152:9092) could not be established. Broker may not be available.
Services & Endpoint yaml
apiVersion: v1
kind: Service
metadata:
name: kafka-worker
spec:
type: ClusterIP
ports:
- port: 9092
targetPort: 9092
---
apiVersion: v1
kind: Endpoints
metadata:
name: kafka-worker
subsets:
- addresses:
- ip: 10.76.XX.XX # kafka worker 1
- ip: 10.76.XX.XX # kafka worker 2
- ip: 10.76.XX.XX # kafka worker 3
ports:
- port: 9092
name: kafka-worker
kubectl.exe get svc,ep
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/ingress-nginx-controller LoadBalancer 10.99.101.185 localhost 80:31247/TCP,443:31340/TCP 11d
service/ingress-nginx-controller-admission ClusterIP 10.103.212.117 <none> 443/TCP 11d
service/kafka-worker ClusterIP 10.100.153.152 <none> 9092/TCP 97s
service/kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 17d
NAME ENDPOINTS AGE
endpoints/ingress-nginx-controller 10.1.0.XX:80,10.1.0.XX:443 11d
endpoints/ingress-nginx-controller-admission 10.1.0.xx:8443 11d
endpoints/kafka-worker 10.76.xx.xx:9092,10.76.xx.xx:9092,10.76.xx.xx:9092 97s
endpoints/kubernetes 192.168.XX.XX:6443 17d