Update Ansible playbook to copy Docker Compose file to manager. Update Docker Compose file. Signed-off-by: Scott Lowe <scott.lowe@scottlowe.org> |
||
|---|---|---|
| .. | ||
| ansible.cfg | ||
| compute.tf | ||
| create-swarm.yml | ||
| data.tf | ||
| destroy-swarm.yml | ||
| docker-stack.yml | ||
| ec2.ini | ||
| ec2.py | ||
| networking.tf | ||
| output.tf | ||
| provider.tf | ||
| README.md | ||
| security.tf | ||
| variables.tf | ||
Instructions for Using this Demo Environment
Prerequisites
This demo environment assumes that you have the following software already installed on your system:
- Terraform 0.9.x (tested with 0.9.2, should work with any 0.9.x version)
- Ansible 2.x (tested with Ansible 2.3.0)
- Git 2.x (should work with any recent version of Git)
This demo also assumes that you've properly configured your AWS credentials. (If the aws command-line tools work, then your credentials are properly configured.)
Before trying to use this demo environment, please ensure that you've installed the necessary prerequisites.
This demo environment was tested on Fedora Linux, but it should work without any issues on any Linux distribution or on recent versions of OS X. I don't know what would be required to make it work on Windows, sorry.
Setup for the Demo Environment
-
Open a terminal and navigate to the directory where you'd like to store the files for this demo environment.
-
Run
git clone https://github.com/lowescott/2017-itx-container-workshopto clone the repository to the current directory. -
Switch into the directory for this demo environment (
cd 2017-itx-container-workshop/ec2-swarm). -
Edit
terraform.tfand specify a valid name for the S3 bucket and the name/path of the file where Terraform should store its state. If you want to use a region other than "us-west-2", you also need to specify the AWS region. -
Run
terraform initto configure the S3 storage for Terraform state. Address any errors that may be reported. -
Edit
ec2.iniand specify the AWS region(s) you'll be using. (If you are using the "us-west-2" region, you may leave this file unmodified.) -
Edit
vars.tfto specify the name of an AWS keypair to use. If you want to use a region other than "us-west-2", you'll also need to specify the name of the AWS region to use.
The demo environment is now ready to be created.
Creating the Demo Environment
-
In the
ec2-swarmdirectory where the repository was cloned, runterraform planto evaluate the requested Terraform configuration against your current AWS infrastructure. -
Run
terraform applyto create all the necessary AWS infrastructure. -
Run
./ec2.py --refresh-cacheto refresh the Ansible inventory. This will query AWS and return information about the AWS infrastructure that was just created by Terraform. -
Run
ansible-playbook create-swarm.ymlto create the Swarm cluster.
At this point you now have a working demo environment.
Deploying the Demo Application
-
Connect to the manager node using SSH with the command
ssh -i <Path to SSH Key file> ubuntu@<public IP of manager>. You can determine the public IP of the manager node using theec2.pyinventory script, if necessary. -
While logged into the manager node, run
docker stack deploy --compose-file docker-stack.yml demoto deploy the sample application. -
Use a local browser to connect to port 8888 of the manager node's public IP address to show the visualizer.
-
Use a local browser to connect to port 8080 of the manager node's public IP address to show WordPress.
-
You can scale up the number of containers using the
docker service scalecommand. The visualizer will reflect the additional containers that are deployed. Usedocker service lsto list the services.
You now have a working demo application.
Destroying Only the Swarm Cluster
If you'd like to tear down the Swarm cluster but leave the AWS infrastructure intact, follow these steps:
-
Open a terminal and switch into the
ec2-swarmdirectory of the cloned repository. -
Run
ansible-playbook destroy-swarm.ymlto destroy the Swarm cluster.
The Swarm cluster will be destroyed, but the AWS infrastructure will remain active. You can use ansible-playbook create-swarm.yml to create a new Swarm using the same infrastructure.
Destroying the Entire Demo Environment
To destroy the entire demo environment, simply run terraform destroy from the ec2-swarm directory.