kubectl port-forward sends traffic from a local machine into a port on a Kubernetes Pod. It provides a quick way to test or debug an HTTP application, including one running in a remote cluster. section 15.2
Forward traffic to a Pod
After deploying the numbers-api Pod, run `kubectl port-forward pod/numbers-api 8015:80`. Browse to `http://localhost:8015/rng` to reach the Pod's port 80 through local port 8015. Stop forwarding with Ctrl-C or Cmd-C. section 15.2
Use port forwarding for:
- Local testing of a Pod that is not directly reachable from outside the cluster. section 15.2
- Debugging an application in a cloud-hosted Kubernetes cluster through the local machine. section 15.2
- Temporary access rather than public exposure; use a Kubernetes Service for incoming application traffic. section 15.2
# deploy the application: kubectl apply -f ch15/exercises/numbers-api/pod.yaml # list Pods, showing the labels: kubectl get pods --show-labels # print human-friendly details about the Pod: kubectl describe pod numbers-api # set kubectl to listen on port 8015 # and relay traffic to the Pod on port 80: kubectl port-forward pod/numbers-api 8015:80 # now browse to http:/./localhost:8015/rng # Ctrl-C or Cmd-C to exit the port-forward
Shows the deployment, inspection, port-forward command, local URL, and exit instruction in one runnable sequence. section 15.2

