Kubernetes Endpoint created for Kafka but not reflecting in POD
Is it possible that you forgot to create the Service object matching the Endpoints? Because you are providing the ip-port pairs yourself the Service would need to be selectorless.
This works for me:
kind: EndpointsapiVersion: v1metadata: name: kafkasubsets: - addresses: [{ip: "1.2.3.4"}] ports: [{port: 9092}]---kind: ServiceapiVersion: v1metadata: name: kafkaspec: ports: [{port: 9092}]
Testing it:
$ kubectl run kafka-dns-test --image=busybox --attach --rm --restart=Never -- nslookup kafkaIf you don't see a command prompt, try pressing enter.Server: 10.96.0.10Address: 10.96.0.10:53Name: kafka.default.svc.cluster.localAddress: 10.96.220.40
Successful lookup, ignore extra *** Can't find xxx: No answer
messages
Also, because there is a Service object you get some environment variables in your Pods (without having to declare them):
KAFKA_PORT='tcp://10.96.220.40:9092'KAFKA_PORT_9092_TCP='tcp://10.96.220.40:9092'KAFKA_PORT_9092_TCP_ADDR='10.96.220.40'KAFKA_PORT_9092_TCP_PORT='9092'KAFKA_PORT_9092_TCP_PROTO='tcp'KAFKA_SERVICE_HOST='10.96.220.40'KAFKA_SERVICE_PORT='9092'
But the most flexible way to use a Service is still to use the dns name (kafka
in this case).