0
0
Kubernetesdevops~5 mins

kubectl port-forward for local access in Kubernetes - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the kubectl port-forward command do?
It forwards a port from a local machine to a port on a Kubernetes pod, allowing local access to the pod's service without exposing it externally.
Click to reveal answer
beginner
How do you forward local port 8080 to port 80 on a pod named my-pod?
Use the command: kubectl port-forward pod/my-pod 8080:80
Click to reveal answer
beginner
Can kubectl port-forward be used to access services inside a Kubernetes cluster without exposing them externally?
Yes, it allows local access to pods or services without changing cluster network settings or exposing services outside the cluster.
Click to reveal answer
intermediate
What is the syntax to forward a local port to a service instead of a pod?
Use: kubectl port-forward service/ :
Click to reveal answer
intermediate
Why might you use kubectl port-forward instead of exposing a service with a LoadBalancer?
Because it is quick, requires no cluster changes, and is safer for temporary access without exposing the service to the internet.
Click to reveal answer
What is the correct command to forward local port 3000 to port 80 on a pod named web-pod?
Akubectl port-forward pod/web-pod 3000:80
Bkubectl forward-port pod/web-pod 80:3000
Ckubectl port-forward service/web-pod 80:3000
Dkubectl expose pod/web-pod 3000:80
Which resource types can kubectl port-forward forward ports to?
APods and Services
BOnly Pods
COnly Services
DNodes
What happens if you close the terminal running kubectl port-forward?
AThe pod restarts
BThe port forwarding continues in the background
CThe port forwarding stops immediately
DThe service is exposed externally
Why is kubectl port-forward considered secure for local testing?
AIt encrypts all traffic automatically
BIt does not expose ports outside the local machine
CIt requires a VPN connection
DIt changes pod firewall rules
Which of these is NOT a valid use of kubectl port-forward?
ATesting an internal API without cluster changes
BDebugging a database inside the cluster
CAccessing a pod's web server locally
DExposing a service to the internet permanently
Explain how kubectl port-forward helps you access a Kubernetes pod locally without exposing it externally.
Think about how you connect your computer to a service inside the cluster safely.
You got /4 concepts.
    Describe the steps and command syntax to forward local port 5000 to port 5000 on a service named my-service.
    Remember the resource type and port mapping format.
    You got /4 concepts.