Skip to content

pexaorj/nginx-consul-nodejs-terraform

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Readme First

This repository works as an example of how to create and deploy applications on Amazon AWS using some DevOps tools. The intent here is to put you in a new perspective of how do those things, running aways the old fashion of do things manually at AWS console, at the end of this tutorial you will have had deployed at least one simple application on AWS using the new way of do things, called IaC (Infrastructure as code).

What you will need to use this repository as example

Repository Structure

├── docker
│   ├── docker-nginx-consul
│   └── nodejs
├── scripts
│   └── stress_test.sh
├── terraform
│   ├── arch-main-state.tf
│   ├── gera-chave-ssh.sh
│   ├── makeconfig.sh
│   ├── modules
│   │   ├── eip
│   │   ├── env
│   │   ├── instances
│   │   │   ├── app-instances
│   │   │   └── arch-instances
│   │   ├── routes
│   │   ├── security-group
│   │   ├── subnets
│   │   └── vpc
│   ├── README.md
│   ├── ssh_keys
│   │   ├── debug-key
│   │   └── debug-key.pub
│   ├── ssh-key.tf
└── vagrant

Folders

Docker - contains all files to build docker images Scripts - contains all scripts Terraform - contains all tf files used to deploy the infrastructure during this demo Vagrant - used to build one Ubuntu test machine

Requirements

  • One AWS account created
  • Enough permissions to use this AWS account to deploy this tutorial on N.Virginia Region
  • Basic knowledge working with AWS
  • Use bash on your console (this example assume that you are one Linux User or are familiar with bash commands)

What will be deployed

nginx-consul-template.png

  • 1 Instance to work as a load balancer with (Nginx + Consul + Consul-template + Register)
  • 2 Instances acting as application instances ( Nodejs + Register)
  • 1 Route53 Zone + records to instances interact using dns names instead directly ip's
  • All other things are not described here in detail since it's not the main purpose of this tutorial.

Points to pay attention to and have in mind

As this repository works as a simple example, some important aspects are not covered here, like:

  • One ELB to split the load between frontend servers
  • High Availability over Nat Instances
  • Auto Scaling group
  • Bastion Host
  • Log improvements and tools (ELK, graylog, datadog, cloudwatch, etc)

Deploy the example Stack.

  1. Create one S3 Bucket in N.Virginia (us-east-1) region using the AWS Console

2)Create one IAM user and download the API/key to use during this example

  1. Configure your console to use this credential with the command:
aws config
  1. Open this file arch-main-state.tf, and update the bucket name, using the name of the s3 bucket created in the 1 step.
terraform {
    backend "s3" {
    bucket = "terraform-chaordic"
    key    = "arch-state/terraform.tfstate"
    region = "us-east-1"
    shared_credentials_file = "/root/.aws/credentials"
    profile                 = "default"
  }
}
  1. Run this script to generate one SSH Key pair. This key will be used to access all servers if needed.
terraform/gera-chave-ssh.sh
  1. Download the terraform version 0.9.0 -[terraform_0.9.0](https://releases.hashicorp.com/terraform/0.9.0/)

  2. Run this script to perform the planning over your AWS Account.

terraform/makeconfig.sh

If all ran well and you started to see in the console output all resources that will be created on your AWS account, you can go to the next step, which will apply this code to your AWS account.

  1. Apply the code using terraform
terraform apply

So far so good, but explain to me how it works

After performing one terraform apply, terraform will start to interact with amazon cli using your api/key to do some instructions to create your described infrastructure using your code. It can take a while and you will see all steps from your console output.

To test this example and check if all those actions worked as expected you should now open your AWS account console and:

  • Go to EC2>>Instances and look for the instance of nginx-web-proxy, grab the public DNS (ipv4).
  • Use this address to paste it on your browser URL to get access to this example application.
  • If you reload the page, you will see 2 responses, each of them coming from one server (in this example we have 2).

Clean up

After performing all tests, remember that maintaining resources running on AWS can generate costs for you or your organization, so to avoid any kind of billing problems, remember to delete this stack at the end of your tests, as you saw, using IaC is simple to have the complete environment up and running in a few moments.

To clean run this command: terraform destroy It will ask if you want to perform this action, please type yes.

About

Docker + Nginx + Nodejs + Terraform + Register + Consul +Consul-Template + Ubuntu 16.04 Server

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published