A developer created a Deployment with 3 replicas and a ClusterIP Service named 'app-service' on port 80 targeting port 8080 on the pods. Pod logs show that the container is listening on 8080, but curl from another pod in the same namespace to http://app-service:80 fails with 'Connection refused'. What is the most likely cause?
Trap 1: The container port is 8080 but the Service targetPort is 80.
This option is incorrect because the Service's targetPort is already correctly configured to match the container's listening port of 8080. If a mismatch actually existed, traffic would be routed to an inactive port on the container, but the configuration details confirm that the ports are aligned. Therefore, port mismatch is not the root cause of the connectivity issue.
Trap 2: The Service type should be NodePort for inter-pod communication.
The default ClusterIP service type is specifically designed and sufficient for secure, internal inter-pod communication within a Kubernetes cluster. Changing the service type to NodePort is unnecessary and introduces security risks by exposing the service on a static port across all cluster nodes. Internal workloads should always use ClusterIP to communicate with each other.
Trap 3: The DNS resolution for 'app-service' is failing.
If DNS resolution for the service name were failing, the client pod would throw a 'name not resolved' or 'host not found' error rather than a connection timeout or refusal. The ability to attempt a connection indicates that CoreDNS successfully resolved 'app-service' to its ClusterIP. The failure occurs at the network routing layer because no backend endpoints are associated with that IP.
- A
The Service selector does not match the pod labels.
Kubernetes Services rely on label selectors to dynamically discover and route traffic to backend Pods. If the Service's selector does not match the labels defined in the Deployment's Pod template, the Service will fail to populate its Endpoints or EndpointSlice resources. Consequently, any traffic sent to the Service IP will result in a connection failure because there are no active backend Pods registered to receive the traffic.
- B
The container port is 8080 but the Service targetPort is 80.
Why wrong: This option is incorrect because the Service's targetPort is already correctly configured to match the container's listening port of 8080. If a mismatch actually existed, traffic would be routed to an inactive port on the container, but the configuration details confirm that the ports are aligned. Therefore, port mismatch is not the root cause of the connectivity issue.
- C
The Service type should be NodePort for inter-pod communication.
Why wrong: The default ClusterIP service type is specifically designed and sufficient for secure, internal inter-pod communication within a Kubernetes cluster. Changing the service type to NodePort is unnecessary and introduces security risks by exposing the service on a static port across all cluster nodes. Internal workloads should always use ClusterIP to communicate with each other.
- D
The DNS resolution for 'app-service' is failing.
Why wrong: If DNS resolution for the service name were failing, the client pod would throw a 'name not resolved' or 'host not found' error rather than a connection timeout or refusal. The ability to attempt a connection indicates that CoreDNS successfully resolved 'app-service' to its ClusterIP. The failure occurs at the network routing layer because no backend endpoints are associated with that IP.