0
0
Kubernetesdevops~20 mins

kubectl port-forward for local access in Kubernetes - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Port-Forward Pro
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
Output of kubectl port-forward command

What is the output when you run kubectl port-forward pod/myapp-pod 8080:80 successfully?

Kubernetes
kubectl port-forward pod/myapp-pod 8080:80
AConnection refused: unable to forward port
BError from server (NotFound): pods "myapp-pod" not found
CPort 80 is already in use on localhost
D
Forwarding from 127.0.0.1:8080 -> 80
Forwarding from [::1]:8080 -> 80
Attempts:
2 left
💡 Hint

Successful port-forward shows the local and IPv6 forwarding lines.

🧠 Conceptual
intermediate
1:30remaining
Purpose of kubectl port-forward

What is the main purpose of using kubectl port-forward in Kubernetes?

ATo permanently expose a pod to external traffic
BTo expose a pod's port locally without creating a service
CTo scale the number of pod replicas
DTo update the pod's container image
Attempts:
2 left
💡 Hint

Think about temporary local access to pod ports.

Troubleshoot
advanced
2:30remaining
Troubleshooting port-forward connection refused error

You run kubectl port-forward pod/myapp-pod 8080:80 but get error: unable to forward port because connection refused. What is the most likely cause?

Akubectl is not installed on your machine
BThe local port 8080 is already in use by another process
CThe pod is not running or the container port 80 is not open
DThe Kubernetes API server is down
Attempts:
2 left
💡 Hint

Check pod status and container ports.

🔀 Workflow
advanced
2:00remaining
Correct kubectl port-forward command for service

You want to access port 5432 of a PostgreSQL service named db-service locally on port 15432. Which command is correct?

Akubectl port-forward svc/db-service 15432:5432
Bkubectl port-forward pod/db-service 15432:5432
Ckubectl expose svc/db-service --port=15432 --target-port=5432
Dkubectl forward-port svc/db-service 5432:15432
Attempts:
2 left
💡 Hint

Remember to specify the resource type and correct port mapping.

Best Practice
expert
3:00remaining
Best practice for secure kubectl port-forward usage

Which practice helps keep your local system secure when using kubectl port-forward?

AUse port-forward only on localhost and avoid exposing it to public networks
BAlways forward ports to 0.0.0.0 to allow all network access
CRun port-forward with root privileges to avoid permission issues
DDisable firewall to ensure port-forward connections succeed
Attempts:
2 left
💡 Hint

Think about limiting network exposure.