14 January 2017

Run Cloud Foundry on a USB drive

Cloud Foundry is an easy-to-use, comprehensive platform as a service (PaaS).  You can write an app locally, cf push it, and have it running in the cloud in seconds.

Pivotal's PCF Dev is a great, simple way to learn and practice using Cloud Foundry.

While you're learning, it enables you to develop and test on a local instance of Pivotal Cloud Foundry.  Then, when you're ready, you can just cf push to Pivotal Web Services (PWS), IBM BlueMix, or wherever your Cloud Foundry is hosted.

It took me about 30 minutes to get PCF Dev running: Download PCF Dev and cf CLI, install them, start the VM, and cf push a simple Python Flask app.

Why develop locally?

Hosted Cloud Foundry costs money.  While I'm in try-and-see mode I'd rather not have to monitor usage or worry about leaving something running that will drain my credit card.

BlueMix, PWS, and others provide a free tier or intro credits.  I'd like to use those up working with those providers' services like Watson, databases, and other integrations.

OK, but .. on a USB drive?

A running VM's swap files and logs can thrash the storage they sit on, wrecking capacity plans and burning out flash.  I'd rather risk that on a good $30 USB drive than on my system drive.

What about performance?

On this laptop the USB flash is a lot slower than the PCIe flash.  This is try-and-see, though, so I'm willing to sacrifice the performance.  When I need my app to run faster or be more highly available I'll cf login to my PWS or BlueMix account and cf push my app there.

Step by step

These steps cover OS X and are similar to Linux.  What did I miss?  Please leave comments!

You'll get used to using the cf commands in a shell anyway, so we'll do our work there.  Ready to go?  Good.

  1. Get a Pivotal Network account; Install or update VirtualBox; Get a good, empty 128GB USB drive.
  2. Pivotal's documentation covers the PCF Dev install really well.  Use it.
    (Check prerequisites; Download the installer; Download and install cf CLI; Install PCF Dev; cf dev start)
  3. Notice where your VM and USB drive are :
    Where's the PCF Dev VM?  ls -d ~/.pcfdev/vms/pcfdev*
    Where's your USB drive mounted?  On a Mac it's like /Volumes/somelabel
  4. Suspend PCF Dev and move it to your USB drive, for example :
    $ cf dev suspend
    $ mv ~/.pcfdev/vms/pcfdev-v0.436.0 /Volumes/somelabel/
    (This move may take a while .. it seems to run 18GB or so)
  5. Link to the new location and resume PCF Dev, for example :
    $ ln -s /Volumes/somelabel/pcfdev-v0.436.0 ~/.pcfdev/vms/pcfdev-v0.436.0
    $ cf dev start -t

A few words about space

tl;dr?  PCF Dev may try to use 60GiB (a little more than 64GB) of space.

What if you want to use a smaller USB drive? or put other things on it besides PCF Dev?  Are those GB? or GiB?  What's the capital of Nebraska?!

The first time I put PCF Dev on USB, I used a 64GB (a little less than 60GiB) drive with 30GiB free.  Then I learned that unmitigated try-and-see will cause Cloud Foundry to download all manner of buildpacks.  And I learned that the .vmdk in PCF Dev will try to grow up to 60GiB.

My PCF Dev .vmdk grew to, any guesses?, 30GiB; At that point PCF Dev seized up and VirtualBox was no longer able to manage the VM.  Want to know more?  Get your storage admin and your VMware admin on a conference call, tell them your VM crashed when it ran out of space in the datastore, ask them why, and demand that it be fixed immediately.

I deleted that PCF Dev and created a new one.  I also emptied my USB drive.  When you delete from a USB drive on a Mac, make sure you're deleting and not just moving to Trash.

Before I moved the new PCF Dev to the USB drive (between steps 3 and 4 above), I did this :
  1. cf dev stop to shutdown PCF Dev
  2. Open VirtualBox, use the PCF Dev VM settings to add the GParted .iso as an optical drive
  3. Boot the PCF Dev VM from the GPartEd .iso
  4. Resize the PCF Dev system partition down to 40GiB (40960MiB)
  5. Apply changes, shut down
  6. Remove the optical disk from the PCF Dev VM
  7. cf dev start -t to start PCF Dev and make sure it's working
The capital of Nebraska is Lincoln.