After you point vmc to a specific Cloud Foundry target, typing vmc services will show you the available services. For example, after targeting http://api.cloudfoundry.com, vmc services will show the following.
During the deployment, Cloud Foundry asks if you want to bind the application to any of the services. Once you choose a specific service, it can be accessed during the runtime through the VCAP_SERVICES environment variable. But many times, developers need to access the services like MySQL, PostgreSQL and MongoDB directly to manage the database. This is where Cloud Foundry tunneling comes into the picture. In this tutorial, we will access MySQL from the local machine through the popular MySQL Workbench.
First, let us make sure that the MySQL data service is provisioned for us. We can check this by typing vmc services and looking under the provisioned services.
Now, let’s install the Caldecott gem to enable tunneling. Caldecott is a simple Ruby gem that enables port forwarding on the local machine.
gem install caldecott
With Caldecott in place, it’s time for us to create the tunnel. We do this by typing vmc tunnel.
Note that this command shows the provisioned services. After we select that, the next step is to choose the mysql tool that can be invoked directly by the tool.
If the mysql command line is in path, choosing option 2 will launch it with appropriate parameters. But by choosing 1, we will able to use any tool that can connect to MySQL In this case, we will use MySQL Workbench.
Launch MySQL Workbench and click on New Server Instance under Server Administration.
Select Remote Host and enter 127.0.0.1. Do not enter the port number at this point.
In the next step, enter the port number that vmc tunnel has shown followed by the username and password.
Click continue to see the confirmation.
Finally, double clicking on the server will launch the query editor.
Now, you can run queries and perform any operations on the database provisioned at CloudFoundry.com.
- Janakiram MSV, Chief Editor, CloudStory.in