tl;dr

Quickly spin up multiple VMs with useful DNSs on your local machine and automate complex environments easily.

Here’s a video:

Introduction

Maintaining Docker at scale, I’m more frequently concerned with clusters of VMs than the containers themselves.

The irony of this is not lost on me.

Frequently I need to spin up clusters of machines. Either this is very slow/unreliable (Enterprise OpenStack implementation) or expensive (Amazon).

The obvious answer to this is to use Vagrant, but managing this can be challenging.

So I present here a very easy way to set up a useful Vagrant cluster. With this framework, you can then automate your ‘real’ environment and play to your heart’s content.

$ pip install shutit

$ shutit skeleton # Input a name for this module.

# Default: /Users/imiell/shutit_resins [hit return to take default] # Input a ShutIt pattern.

Default: bash

bash: a shell script

docker: a docker image build

vagrant: a vagrant setup

docker_tutorial: a docker-based tutorial

shutitfile: a shutitfile-based project [type in vagrant] vagrant How many machines do you want (default: 3)? 3 [hit return to take default] What do you want to call the machines (eg superserver) (default: machine)? [hit return to take default] Do you want to have open ssh access between machines? (default: yes) yes Initialized empty Git repository in /Users/imiell/shutit_resins/.git/

Cloning into ‘shutit-library’...

remote: Counting objects: 1322, done.

remote: Compressing objects: 100% (33/33), done.

remote: Total 1322 (delta 20), reused 0 (delta 0), pack-reused 1289

Receiving objects: 100% (1322/1322), 1.12 MiB | 807.00 KiB/s, done.

Resolving deltas: 100% (658/658), done.

Checking connectivity… done. # Run:

cd /Users/imiell/shutit_resins && ./run.sh

to run. [follow the instructions to run up your cluster. $ cd /Users/imiell/shutit_resins && ./run.sh

This will automatically run up an n-node cluster and then finish up.

NOTE: Make sure you have enough resources on your machine to run this!

BTW, if you re-run the run.sh it automatically clears up previous VMs spun up by the script to prevent your machine grinding to a halt with old machines.

Going deeper

What you can do from there is automate the setup of these nodes to your needs.

For example:

def build(self, shutit):

[... go to end of this function ...] # Install apache

shutit.login(command='vagrant ssh machine1')

shutit.login(command='sudo su - ')

shutit.install('apache2')

shutit.logout()

shutit.logout() # Go to machine2 and call machine1's server

shutit.login(command='vagrant ssh machine2')

shutit.login(command='sudo su -')

shutit.install('curl')

shutit.send('curl machine1.vagrant.test')

shutit.logout()

shutit.logout()

Will set up an apache server and curl a request to the first machine from the second.

Examples

This is obviously a simple example. I’ve used this for these more complex setups which are can be instructive and useful:

Chef server and client

Creates a chef server and client.

Docker Swarm

Creates a 3-node docker swarm

OpenShift Cluster

This one sets up a full OpenShift cluster, setting it up using the standard ansible scripts.

Automation of an etcd migration on OpenShift

This branch of the above code sets up OpenShift using the alternative Chef scripts, and migrates an etcd cluster from one set of nodes to another.

Docker Notary

Setting up of a Docker notary sandbox.

Help Wanted

If you have a need for an environment, or can improve the setup of any of the above please let me know: @ianmiell

Learn More

My book Docker in Practice:

Get 39% off with the code: 39miell