CKA Services and Networking Practice Question
Which command forwards local port 8080 to port 80 of a pod named 'web-pod'?
⚠ Common exam trap
Test-takers frequently confuse `kubectl port-forward` with `kubectl expose` or `kubectl proxy`, mistakenly thinking that creating a Service or a proxy is the correct way to forward a local port to a specific pod, when in fact `port-forward` is the only command that creates a direct local-to-pod tunnel.
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
✓
kubectl port-forward pod/web-pod 8080:80
`kubectl port-forward` creates a direct tunnel from a local port to a specified port on a pod, allowing access to the pod's service without exposing it externally. The syntax `pod/web-pod 8080:80` forwards localhost:8080 to port 80 of the pod named 'web-pod'.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
kubectl exec -it web-pod -- nc -l -p 8080
Why it's wrong here
kubectl exec runs a one-off command inside the container; here it launches netcat as a listening process in the pod's network namespace, so any port 8080 binding exists only inside that container. It does not allocate a localhost port on your workstation, nor does it map 8080 to the pod's port 80, and the connection is interactive rather than a persistent tunnel. This is why it fails to provide port forwarding.
- ✗
kubectl proxy --port=8080
Why it's wrong here
kubectl proxy starts an HTTP proxy server on localhost:8080 that fronts the Kubernetes API server, not a specific pod endpoint. To reach an individual pod you would need to craft API proxy URLs and authenticate, and raw TCP traffic to port 80 is not supported. It therefore changes what is listening locally but does not forward local port 8080 to the web-pod's port 80.
- ✗
kubectl expose pod web-pod --port=8080 --target-port=80
Why it's wrong here
kubectl expose creates a Service resource that load balances or routes to the selected pod on cluster-internal virtual IPs. While it maps service port 8080 to target port 80, nothing is opened on your local machine; you would still need kubectl port-forward, a NodePort, or an ingress to reach it from outside the cluster. Thus it configures cluster networking rather than performing a local-to-pod port forward.
- ✓
kubectl port-forward pod/web-pod 8080:80
Why this is correct
kubectl port-forward pod/web-pod 8080:80 creates a direct TCP tunnel from your localhost:8080 to port 80 inside web-pod via the Kubernetes API server. The pod/<name> resource identifier and the local:remote port pair are the correct port-forward syntax, and this is the intended command for one-off debugging access. It keeps running until interrupted.
Go deeper
Related to this question
About these practice questions
Courseiva writes every CKA question from scratch — 302 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. 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.