This project was created to be 100% automated, which means, Terraform will create all AWS resources (VPC, Subnets, Route tables, IGW, NAT and EC2) and then Ansible will install, set Kubernetes up on the master and the EC2 nodes and deploy the Nginx Ingress, WordPress and Bananas apps as soon as Terraform finishes the deployment without the need to update any file, but before this make sure you've done all prereqs.
Terraform will create the MySQL RDS as well as export the endpoint to Ansible to be used on WordPress Deployment. Also, the RDS password for the user, wpmysql, will be created via Terraform as well as the password via SSM Parameter, secure string, and then as soon as Ansible starts the deployment, it'll grep this password and store it in a variable to be used on WordPress Deployment as well.
Therefore, sensitive data won't be exposed.
These tools were installed locally.
- Make sure the file in /group_vars/all/default.yml is updated according to your infrastructure.
- Update the file ansible.cfg, parameter private_key_file to your EC2 key pair in the Dev directory. This Key Pair will be used to access the EC2 by Ansible.
[defaults]
inventory=./inventory/hosts
host_key_checking=false
private_key_file= path_to_your_key_pair (eg. /myfolder/mykey.pem)
- Update key_pair_name variable on main.tf file in the Dev directory to your EC2 key pair.
Terraform project
Update the main.tf file in the Dev directory if you want to change any AWS resource name.
Access the Dev folder and run terraform init
to initialize the project.
Access the Dev folder and run terraform plan
to check out any issue.
Once it’s OK, run terraform apply
Wordpress Website
Banana website
AWS Nginx Network Load Balancer
K8s svc
AWS RDS
AWS SSM Parameter
Running the below command in a couple of terminal windows, we can stress the environment and then test the HA.
while true; do curl http://my-website.ugulino.com -v; echo; done
As soon as the CPU will be consumed more than 50%, the pods will scale up.
As soon as the CPU will be consumed less than 50%, the pods will scale down.
You can destroy your environment running the below command.
terraform destroy