Geekery of all stripes

Intro to Cloud Foundry and Bosh Part 3

· David Bishop

For the third (and probably final) part of this series, we’re going to setup a MySQL database and make it available on our Cloud Foundry instance as a service that webapps can use. After all, being able to push webapps to CF is neat, but without a database backend, it’s not really super useful. And we’re going with MySQL instead of something like PostgreSQL because, well, that’s what I got working first.

To make this easy, we’re going to use BOSH to provision the MySQL VM. And because I love standing on the shoulders of giants, we’re going to use a premade BOSH release. So, step one is to clone https://github.com/cloudfoundry/cf-mysql-release into ~/workspace/. Note - unless you want to dig around and edit some scripts later, you do have to have that in ~/workspace/cf-mysql-release/. I’ll be proceeding under that assumption.

I mentioned this in a previous article, but one of the things that BOSH uses is templates of virtual machines, called “stemcells”. The stemcells can be turned into a running VM of any stripe - database, webserver, what have you. And the stemcells can be based off of any given linux distribution - ubuntu, CentOS, whatever. But a given BOSH release might depend (or at least only be “guaranteed” to work with) a specific stemcell. Seeing as BOSH will be doing things like installing packages and compiling software, that makes sense. Compiling MySQL 5.5 on Ubuntu 12.1 is a very different proposition from doing the same thing on Centos 6.5. Each stemcell is also specific to a given virtual machine provider (or “CPI” - Cloud Provider Interface, in BOSH terminology). A stemcell that can be used with Amazon’s AWS is different than one that works with VMWare’s ESX or Xen. CPI’s differ in terms of what type of filesystem images they accept, among other things. In this case, we’re going to be getting a stemcell of a Ubuntu “Trusty” that’s configured to work with VMware’s Vsphere (and by not-a-coincidence, will also work with VirtualBox). To read more about the details of uploading stemcells and all that entails, checkout (this link)[http://docs.cloudfoundry.org/deploying/openstack/uploading_bosh_stemcell.html], but while you’re doing that run the following:

bosh upload stemcell https://s3.amazonaws.com/bosh-jenkins-artifacts/bosh-stemcell/vsphere/bosh-stemcell-2719.3-vsphere-esxi-ubuntu-trusty-go_agent.tgz

Now we’re going to go into the cf-mysql-release directory and run the following commands:

./update
bosh upload release releases/cf-mysql-16.yml
./bosh-lite/make_manifest_spiff_mysql
bosh deploy

This whole process will take a while, depending on the size of your computer. On a fairly recent MacBook Pro, it took around 15 minutes.

rule.json (ip of the haproxy vm in the cf-warden-mysql deployment, as per bosh vms): [ { “destination”: “10.244.1.18”, “protocol”: “all” } ]

cf create-security-group p-mysql rule.json cf bind-running-security-group p-mysql

cf marketplace

cf create-service p-mysql 100mb-dev mysql-test

rails new testapp -d mysql

manifest.yml:

applications:

  • name: testapp command: bundle exec rake db:migrate && bundle exec rails s -p $PORT services:
    • mysql-test

cf push testapp

open page, yes it’s a 404 but that means your app can talk to the database.

Done!