port-forward
What is port-forward?
port-forward: Tunnel a local port to a Pod or Service port. Lets you hit an internal service from your laptop without exposing it. kubectl port-forward creates a tunnel from a port on your computer to a pod or service in the cluster. kubectl port-forward svc/mysql 3307:3306 lets you connect a local database tool to the cluster's database on localhost:3307.
Frequently asked questions about port-forward
How is port-forward used in practice?
It is ideal for debugging and admin tasks. You can reach internal services that are deliberately not exposed to the internet, without changing any configuration.
What should you keep in mind with port-forward?
The tunnel lives only as long as the command runs, and it goes through the Kubernetes API, so it is not meant for production traffic or heavy data transfers. Be careful when connected to production this way, because your local tools now act directly on live data. A clear terminal title or a different port number for production helps avoid running a test query on the wrong database.
What does an example of port-forward look like?
kubectl port-forward svc/web 8080:80 At a glance
| Category | Kubernetes |
|---|---|
| Explained by | Reinier de la Parra |
| Updated |