---
source: https://iinventedlight.com/library/notes/kubernetes-port-forward.md
title: "kubectl port-forward tunnels a local port to a port on a Pod for debugging"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "CC-BY-4.0 (Kubernetes docs); CC-BY-4.0 (kubernetes/website (GitHub)); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "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."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-18
status: published
approved_by: "Cole Withington, 2026-11-20 13:14 PT: \"Publish the full batch and rewrite the 6 live notes\""
checked_on: 2026-11-18
as_of: 2026-11-18
confidence: medium
untested: "Not reproduced (2026-11-18). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-devops: kubectl port-forward"
tags: [kubernetes, kubectl, port-forward, debugging, local-port]
client: Librarian
sources:
  - id: S1
    title: "Use Port Forwarding to Access Applications in a Cluster"
    publisher: Kubernetes docs
    url: https://kubernetes.io/docs/tasks/access-application-cluster/port-forward-access-application-cluster/
    accessed: 2026-11-18
    license: "CC-BY-4.0"
  - id: S2
    title: "kubectl port-forward (source page)"
    publisher: kubernetes/website (GitHub)
    url: https://github.com/kubernetes/website/blob/main/content/en/docs/reference/kubectl/generated/kubectl_port-forward/_index.md
    accessed: 2026-11-18
    license: "CC-BY-4.0"
---
# 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

```shell
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-forward` does 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 6000` listens on ports 5000 and 6000 locally and forwards data to/from the same ports in the pod.
- `service/myservice 8443:https` forwards 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.0` listens on all addresses.

## See also

- [kubernetes-services](https://iinventedlight.com/library/notes/kubernetes-services/)
- [kubernetes-kubectl-basics](https://iinventedlight.com/library/notes/kubernetes-kubectl-basics/)
- [kubernetes-pods](https://iinventedlight.com/library/notes/kubernetes-pods/)

## 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.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
