Bartosz Bierkowski - Low dose cloud

OpenShift Morsels: oc port-forward – troubleshooting your application

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.

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.

Environment

The commands were executed using minishift and the following client/server versions of OpenShift.

Client:
oc v3.6.1+008f2d5
client kubernetes v1.6.1+5115d708d7
Server:
openshift v3.6.0+c4dd4cf
server kubernetes v1.6.1+5115d708d7

Newsletter

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.

Did you like the article?
Join the newsletter to receive notifications about new articles.
I respect your privacy.