Kubernetes Kafka Endpoint已创建但Pod解析异常,咨询端口映射规则
Let me break this down clearly — you’re absolutely spot-on with your observation: Kubernetes Endpoints only map IP addresses, not ports, when referenced by name.
Here’s the breakdown of what happened:
- When you created the
kafkaEndpoint, you defined the target IP and port, but the Endpoint object itself acts as a DNS entry that only resolves to the listed IP(s). The port isn’t included in the DNS resolution for the Endpoint name. - When you set
BROKER_IP=kafkain your Deployment, your Spring Boot app only received the hostname (which resolves to the Endpoint’s IP), with no port information attached. That’s why your bootstrap server config was missing the critical port value, leading to connection failures. - Once you updated the env var to
kafka:9092, you explicitly added the port your Kafka cluster listens on, which let your app establish a proper connection.
To put it simply: Kubernetes Endpoints exist to map a logical name to a set of backend IPs. Port details are typically handled by Kubernetes Services (if you use one), but when working directly with Endpoints, you have to specify the port explicitly in your application configuration.
If you want to avoid hardcoding the port in your env var, consider creating a Kubernetes Service tied to your existing Endpoint. A Service can include port mapping, so referencing the Service name (kafka) will automatically handle port forwarding. Here’s a quick example of what that Service might look like:
apiVersion: v1 kind: Service metadata: name: kafka spec: ports: - port: 9092 targetPort: 9092 selector: {} # Leave empty to bind directly to your existing Endpoint
With this Service deployed, you could set BROKER_IP=kafka again, and your app would automatically resolve to kafka:9092 since the Service handles the port mapping behind the scenes.
内容的提问来源于stack exchange,提问作者Arpan Sharma

