This bash script provisions a fixed size docker swarm cluster using EC2 in AWS.
It uses bash scripts, AWS CLI, JQ and Ansible (to init the swarm cluster inside the vm's)
- Create IAM User and API key
- Create ssh key pair
aws ec2 create-key-pair --key-name <value> --output text > private_key1.pem
- Generate pubkey from private key
ssh-keygen -y -f private_key1.pem > public_key1.pub
- Create a AWS Route 53 Hosted Zone
- bash
- docker
- make
- Create file called
aws-variables.properties
in project's root dir, use reference values fromtemplate/aws-variables.properties
according to your project's parameters - Export
AWS_KEY_ID
andAWS_SECRET_KEY
variables - Run
make build
- Run
make dkrun
- Seat back and relax ☕ (:
- bash 3.2
- python 2.7
- ansible 2.x
- pip
- aws cli
- awk
- dos2unix
- jq
- openssl
- docker-py
- boto
- Create API keys access in IAM with permissive policy
- Create file called
password.properties
in project's root dir and supply withAWS_KEY_ID
andAWS_SECRET_KEY
variables - Create file called
aws-variables.properties
in project's root dir use reference values fromtemplate/aws-variables.properties
according to your project - Run
./create-ec2-swarm-cluster.sh
- Seat back and relax ☕ (:
Some blueprints to explain the provision setup
This VPC is distributed in two availability zones each one with a private subnet and a public one and an internet gateway that provides internet access to the public subnet.
This setup is provided by this Cloudformation template under Apache License, Version 2.0
The NAT Gateway allows instances placed in a private subnet to access the internet.
This setup is provided by this Cloudformation template under Apache License, Version 2.0
The SSH Bastion Linux Server provide secure access to Linux instances located in the private and public subnets.
This setup is provided by this Cloudformation template under Apache License, Version 2.0
- Use Terraform which is unarguably a better solution then bash scripts to provision complex infrastructures in cloud environments
- Create an auto scaling group for Docker Swarm Workers
- Create a lambda function described in
rotate-ebs-snapshots.py
and configure the CloudWatch trigger for it at the end of the provisioning process, this will enable automatic backup rotation.
Rogério Castelo Branco Peixoto (rcbpeixoto@gmail.com)