CloudFoundry: The lifecycle of a simple BOSH release

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

Software to be deployed via BOSH is called a release, and in this article I will use a very simple release to illustrate how to create, deploy, version, and revert these releases.

Prerequisites

If you do not already have BOSH installed, you can install locally on VirtualBox or on AWS.

Simple BOSH deployment

Now that we have a BOSH CLI and a BOSH Director, let’s deploy a simple release – an Apache server with a configurable greeting.

Grab project from github

Retrieve the simple project from github.

sudo apt-get install git curl -y

# grab simple project
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, name of the release, and name of the stemcell that should be used, static IP of the container, and custom greeting that Apache will deliver.

$ bosh int deployments/warden.yml --path /name
webapp-warden

$ bosh int deployments/warden.yml --path /releases/0/name
simple-bosh-release

$ bosh int deployments/warden.yml --path /resource_pools/0/stemcell/name
bosh-warden-boshlite-ubuntu-trusty-go_agent

$ bosh int deployments/warden.yml --path /networks/0/subnets/0/static/0
10.244.1.2

$ bosh int deployments/warden.yml --path /properties/webapp/greeting
Hello, world!

Retrieve Stemcell

First download the stemcell referred to in the warden.yml manifest.  We can download the latest version as referenced from its download page on bosh.io.

bosh upload-stemcell https://bosh.io/d/stemcells/bosh-warden-boshlite-ubuntu-trusty-go_agent?v=3586.60

Create a release

The first step in deployment is to create a release, notice the version is 0+dev.1.

$ bosh releases
$ bosh create-release --name=simple-bosh-release --force
...
Added dev release 'simple-bosh-release/0+dev.1'
...

# no releases exist yet, until uploaded in next step

Upload the release

Then upload “simple-bosh-release/0+dev.1” release to the Director.

$ bosh upload-release --name=simple-bosh-release
...
Task 65 | 01:49:37 | Release has been created: simple-bosh-release/0+dev.1 (00:00:00)
...
Succeeded

$ bosh -d simple-bosh-release releases

Name Version Commit Hash 
simple-bosh-release 0+dev.1 16e45d0
...
1 releases
...

# no deployments exist yet, until created in next step

Create deployment from release

Using the “simple-bosh-release/0+dev.1” release, now we need to instantiate a deployment.  The deployment is called “webapp-warden” as defined in the manifest.

$ bosh deployments
...
0 deployments
...

$ bosh deploy --deployment=webapp-warden deployments/warden.yml --no-redact


$ bosh deployments
...
Name Release(s) Stemcell(s) Team(s) Cloud Config 
webapp-warden simple-bosh-release/0+dev.1 bosh-warden-boshlite-ubuntu-trusty-go_agent/3586.60 - none 
..
1 deployments
...


$ bosh -d webapp-warden vms
...
Instance Process State AZ IPs VM CID VM Type Active 
webapp/41c79066-f256-4261-8e1d-114b27f30793 running - 10.244.1.2 e3bffeeb-5787-4631-6746-5a98a57a82fd common-resource-pool false
...

The vms listing above shows us the IP address of the newly deployed host, 10.244.1.2, as set in the manifest.

Test Apache web service

A curl to 10.244.1.2 where Apache is installed delivers the greeting from the manifest.

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

If you are using a local VirtualBox for BOSH, it is because of the route added during that installation that a request to 10.244.0.0 is sent to the BOSH Lite VM, which then knows how to route to the container’s internal IP of 10.244.1.2.

Change greeting and redeploy

In order to emulate a generic change, let’s change the greeting to say “Hello again!” and then redeploy the service.  This will take the release to “0+dev.2”.

# yq was installed in earlier articles, you can modify manually also
$ yq w -i deployments/warden.yml properties.webapp.greeting "Hello Again!"

$ bosh create-release --name=simple-bosh-release --force
...
Added dev release 'simple-bosh-release/0+dev.2'
...

# still only 0.1 version, upload has not happened yet
$ bosh releases
...
Name Version Commit Hash 
simple-bosh-release 0+dev.2 16e45d0+ 
~ 0+dev.1* 16e45d0 
...


$ bosh upload-release --name=simple-bosh-release
...
Task 68 | 01:59:31 | Release has been created: simple-bosh-release/0+dev.2 (00:00:00)
...

# now 0.1 and 0.2 versions exist
$ bosh releases
 ... 
Name Version Commit Hash 
simple-bosh-release 0+dev.2 16e45d0+ 
~ 0+dev.1* 16e45d0 ... 

$ bosh deploy --deployment=webapp-warden deployments/warden.yml --no-redact
...
- version: 0+dev.1
+ version: 0+dev.2
...
- greeting: "Hello, world!"
+ greeting: "Hello Again!"

# message changed
$ curl http://10.244.1.2
<html><body><h1>Hello Again!</h1></body></html>

Control VMs

The container VMs can be stopped/started as well as using ssh and scp for file and command control.

$ bosh -d webapp-warden vms
$ bosh -d webapp-warden ssh webapp/0
webapp/....$ hostname
webapp/....$ exit

# show ssh and scp abilities
$ bosh -d webapp-warden ssh webapp -c "echo hello world > /tmp/mytest.txt"
$ bosh -d webapp-warden scp webapp:/tmp/mytest.txt mytest.txt
$ cat mytest.txt

# start and stop
$ bosh -d webapp-warden stop webapp
$ bosh -d webapp-warden vms
$ echo y | bosh -d webapp-warden start webapp

Reverting to previous releases

If you needed to revert to a previous instance, it would mean deleting the current deployment, changing the version in the manifest, then redeploying.

# show current deployments and releases
$ bosh deployments
$ bosh releases

# modify manifest so specific version is used
yq w -i deployments/warden.yml properties.webapp.greeting "Forced version 0.1"
yq w -i deployments/warden.yml releases[0].version "0+dev.1"


# redeploy given new manifest values
$ bosh deploy --deployment=webapp-warden deployments/warden.yml --no-redact

# see that change was done
$ curl http://10.244.1.2
<html><body><h1>Forced version 0.1</h1></body></html>

# deployments shows 0+dev.1 
$ bosh -d webapp-warden deployments
... Name Release(s) Stemcell(s) Team(s) Cloud Config 
webapp-warden simple-bosh-release/0+dev.1 bosh-warden-boshlite-ubuntu-trusty-go_agent/3586.60 - none 
.. 1 deployments ...

 

Teardown deployments and releases

If you want to tear down the deployment and releases created, here are the commands.

# delete deployment
bosh deployments
bosh delete-deployment -d webapp-warden
bosh deployments

# delete specific releases
bosh releases
bosh delete-release simple-bosh-release/0+dev.2
bosh delete-release simple-bosh-release/0+dev.1
bosh releases

# to delete all versions of release
bosh delete-release simple-bosh-release
bosh releases

 

 

REFERENCES

NOTES

Download stemcell manually

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