So you want to offer your developers an Infrastructure as a service (IaaS) that is beyond just traditional Physical, virtual or cloud servers right? Well look no further, vRealize Automation can quickly and easily be extended to accommodate containers as an IaaS offering . In this guide I will show you how you can offer containers as a service through the vRA portal while still maintaining all the rich automation, reclamation, policy and governance that vRA is famous for. Add in NSX and you can also provision load balancers and networks for your containers! So what are you waiting for? Let’s get going!
NOTE: in part 1 we used the Linux Guest agent. While you can build on that blueprint with this guide, it is not required. This guide will also install and start the docker service so the guest agent is not needed.
Docker as a Service vRA/vCAC Extension v.1.0
Pre-Reqs you will need in place for this solution:
- vCAC 6.0, 6.1 or vRA 6.2 installed and configured (This will probably work with vCAC 5.2 but I have not tested)
- vRA/vCAC configure to run vCO workflows at machine states. See my guide here.
- RHEL or CENTOS 6.6 or higher blueprint setup to provision from the vRA or vCAC portal.
- Provisioned VM’s need to have access to the internet to pull repository packages and docker images.
- An NFS server with a mountable script directory available for you to run scripts and install software from. See this guide here.
- A quite place to work for a few hours where you will not be interrupted.
- If you need the docker images to download faster or your VM’s don’t have access to the internet, you may consider a local Docker registry. Follow my guide here. (NOTE you will need to modify the Docker scripts in this guide to work with a local docker registry)
Power on your Linux template and login as root or sudo to root and create directory on the root file system named repo. This is where you will mount your NFS share to.
Next, create a file named repomount.sh using the vi editor with the following content and save it.
mount -t nfs $1:$2 /repo &>/repomount.log
Now shutdown your template. Remember, if you are using Linked clones you will also need to take a new snapshot in vCenter Client and then run an inventory scan in vCAC and update the blueprint to point to the new snapshot.
Now let’s create the script that we will run to install Docker. Pull the Docker image and start the container. Using the vi editor create the script dockerpullandrun.sh
Press the i key to change to insert mode and enter the following lines then press escape and then Hold Shift and press ZZ to save it.
yum -y install epel-release yum -y install docker-io service docker start >/dockerstarted.log 2>&1 chkconfig docker on sleep 30 $1 >/dockerpull.log 2>&1 $2 >/dockerrun.log 2>&1
The above script is first installing the Extras packages, then it installs docker, next it starts the docker service then adds it to start at boot. The next step is a sleep for 30 seconds to make sure docker is started properly. Then I pass the Docker run string and Docker pull string from the user input in vRA to pull and run the container.
Now we need to import the workflow package into your vCO instance. NOTE: if you have not already configured vRA and vCO together this guide will not work.
Download My Package here >>.org.vmtocloud.vravcac.dockerinstallpullandrun
The file is in ZIp format. Unzip the file first and then log into the vRO client and import the package like so.
Edit this workflow and go to the General tab. You will need to edit the vmUsername and vmPassword so the workflow can access the newly provisioned VM.
Now we need the workflow ID so we can create the Build Profile in vRA to call this workflow as part of the provisioning process. Copy the ID to the clipboard.
Now login to the vRA\vCAC portal and navigate to the Infrastructure tab, then Blueprints and build profiles and create the following build profile. Notice the DockerPull and DockerRun Prompt the user. Click OK to save the build profile.
docker.pullandrun.script /repo/dockerpullandrun.sh DockerPull DockerRun ExternalWFStubs.MachineProvisioned This is the ID of the vCO workflow you copied to your clipboard. repo.path The path to your NFS share repo.server The NFS server VMware.VirtualCenter.OperatingSystem rhel6_64Guest
Now fire off a new request and provide the Docker Pull and Run commands you want. I provided an easy ones below.
docker pull vmtocloud/myblog docker run -d -p 80:80 vmtocloud/myblog