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

CommandWhat it does
kubectl port-forward deploy/api 8080:8080Pods behind a deployment
kubectl port-forward svc/pg 5432:5432Database via its service
kubectl proxyLocal proxy to the API server
curl localhost:8001/api/v1/namespaces/default/podsAPI 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.

Întrebări frecvente

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