A template for create a Docker Swarm mode cluster on AWS.
These instructions will get you a copy of the project up and running on your cloud server for development and testing purposes.
- CARE!!! This template runs (5) t2.micro instances by default, it will be consume 5 hours of free tier once per execution.
For run this project you need:
- Amazon AWS account - Amazon cloud server
- Amazon AWS EC2 user - User with EC2 permissions
- Terraform - Write, Plan, and Create Infrastructure as Code
- Ansible - Automation for everyone
First of all you must create an aws account and install all prerequisites, you can find it easy on their website.
When you are done with prerequisites, you can simply run the setup.sh
script inside the folder inventory
, it must
create a ssh keypair and export all environment variables that project need if required.
## Note that script is invoked using source
source setup.sh
Another way is to setup environment manually following those steps that maybe you don't need to do:
Export environment variable AWS_ACCESS_KEY_ID with the access key id of user with EC2 permissions.
## Example: replace XXXXXXXXXXXXX for your key id
export AWS_ACCESS_KEY_ID=XXXXXXXXXXXXX
Export environment variable AWS_SECRET_ACCESS_KEY with the access secret key of user with EC2 permissions.
## Example: replace XXXXXXXXXXXXX for your access key
export AWS_SECRET_ACCESS_KEY=XXXXXXXXXXXXX
Export environment variable AWS_DEFAULT_REGION with the region on cluster must be deployed.
## Example: replace at-narnia-2 for your region
export AWS_DEFAULT_REGION=at-narnia-2
Export environment variable ANSIBLE_HOST_KEY_CHECKING to avoid fingerprint check.
export ANSIBLE_HOST_KEY_CHECKING=False
Create a ssh keypair with and put the keys on inventory
folder as sw-aws-key
and sw-aws-key.pub
.
## Example: you can generate the key as you want
ssh-keygen -f sw-aws-key -t rsa -b 4096 -N "" -C "" -q
chmod 400 sw-aws-key
Once you completed all you can be able to see exported vars with env
command and the public key file on inventory
folder.
You can adjust all cluster nodes number and instance types on variables.tf
file.
When you ready, you can run the commands below to create the cluster.
## Init the providers
terraform init
## Check the plan
terraform plan
## Apply the plan
terraform apply
## WAIT!!! until aws instances start up
## Run Ansible
ansible-playbook -i ./inventory/hosts --private-key ./inventory/sw-aws-key playbook.yml
A fast way to run this if you don't like read.
#!/usr/bin/env bash
# Clone the repository
git clone https://github.com/Xustyx/AADSMCT.git
# Move to inventory folder
cd ./AADSMCT/inventory
# Run setup script
source setup.sh
# Move backwards
cd ..
# Run terraform stuff
terraform init
terraform plan
terraform apply
## WAIT!!! until aws instances start up
sleep 60
# Run ansible stuff
ansible-playbook -i ./inventory/hosts --private-key ./inventory/sw-aws-key playbook.yml
## GG
To remove all the cluster you only need to run this command:
terraform destroy
- Amazon AWS cloud - Amazon cloud server
- Terraform - Write, Plan, and Create Infrastructure as Code
- Ansible - Automation for everyone
The author can not be held liable for any use of this code.