Ansible & Cloud Formation automation for creating Highly-Available Docker Swarm clusters on AWS
Scalable Docker Swarm cluster deployment using the combination of AWS CloudFormation to create resources (such as EC2, VPC, AutoScaling etc..) and Ansible to automate the process with a single command. Deployment EC2 instances use CoreOS as it's ideal for this scenario.
If a Stack already exist with the given stack name, it will update. Otherwise creates a new stack from scratch.
Topology of Deployment
- CoreOS as the host OS for all instances.
- Self provisioning of instances using cloud-config of CoreOS
- Two launch configurations, auto scaling groups and elastic load balancers are created: Masters and Minions
- Minions auto scaling group depends on the creation of the Master auto scaling group to prevent race condition.
- Etcd enabled for Masters and disabled for minions.
- Etcds run on master nodes which automatically create a ring cluster by using the discovery url, hence highly-available.
- Docker Swarm managers on master nodes join the Swarm cluster by using their local Etcd configuration.
- Docker Swarm minions join the cluster using Master ELB DNS to ensure high-availability.
Install Docker and Ansible on your local and clone this repo.
group_vars/all/credentials.yml.exampleand change it as
group_vars/all/common.ymlas it fits your needs.
Make sure to create a keypair in AWS IAM.
Create the CloudFront Stack using Ansible
Once the Stack creation is complete, Ansible will out provide the output of Swarm Master as related information and swarm node http load balancer
From your local, connecto Swarm Master and see info:
docker -H tcp://<MasterElbDns>:4000 info
An example deployment to all nodes from your local:
docker -H tcp://<MasterElbDns>:4000 run -d -p 80:80 nginx