CloudFoundry: Install BOSH CLI v1 and BOSH Lite on Ubuntu

Update Jan 2019: Instead of these instructions, please see my newer article for local BOSH installation on VirtualBox using CLI v2.

 

BOSH is a project that unifies release, deployment, and lifecycle management of cloud based software.

The BOSH CLI v1 is now older and has been replaced with CLI v2, so if you want to install the newer version read my other article by clicking here.

But if you still need to use the CLI v1, then I will describe how to install it on Ubuntu along with BOSH Lite which puts a  Director into a single VirtualBox VM instance that can be targeted by the CLI client.

Install BOSH CLI v1

Install Ruby and RubyGems

The BOSH CLI v1 is built using Ruby.

For Ubuntu 14.04, you should install Ruby 2.3 and RubyGems 2.6 from source.  For Ubuntu 16.04, Ruby 2.3 is in the standard apt repository and we will install RubyGems 2.7 from source.

I tried other combinations such as Ruby 2.1 and RubyGem 2.7 but there were warnings thrown regarding “kernel_require.rb” and missing libraries, so proceed at your own risk if you want a different pairing than described here.

Ubuntu 14.04

There are various ways to install Ruby 2.3 (rbenv/rvm/source), but I choose  the ppa from Brightbox.

$ sudo apt-add-repository ppa:brightbox/ruby-ng -y
$ sudo apt-get update
$ sudo apt-get install ruby2.3 ruby2.3-dev -y
$ which ruby2.3
$ sudo update-alternatives --config ruby
$ ruby --version

Then install RubyGems by grabbing the archived source from this download page  We will use 2.6.4 on Ubuntu 14.04.

$ sudo apt-get remove rubygems
$ wget https://rubygems.org/rubygems/rubygems-2.6.4.tgz
$ tar xvfz rubygems-2.6.4.tgz
$ cd rubygems-*
$ sudo ruby setup.rb
$ which gem2.3
$ sudo update-alternatives --config gem
$ gem --version
Ubuntu 16.04

On Ubuntu 16.04, Ruby 2.3 can be installed directly from the standard repository.

$ apt-cache search ruby2.3
$ sudo apt-get install ruby2.3 -y
$ sudo ln -fs /usr/bin/ruby2.3 /usr/bin/ruby
$ ruby --version

Then install RubyGems by grabbing the most recent source from this download page  We will use 2.7.6 on Ubuntu 16.04.

$ sudo apt-get remove rubygems
$ wget https://rubygems.org/rubygems/rubygems-2.7.6.tgz
$ tar xvfz rubygems-2.7.6.tgz
$ cd rubygems-*
$ sudo ruby setup.rb
$ sudo ln -fs /usr/bin/gem2.3 /usr/bin/gem
$ gem --version

Install the BOSH CLI

The BOSH CLI 1.x can be installed as a gem.

$ sudo gem install bosh_cli --no-ri --no-rdoc
$ sudo gem install bundler

Now check the BOSH version and status.

$ bosh --version
BOSH 1.3262.26.0

$ bosh status

The status should show no director or deployment set.

Install bosh-init

Since you are using v1, you will also need to install bosh-init.  This binary can be retrieved from the download page.

$ wget https://s3.amazonaws.com/bosh-init-artifacts/bosh-init-0.0.103-linux-amd64
$ sudo chown root:root bosh-init-* 
$ sudo chmod ugo+r+x bosh-init-*
$ sudo cp bosh-init-* /usr/local/bin/bosh-init
$ bosh-init --version

Install Utilities

You will want to install these utilities to assist in your workflow before moving forward.  Spiff is useful for yaml comparisons and yq is a yaml parser in the same spirit as jq for json.

Install Spiff

$ wget https://github.com/cloudfoundry-incubator/spiff/releases/download/v1.0.8/spiff_linux_amd64.zip

$ sudo unzip spiff_linux_amd64.zip -d /usr/local/bin

Install yq

Source, download page, and docs.

$ wget https://github.com/mikefarah/yq/releases/download/1.14.0/yq_linux_amd64
$ sudo chown root:root yq_linux_amd64
$ sudo chmod ugo+r+x yq_linux_amd64
$ sudo mv yq_linux_amd64 /usr/local/bin/yq

Creating a Director using BOSH Lite

Now that we have a full BOSH v1 client install, we need to point it to a Director.  The quickest way to create a Director is using BOSH Lite, which allows us to put multiple components all unto a single VM.

In this article, we will deploy BOSH Lite unto a VirtualBox VM using the Vagrantfile method.

Note that this Vagrantfile method is no longer recommended.  When you upgrade to the BOSH CLIv2, use the “create-env” command instead as described in my article here.  I’ve noticed more stability in the Director when using this newer implementation.

 

Install VirtualBox and Vagrant

The first step is to install Oracle VirtualBox 5.1+ as the type 2 hypervisor, and the latest version of Vagrant.  I have written up full details for Ubuntu 14.04/16.04 in this article.

Instantiate BOSH Lite Director

Now we can bring up the BOSH Lite Virtualbox, which is named “bosh-lite_default…” and is on the Host-only network 192.168.50.0/24.  This VM is where the BOSH Director is deployed and is where we will point the BOSH client.

$ git clone https://github.com/cloudfoundry/bosh-lite
$ cd bosh-lite
$ vagrant up --provider=virtualbox
$ vboxmanage list vms | grep bosh-lite

