A simple feature that simplifies life on day #10. Exposing pods’ ports locally
Port forwarding as the name suggests forwards the port from your pod to localhost. You can expose multiple ports locally.
Forwarding from 127.0.0.1:9021 -> 8080
Forwarding from [::1]:9021 -> 8080
Handling connection for 902
The command above forwards to local port 9021 the pod’s port 8080. In your browser you can now just go to localhost:9021 to check out the application’s page.
This pod does not expose any other ports, so there is nothing more to forward. When using Java based pods, you can additionally expose a JMX and/or debugging port. Forwarding the debugging port to your local machine simplifies the debugging process. When restarting pods, you can always forward ports from new pod to the same ports locally and bind your local tools to always attach to the same ports.
Just a bit more about the syntax to expose multiple ports.
Will listen locally on ports 9021 and 9022.
There are no more options available in port-forward command. It does just this little thing.
The commands were executed using minishift and the following client/server versions of OpenShift.
Thanks for reading the OpenShift morsels. To get updates about new articles, you can sign up to the newsletter below.
As a thank you message, you will also get access to OpenShift CLI CheatSheet listing most commonly used commands together with a short explanation.