Requirements:
- AWS Account as user
- Terraform configured ( Could use the docker compose file to set it up)
- AWS CLI installed and credentials configured.
- Ansible setup
TO DO TASKS
- Building and pushing the Docker images to Amazon ECR
- Setting up Infrastructure
- Setting up CICD pipeline
- Ensuring all the services are up and running
- Testing the solution.
- Creating DNS Record for the Load Balancer's
- Setting up ssl security
- Monitoring and tracing
Click the 'Use this Template' button for your initial setup
Terraform Readme is located at terraform/TERRAFORM_README.md
Make the file terraform_script.sh file executable ('chmod +x terraform_script.sh') and execute it by running:
./terraform_script.sh
This provisions the infrastructure for the first time,and from the output copy those ip addresses key to the hosts file under inventoy directory.inventory
Once all the configurations is set,run the terraform script again ./terraform_script.sh
then this command from the ansible playbook which deploys the cluster
ansible-playbook -i inventory/hosts playbook.yml
The swarm cluster should now be ready.To chck the cluster using ssh in manager node:
ssh -i your_key_file.pem ubuntu@manager_public_ip
sudo docker node ls`
To run the terraform files
terraform init
To set the resources to be provisioned use
terraform plan -var-file=tfvars/dev.tfvars
&&
terraform apply -var-file=tfvars/dev.tfvars
Doing terraform apply provisions the Docker Swarm resources, VPC with 3 instances (Worker and master) The shell script install_dockercompose.sh installs docker and docker compose in your servers.
Ansible script responsible for creating the swarm cluster (a manager and two worker node)
The inventory/hosts directory should be changed to the ec2 instances ip addresses to enable ssh.
Playbook command:
ansible-playbook -i inventory/hosts playbook.yml
- terraform init
- terraform plan -var-file=tfvars/dev.tfvars
- terraform apply -var-file=tfvars/dev.tfvar
To terminate the infrastructure : terraform destroy -var-file=tfvars/dev.tfvars
Note:
-
To generate keys ssh-keygen cat ./ssh/id_rsa.pub aws configure --profile (set your profile)
-
Incase faced with lock state key. Solution
docker-compose up
docker run -d -it --name terraform-ubuntu ubuntu