debug
kubectl proxy
Runs a local HTTP proxy that authenticates as your kubeconfig user and forwards requests to the Kubernetes API server. Useful for exploring the raw API with curl or serving the dashboard behind localhost auth.
kubectl proxy [--port=PORT] [--address=IP] [--www=DIR] [flags] Common flags
| Flag | Purpose |
|---|---|
| -p, --port | Local port to listen on (default 8001; 0 picks a random free port). |
| --address | Local address to bind (default 127.0.0.1). |
| --accept-hosts | Regex of Host headers the proxy will accept. |
| --api-prefix | Prefix to serve the API under (default /). |
| --www | Serve static content from this directory alongside the API. |
| --disable-filter | Disable request filtering (risky - allows non-local hosts). |
Examples
kubectl proxy --port=8001 Reach the API at http://localhost:8001/api/v1/...
curl http://localhost:8001/api/v1/namespaces/default/pods List pods via the raw REST API through the proxy.
kubectl proxy --www=./dashboard --www-prefix=/ui/ Serve static files at /ui/ alongside the API.
Gotcha
Anyone who can reach the local port inherits your cluster credentials - never bind to 0.0.0.0 unless you know what you are doing.
Related commands
kubectl port-forward
Forwards one or more local ports to a pod, service, or deployment inside the cluster via the API server. Ideal for reaching internal services (databases, admin UIs) from your laptop without exposing them publicly.
kubectl cluster-info
Prints the endpoints of the control-plane services for the current context. The dump subcommand collects a large diagnostic bundle of cluster state for offline analysis.
kubectl config
Reads and modifies kubeconfig files that define clusters, users, and contexts. It is how you switch between clusters, change the active namespace, and register new credentials.
kubectl logs
Prints container logs from a pod, deployment, or other workload. Supports streaming, previous-instance recovery after crashes, and selecting a specific container in multi-container pods.
kubectl exec
Executes a command inside a running container. Use -it for an interactive TTY shell; omit them for a one-shot command whose stdout you want to capture for scripts.