SSH into the BOSH-Lite box, and check for yourself the IP address and which ports are listening for connections.

$ vagrant ssh
vagrant@bosh-lite$ hostname
vagrant@bosh-lite$ ifconfig | grep "inet addr"
vagrant@bosh-lite$ netstat -an | grep -i "LISTEN "
vagrant@bosh-lite$ exit
$ hostname

You should see that the vagrant box has a static host-only network adapter set to 192.168.50.4.  And it will have a listener on port 25555 which is how the BOSH CLI client will communicate with it.

 Target the BOSH Director

Use 192.168.50.4 as the address for the BOSH Director and use the credentials admin/admin when prompted for username and password.

$ bosh target 192.168.50.4
Target set to 'Bosh Lite Director'
Your username: admin
Enter password: admin
Logged in as 'admin'

Now check the BOSH status again.

$ bosh status
Config
             /home/fabian/.bosh_config

Director
RSA 1024 bit CA certificates are loaded due to old openssl compatibility
  Name       Bosh Lite Director
  URL        https://192.168.50.4:25555
  Version    260.0.0 (00000000)
  User       admin
  UUID       63ddb6a6-d6fe-40e1-b16b-2ff6b2034c79
  CPI        warden_cpi
  dns        disabled
  compiled_package_cache enabled (provider: local)
  snapshots  disabled

Deployment
  not set

This time we can can see that the Director is set to 192.168.50.4:25555.

Before moving on, add routes to the local network route table so that deployments are accessible.  This will send any traffic bound for 10.244.0.0/16 into this BOSH-lite VM at 192.168.50.4.

$ sudo bin/add-route

 

Simple BOSH Deployment

Now that we have a BOSH CLI v1 and a BOSH Director, let’s deploy a simple Apache server with a simple greeting using BOSH.

Grab project from github

Retrieve the simple project from github.

$ sudo apt-get install git curl -y
$ git clone https://github.com/fabianlee/simple-bosh-release.git
$ cd simple-bosh-release

The manifest for this project can be found at “deployments/warden.yml”.  It contains the name of the deployment, the stemcell to use as a base filesystem, the network address for this container (10.244.1.2), and a set of custom properties to pass into the container including the greeting that Apache will deliver.

First we need to download the stemcell referred to in the warden.yml manifest, which you can look at manually or can be pulled using the yq utility like below.

$ yq r deployments/warden.yml resource_pools.*.stemcell.name

Now that we know the stemcell used is named “bosh-warden-boshlite-ubuntu-trusty-go_agent”, we can download the latest version as referenced from its download page on bosh.io.

$ wget --content-disposition https://bosh.io/d/stemcells/bosh-warden-boshlite-ubuntu-trusty-go_agent?v=3541.5

Then we upload this local stemcell to the Director, which places it into the Blobstore.

$ bosh upload stemcell bosh-stemcell-3541.5-warden-boshlite-ubuntu-trusty-go_agent.tgz

Note that the “upload-stemcell” command is capable of using a remote URL.  In locked down production environments, you may be forced to copy over the stemcells manually, so I wanted to show how that would work.

Now create and upload the release, using the name “simple-bosh-release” when prompted by the create.

$ bosh releases
$ bosh create release --force
$ bosh upload release
$ bosh releases

This created the release, but now it must be deployed.

$ bosh vms
No deployments

$ bosh deployment deployments/warden.yml
$ bosh deploy

$ bosh vms

With deployment complete, we can use curl or a browser to test static page returned from Apache.

$ curl http://10.244.1.2
<html><body><h1>Hello, world!</h1></body></html

Modify the “greeting” property in “deployments/warden.yml” either manually or using yq.

$ yq w -i deployments/warden.yml properties.webapp.greeting "Hello Again!"

And then redeploy.

$ echo yes | bosh deploy
$ curl http://10.244.1.2
<html><body><h1>Hello Again!</h1></body></html

To stop the VM and then delete the deployment and release completely, use the commands below.

$ bosh vms
$ bosh stop webapp --force
$ bosh delete deployment webapp-warden

$ bosh deployments
$ bosh vms

$ bosh delete release simple-bosh-release
$ bosh releases

 

 

REFERENCES

https://bosh.io/docs/sysadmin-commands.html (CLI v1)

https://bosh.io/docs/cli-v2-diff.html (diff between v1 and v2 CLI)

https://bosh.io/docs/install-bosh-init.html (installing bosh-init, older v1 utility)

https://www.brightbox.com/blog/2016/01/06/ruby-2-3-ubuntu-packages/ (ppa for ruby 2.3)

https://makandracards.com/makandra/716-install-rubygems-on-ubuntu-debian (install RubyGems from source)

https://rubygems.org/pages/download#formats (RubyGems source download)

https://medium.com/@ravijagannathan/install-cloud-foundry-on-bosh-lite-6d3b9a1e416a (releasing with v1)

NOTES

Installing Ruby 2.3 from source on Ubuntu 14.04

wget http://ftp.ruby-lang.org/pub/ruby/2.3/ruby-2.3.1.tar.gz
tar -xzvf ruby-2.3.1.tar.gz
cd ruby-2.3.1/
./configure
make
sudo make install
which ruby
/usr/local/bin/ruby --version
ruby --version
sudo ln -fs /usr/local/bin/ruby /usr/bin/ruby