Port forwarding redirects traffic arriving at one port to a designated port on another endpoint. It can make a containerized service available on a development computer or provide local access to a service inside a Kubernetes cluster. section 3.8.3 section 11.3.2
For a Docker container, use -p to bind a host port to a container port. The service must also be configured to listen on the container port. In this example, PORT=3000 configures the microservice, while -p 3000:3000 forwards host traffic to it. section 3.8.3
cd chapter-3/example-1 docker run -d -p 3000:3000 -e PORT=3000 video-streaming
Run the video-streaming image in the background with host port 3000 mapped to container port 3000. section 3.8.3
If the host port is already allocated, stop the other application or choose another port. Use docker container list to check the running container and its port mapping. section 3.8.3 section 3.8.3
For a Kubernetes microservice accessible only inside the cluster, kubectl port-forward provides local access for testing without exposing the service to the outside world. The following command forwards localhost:6000 to port 80 on the named pod while the command is running. section 11.3.2
kubectl port-forward metadata-55bb6bdf58-7pjn2 6000:80
Forward local port 6000 to port 80 on the metadata pod, then send requests to http://localhost:6000. section 11.3.2
The general form is kubectl port-forward <pod-name> [<local-port>:]<pod-port>. The same technique can reach a third-party service such as a RabbitMQ dashboard. Take care when inspecting a customer-facing system. section 11.3.2




