liveBook · Manning

Port forwarding

As explained in Google Anthos in Action

Port forwarding is a networking technique that maps a port on one system to a port on another service or system.

Port forwarding exposes a service running in a Kubernetes cluster through a port on the local machine, enabling local application previews. In a minikube workflow, a service can be forwarded to localhost even after being exposed as a NodePort. section 12.3.1

A local preview workflow typically:

  • Starts minikube and creates a Deployment. section 12.3.1
  • Exposes the Deployment through a NodePort service and verifies the service. section 12.3.1
  • Forwards service port 8080 to local port 8080, then opens http://localhost:8080. section 12.3.1
  • Uses Skaffold to include port forwarding as part of a broader development pipeline alongside deployment, file synchronization, log tailing, and cleanup. section 12.3.2

Forward a minikube service

After creating and exposing the hello-minikube Deployment, run `kubectl port-forward service/hello-minikube 8080:8080`. The command forwards localhost port 8080 to the service and reports listeners on 127.0.0.1 and ::1. section 12.3.1

kubectl port-forward service/hello-minikube 8080:8080
Forwarding from 127.0.0.1:8080 -> 8080
Forwarding from [::1]:8080 -> 8080

Use the command listing to inspect the exact kubectl syntax and forwarding output. section 12.3.1

How Google Anthos in Action covers it

How deep it goes
Shows the service-level kubectl command and local result, then places forwarding within Skaffold’s development pipeline.
Examples
Uses the hello-minikube Deployment, NodePort service, port 8080, and browser access at localhost.
What it assumes
Assumes a running Kubernetes cluster, a deployed application, and an exposed service; minikube setup is demonstrated.
What you can do after
Apply it via kubectl or Skaffold to preview a Kubernetes service from a local browser.
How it connects
Connects Kubernetes services, NodePort, minikube, localhost, kubectl, and Skaffold.

Also explained in

Compare how 5 books explain port forwarding →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Google Anthos in Action. The section links point to the parts of the book it draws on.