CKA Services and Networking Practice Question
A developer runs 'kubectl port-forward service/my-svc 8080:80' and reports that connections to localhost:8080 fail. The service is a ClusterIP service that selects pods with label 'app: my-app'. What is the most likely cause?
⚠ Common exam trap
Watch out — candidates often assume port forwarding only works with pods, but Kubernetes actually supports port forwarding to services by automatically selecting a pod from the service's endpoints.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
No pods match the service selector, so the service has no endpoints.
B is correct because if no pods match the service selector 'app: my-app', the service will have no endpoints. Without endpoints, the service cannot route traffic, and kubectl port-forward will fail to establish a connection to localhost:8080. The port-forward command relies on the service having at least one endpoint to forward traffic to.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
The service type is ClusterIP, which does not support port forwarding.
Why it's wrong here
This statement is false because kubectl port-forward fully supports ClusterIP services; the service type has no bearing on port-forwarding capability. The command works by having the API server proxy traffic to a backing pod, and a ClusterIP service's virtual IP is irrelevant for that tunnel. If port-forwarding fails for a ClusterIP service, the cause lies elsewhere, typically missing endpoints, not the service type.
- ✓
No pods match the service selector, so the service has no endpoints.
Why this is correct
This is the correct explanation. For a Service, kubectl port-forward requires at least one ready endpoint, which is created automatically when pod labels match the service's selector. When no pods match, the Endpoints object is empty, causing the API server to fail with an error such as 'Unable to connect to a frontend pod'. The developer must verify the selector against existing pod labels or manually define endpoints for selector-less services.
- ✗
kubectl port-forward cannot forward to services, only to pods.
Why it's wrong here
This is incorrect; kubectl port-forward has supported Service resources since Kubernetes v1.10. The command accepts the syntax `kubectl port-forward service/myservice 8080:80`, and it resolves the service to a randomly selected backing pod before establishing the tunnel via the API server. Thus, the tool's resource support is not limited to pods, so this statement misidentifies a capability that actually exists.
- ✗
The port forward command requires the --address flag to bind to localhost.
Why it's wrong here
This statement is wrong because `--address` is an optional flag that specifies which local interface to bind to, and it defaults to localhost (127.0.0.1). Omitting it does not cause port-forward failures; the default already provides the intended local-only exposure. A port-forward to a service with no endpoints fails before address binding occurs, so the missing flag is irrelevant to the observed problem.
Go deeper
Related to this question
Learn chapter
Network Policies and Secure Connectivity
Key term
ClusterIP NodePort LoadBalancer
ClusterIP, NodePort, and LoadBalancer are three types of Kubernetes Services that control how traffic reaches your application pods inside the cluster or from outside.
Key term
kubectl Command Reference
kubectl is the command-line tool used to interact with and manage Kubernetes clusters by sending commands to the Kubernetes API.
About these practice questions
One of 302 original CKA practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. Learn why practice questions differ from exam dumps →
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This CKA practice question is part of Courseiva's free CNCF certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the CKA exam.