How do you port-forward to a pod with kubectl?
kubectl port-forward [pod] 8080:80 — Port forward
kubectl port-forward [pod] 8080:80 maps local port 8080 to port 80 inside the pod, so http://localhost:8080 reaches the container while the command runs. The first number is the local port, the second is the pod port.
Related Kubernetes (kubectl) shortcuts: Manage Resources
| Shortcut | Action | Notes |
|---|---|---|
| kubectl apply -f [file] | Apply resource | Create/update resources from YAML. |
| kubectl delete pod [name] | Delete pod | Delete a pod. |
| kubectl scale deploy [name] --replicas=3 | Scale | Change deployment replica count. |
| kubectl exec -it [pod] -- bash | Enter pod | Open bash shell inside a pod. |
| kubectl port-forward [pod] 8080:80 | Port forward | Forward local port to pod port. |
| kubectl rollout restart deploy [name] | Rolling restart | Rolling restart a deployment. |
From the Kubernetes (kubectl) reference (17 entries) · all how-to answers