kubectl Port Forward¶
Introduction¶
This guide explains kubectl port forward with practical kubectl commands, realistic output, and production-focused checks. The examples focus on commands you can run during daily cluster administration and incident response.
When to Use This Command¶
Use it when you need to inspect, change, or verify Kubernetes resources without guessing. Prefer namespace-scoped commands unless you intentionally need cluster-wide output.
Basic Syntax¶
kubectl get svc,endpoints -A
Practical Examples¶
kubectl get svc,endpoints -A
kubectl describe svc web -n app
kubectl get ingress -A
kubectl run curl --rm -it --image=curlimages/curl --restart=Never -- curl -I http://web.app.svc.cluster.local
kubectl get events -n app --sort-by=.lastTimestamp
Example output:
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/web ClusterIP 10.96.42.10 <none> 80/TCP 2d
Useful Options¶
- Use
-n <namespace>to avoid checking the wrong namespace. - Use
-o wide,-o yaml, or-o jsonwhen default columns are not enough. - Use label selectors for application-focused output.
Verification¶
kubectl get events -n app --sort-by=.lastTimestamp
kubectl get all -n app
Common Mistakes¶
- Running commands in the wrong context or namespace.
- Editing live resources without saving the manifest in version control.
- Ignoring events because the first kubectl output looks normal.
Production Tips¶
Check the current context before making changes, use dry-run where supported, and prefer declarative manifests for repeatable changes.
Related Guides¶
- kubectl Troubleshooting Cheat Sheet
- kubectl Logs Examples
- kubectl Describe Pod
- kubectl Events Troubleshooting
Summary¶
Good kubectl usage is precise: choose the right context, namespace, output format, and verification command before changing production workloads.