This article describes the process of setting up a VM running OpenShift development environment inside VirtualBox on Windows 7. The article was inspired by the “OpenShift Origin Virtual Machine Deployment Guide“, it borrows some information from the guide but concentrates on Windows 7 as a host and development machine and addresses various issues that a Windows developer may come across (and not covered by the original guide).
I am going to dwell on the following aspects:
- Setting up the Virtual Machine
- Network configuration
- Accessing the Virtual Machine
- Accessing deployed application from the Windows host
- Using RHC tools with multiple servers
- Port forwarding
- Accessing deployed databases from host machine
Setting up the Virtual Machine
Download the VM from the OpenShift “mirrors” site (about 1.3 GB):
Unpack the package with your favorite .zip manager. This can take quite a while. The result will be the creation of four additional files (file sizes may vary):
Create New VM
You are going to create a new Linux machine with Fedora (64 bit)
Set VM Memory Size
Set the memory size to something reasonably large. 1 GB should be a good start. Later on you can give your machine more memory depending on cartridges used.
Select VM “Hard Drive” Image
For this step you will need to select the virtual disk image (you’ve unpacked earlier) which contains the OpenShift Origin virtual machine.
By default VirtualBox uses Network Address Translation (NAT) to create a virtual network interface for your virtual machines. NAT will not let you connect back into your virtual machine. You need to change the network adapter configuration to use Bridged networking. Then you virtual machine will get an IP address from your DHCP server, and you will be able to use that address to browse or log in.
Each system may have different names for the network adapter. Find yours in the pulldown menu labeled “Name”. Select it and press the OK button. You’ll return to the main display ready to start the VM.
When the VM has completed booting VirtualBox will display the access information for the VM and prompt you to start a root console.
Please remember the IP address VM has obtained (i.e. 192.168.1.103) as you will need it in order to access OpenShift Console. More details on IP/URL address configuration and will be given later in this article.
Accessing the Virtual Machine
When VM is running it is accessible from the host machine either using OpenShift console via a web browser or on a command line interface using SSH. The web interface is useful for easily managing applications while the CLI allows developers to write and test applications and components. The web browser will also be used to verify the test applications during development.
There are two user accounts which are used to access the OpenShift Origin VM. Both are displayed on the VM console when it boots as shown in the examples above.
The first one is the OpenShift service account. This is used to access the web console and run the rhc CLI commands as a developer.
- Username: admin
- Password: admin
The second account is the developer account. This is a UNIX account which is used to log into the OpenShift VM via SSH. It provides a work space for exploring the CLI and development environment of OpenShift Origin.
- Username: openshift
- Password: openshift
If you try logging in with one or those and it fails, try using the other.
Using a browser to view the OpenShift Console
When the VM is running you can use the OpenShift console to create and manage applications in the VM. Navigate your browser to the IP address the VM machine has automatically received during boot (i.e. http://192.168.1.103). Enter the username and password (admin/admin) when prompted.
Using SSH to log into the VM
Most of the OpenShift workflow for application development is done from the command line. The OpenShift VM has account created and populated with the tools needed to create, manage and develop apps for demonstration purposes.
Developers may reach the command line on the VM using SSH from the host. The easiest way of using SSH on Windows machines is by Git for Windows bash.
At this point you are going to use IP address of the Virtual Machine for SSH access. When prompted for the password use ‘openshift’ one.
Accessing deployed application from the Windows host
For demonstration purposes I have created a basic ‘Node.js 0.10’ application named ‘Test01‘ having namespace ‘dvuyka‘ like shown below
When application is created you will see an entry within ‘My Applications’ area with a URL having the following format:
However by default on Windows hosts you won’t be able accessing your application with the browser because of DNS resolving. The easiest and quickest way solving this issue would be changing the hosts file and providing required addresses explicitly. This will allow saving time on DNS server configuration especially when working offline or with isolated environment.
Setting up hosts
For more information on modifying ‘hosts’ file on Windows please refer to the following article:
How do I modify my hots file?
You will need at least 3 entries to be explicitly declared, 2 for OpenShift environment and 1 for your application:
Typically you will need mapping every application endpoint to be accessible. There is no need rebooting Windows after making change to ‘hosts’ file.
Now you should be able accessing OpenShift Console via https://openshift.local address
Clicking the application URL will now allow you accessing deployed application from within your Windows host browser:
Using SSH to log into VM
At this point it should be possible using broker.openshift.local address with SSH connections:
Configuring static IP address for VM (optional)
The only problem with ‘hosts’ file approach mentioned above is DHCP configuration. After reboot the OpenShift Origin Virtual Machine make obtain different IP address from DHCP server and all host mappings won’t be working. In order to solve this issue developers may want providing a static for VM to ensure IP address is always the same.
I will be using ‘nano’ editor for the sake of simplicity
sudo yum install nano
You will need to change the BOOTPROTO value from dhcp to static and providing explicit values for IPADDR, NETMASK, NETWORK and GATEWAY depending on your network/router configurations
As soon as you have finished editing the file press “Ctrl+O, Enter” to save the file and “Ctrl+X” to exit. Server needs to be rebooted after that.
Now as per configuration above my VM will always be starting with 192.168.1.103 address.
Using RHC tools with multiple servers
It is possible switching between different servers with RHC tools. Having multiple server configurations allow working with both local and remote environments. In order to create new configuration for your OpenShift Origin VM you will need executing the following commands with Windows command prompt:
rhc setup --server openshift.local
This will RHC tools creating additional configuration called “origin” pointing to your “openshift.local” VM
In order to use “origin” server configuration the “OPENSHIFT_CONFIG” environment variable should be defined before invoking RHC tools next time:
Configuring RHC tools with OpenShift Origin VM will allow using Port Forwarding and accessing your applications and databases from within Windows host.
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.
For more details on port forwarding feature please refer to the following article:
Getting Started with Port Forwarding on OpenShift
Accessing deployed application from Windows host
With Windows (or Visual Studio) command prompt you can setup port forwarding to your VM
rhc port-forward -a test01
While command prompt is running the deployed application can be accessed via local loopback address: http://127.0.0.1:8080
Accessing deployed database from Windows host (MongoDB)
When port forwarding is started RHC tools automatically detect all ports to be wired. That applies to database cartridges as well. Examples below will be based on ‘MongoDB’ cartridge.
Add database cartridge
In the OpenShift web console navigate to your ‘Test01’ application and add ‘MongoDB NoSQL Database 2.2’ cartridge
Don’t forget to write down credentials somewhere as OpenShift Console does not expose them after cartridge is created.
You can get more details on OpenShift support for MongoDB here:
MongoDB on OpenShift
Start port forwarding
Once database cartridge is added you can start port forwarding with Windows or Visual Studio command prompt
rhc port-forward -a test01
You should see multiple ports now:
Connect to database
In order to connect to Mongo database I will be using Robomongo for Windows.
For the authentication section please use credentials you got after having created MongoDB cartridge
It is now possible working with your MongoDB database directly from Windows host
Using Git publishing with VM
There are no specific steps required to enable Git support for OpenShift Origin VM once the Windows environment is configured.
Please refer to the following articles if you want getting more information about Git in the scope of OpenShift
Deploying and building your applications
Accessing your code for your OpenShift Application via Windows Explorer using TortoiseGit
Authentication and SSH Keys
The steps above allow a developer to download and run a self-contained OpenShift service for development or demonstration purposes. The service runs in a VirtualBox virtual machine and is accessible to the user on the host machine running Windows 7 and is accessible to the developer by means of VirtualBox graphical console, by SSH or with a local web browser to access the OpenShift console and/or any applications that are created within the OpenShift service.