Getting Started with Port Forwarding on OpenShift - Archived

When developing database driven applications, it is essential that you have access to connect to your database in both your development and production environments.  Doing this without opening yourself up to security concerns is often a place where developers that are not intimately familiar with system administration and firewall configuration may stumble.

Enter OpenShift PaaS and yet another feature that will help you focus more on your code and less on system management duties.  With OpenShift port forwarding, developers are now able to connect to their remote services while using local client tools without having to worry about the details of configuring complicated firewall rules.

If you want to watch a video demonstrating how to use port forwarding on OpenShift, check out this video.


Step 1
In order to take full advantage of the “rhc port-forward” tool, make sure that you have the latest version of the client tools.  On systems with the client tools installed via ruby gem, enter the following command:
$ sudo gem update rhc

If you are using an rpm based installation, perform the following command:
$ sudo yum update rhc

Step 2

Now that you have the latest client tools installed, you should have access to the “rhc port-forward” command.  Once the command is invoked, the client tools will scan your deployed application and look for any embedded services available to forward.  The client tools will then configure your local system to be able to connect to the available services for your remote application.
$ rhc port-forward -a applicationName

Once the command is issued, you should see a list of services that are being forwarded and the associated ip address and port to use for connections.

In the above screenshot, you can see that I am forwarding a mysql database that has been embedded in my application named ‘port’.

Note:  At the time of this writing, there is an extra step to enable port forwarding on MacOS based systems.  You will need to create an alias on your loopback device for the IP address of your OpenShift server.  In the example above, my IP address is  Given that, I would issue the following command at a terminal prompt:
$ sudo ifconfig lo0 alias

This should be resolved in a future update to the rhc client tools but you can use the above workaround in the meantime.

Step 3

Now that you have your services forward, you can connect to them using your local client tools.  For instance, the connect to the mysql databases that I forwarded in step 2, I would enter the following command:
$ mysql -uadmin -p -h

The mysql client will then prompt me for the admin password and will then connect me to my mysql database running on my OpenShift server.

Note: The database username and password are displayed once you embed the service into your application.  It is always good practice to make a note of these.

News, OpenShift Origin
Comments are closed.