Kubectl Port-Forward and Proxy
Reach private services and the API server from your laptop.
- port-forward
- kubectl proxy
- debug database
- api server
- local access
Kubectl Port-Forward and Proxy
Reach private services and the API server from your laptop.
Commands
| Command | What it does |
|---|---|
kubectl port-forward deploy/api 8080:8080 | Pods behind a deployment |
kubectl port-forward svc/pg 5432:5432 | Database via its service |
kubectl proxy | Local proxy to the API server |
curl localhost:8001/api/v1/namespaces/default/pods | API through the proxy |
Example
kubectl port-forward svc/pg 5432:5432 -n shop &
psql -h localhost -U app shop
kill %1
FAQ
Is port-forward production traffic?
No — single-user debugging only; use Ingress or Gateway for real traffic.
Why does port-forward drop?
Idle timeouts or pod restarts; wrap it in a retry loop for long debug sessions.
常見問題
Is port-forward production traffic?
No — single-user debugging only; use Ingress or Gateway for real traffic.
Why does port-forward drop?
Idle timeouts or pod restarts; wrap it in a retry loop for long debug sessions.
Kubernetes
Kubectl Config and Context
Point kubectl at the right cluster and switch contexts safely.
Kubectl Pods
Inspect pods, describe failures, and get a shell inside.
Kubectl Deployments
Create, update, and inspect Deployments that own your pods.
Kubectl Services
Expose pods stably with ClusterIP, NodePort, and LoadBalancer.