kubectl port-forward tunnels a local port to a port on a Pod for debugging
Answer: kubectl port-forward TARGET LOCAL:REMOTE forwards a local port to a port on a Pod. The target can be a pod, or a deployment, replicaset or service that selects a matching pod. It is useful for database debugging.
Examples
kubectl port-forward pods/mongo-75f59d57f4-4nd6q 28015:27017
kubectl port-forward deployment/mongo 28015:27017
kubectl port-forward service/mongo 28015:27017
kubectl port-forward deployment/mongo :27017
kubectl port-forward pod/mypod 5000 6000
kubectl port-forward service/myservice 8443:https
kubectl port-forward --address 0.0.0.0 pod/mypod 8888:5000
What to expect
- The output is similar to
Forwarding from 127.0.0.1:28015 -> 27017. Connections made to local port 28015 are forwarded to port 27017 of the Pod. kubectl port-forwarddoes not return. Open another terminal to keep working.- With
:27017, the tool finds a local port number that is not in use, avoiding low port numbers, which relieves you from managing local port conflicts. pod/mypod 5000 6000listens on ports 5000 and 6000 locally and forwards data to/from the same ports in the pod.service/myservice 8443:httpsforwards to a pod selected by the service, using the targetPort of its port named "https".- By default it listens on localhost;
--address 0.0.0.0listens on all addresses.
See also
Claims
- id: C1 claim: port-forward can select a pod by resource name such as a deployment. source: S1 evidence: "allows using resource name, such as a pod name, to select a matching pod"
- id: C2 claim: kubectl port-forward does not return. source: S1 evidence: "kubectl port-forward does not return."
- id: C3 claim: Omitting the local port lets kubectl pick an unused one. source: S1 evidence: "finds a local port number that is not in use"
- id: C4 claim: --address 0.0.0.0 listens on all addresses. source: S2 evidence: "Listen on port 8888 on all addresses, forwarding to 5000 in the pod"
Sources
- [S1] Use Port Forwarding to Access Applications in a Cluster. Kubernetes docs. https://kubernetes.io/docs/tasks/access-application-cluster/port-forward-access-application-cluster/ . License: CC-BY-4.0. Accessed 2026-11-18.
- [S2] kubectl port-forward (source page). kubernetes/website (GitHub). https://github.com/kubernetes/website/blob/main/content/en/docs/reference/kubectl/generated/kubectl_port-forward/_index.md . License: CC-BY-4.0. Accessed 2026-11-18.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Kubernetes docs, Use Port Forwarding to Access Applications in a Cluster; kubernetes/website (GitHub), kubectl port-forward (source page). CC-BY-4.0 (https://raw.githubusercontent.com/kubernetes/website/main/LICENSE). Copyright The Kubernetes Authors. Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Kubernetes docs, Use Port Forwarding to Access Applications in a Cluster; kubernetes/website (GitHub), kubectl port-forward (source page). CC-BY-4.0 (https://raw.githubusercontent.com/kubernetes/website/main/LICENSE). Copyright The Kubernetes Authors.
Cite this
iinventedlight. 2026. "kubectl port-forward tunnels a local port to a port on a Pod for debugging." iinventedlight Library, iil:note:7904bhxq, version of 2026-11-18. https://iinventedlight.com/library/notes/kubernetes-port-forward/. License: CC-BY-4.0.
@misc{iil_note_7904bhxq,
author = {{iinventedlight}},
title = {{kubectl port-forward tunnels a local port to a port on a Pod for debugging}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-18},
url = {https://iinventedlight.com/library/notes/kubernetes-port-forward/},
note = {Permanent ID iil:note:7904bhxq. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).
Extra files beside this note
These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.
- kubernetes-port-forward.table.json (table; CC-BY-4.0)
- kubernetes-port-forward.schema.json (schema; CC-BY-4.0)
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/kubernetes-port-forward.md.