Giter Club home page Giter Club logo

wordpress-ecs's Introduction

Wordpress on ECS

This project contains terraform and packer files to provision a Wordpress service on top of AWS EC2 Container Service. It deploys by default in region us-west-2 and spans two availability zones.

Instructions

As we're using AWS ECR to store our docker containers and that our ECS cluster is pulling from it, we'll need to deploy our infrastructure first and then build and push our Wordpress container with packer.

What you'll need on your machine

  • packer
  • terraform
  • docker
  • ansible

Export your AWS credentials

export AWS_ACCESS_KEY_ID=your_access_key
export AWS_SECRET_ACCESS_KEY=your_secret_access_key

Deploy the infrastructure and get the ECR url (without the repo name)

terraform apply
export ECR_REPOSITORY=$(terraform output ecr_repository | sed 's/\/.*//')

Build and push our Wordpress container to ECR

cd packer
packer build wordpress-packer.json

ECS agents should automatically pull our freshly pushed Wordpress image and start it. Wait a few minutes and point your web-browser to the ELB address:

cd ..
terraform output elb_dns

Technical

We want our wordpress to

  • scale easily
  • be highly available
  • be secure

Making the container stateless

To achieve our goal of easy scalability we want to make our Wordpress container stateless, meaning that no particular data are attached to the host the container is running on. Wordpress text article content is stored on an external database so we're good on this side. We'll use a RDS mysql instance for that. Wordpress static content is stored at path /var/www/html/wp-content of the container. We'll store this on some storage space shared between hosts and mounted in the container. We'll use the EFS service for that (AWS nfs as a service). We'll use an internal route53 DNS zone to associate simple names to our services:

  • db.wordpress.ael for RDS
  • nfs.wordpress.ael for EFS

We also want to put our ECS instances in an autoscaling group and put an ELB with HTTP healthcheck in front of it (cloudwatch alarms for autoscaling not implemented yet).

HA

To achieve HA we'll span our autoscaling group in two different availability zones. Our RDS and NFS services are accessible to those two zones but are not HA, we should add that for production deployement.

Security

We use a dedicated VPC for our project, associate restrictive security groups to instances and put our ECS instances, DB and NFS services in private subnets which access the internet through a NAT (ECS instances need to install nfs-utils at startup and pull ECR repo). Only The ELB resides in the public subnet.

Implemented architecture

(NAT and internet gateway are not shown for clarity purposes)

us-west-2
+--------------------------------------------------------------+
|                                                              |
|           +----------------+    +----------------+           |
|           |         +-----------------+          |           |
|           |         |      |ELB |     |          |           |
|public     |         +-----------------+          | public    |
|us-west-2a +----------------+ || +----------------+ us-west-2b|
|                              ||                              |
|           +----------------+ || +----------------+           |
|           |                | || |                |           |
|           | +------------+ | || | +------------+ |           |
|           | |ECS instance| | || | |ECS instance| |           |
|           | |            +^------^+            | |           |
|           | +-----^----^-+ |    | +-----^-----^+ |           |
|private    |       |    |   |    |       |     |  | private   |
|us-west-2a +----------------+    +----------------+ us—west—2b|
|                   |    |                |     |              |
|                +--+--+ +-------------+--+--+  |              |
|                | RDS |               | EFS |  |              |
|                +-----+               +-----+  |              |
|                      +------------------------+              |
+--------------------------------------------------------------+

To improve

For production deployments, the following should be implemented:

  • extract logs from Wordpress containers (push to elasticsearch/cloudwatch logs...)
  • increase instance capacity (t2.micro currently)
  • increase DB size, monitor remaining space and make backups (5GB at the moment)
  • set up CDN to serve static content (AWS one, clouflare, MaxCDN...)
  • set up Cloudwatch alarms on the ASG so we can really autoscale
  • customize Wordpress image for performance (use nginx, php fpm, tweak perf parameters...)

wordpress-ecs's People

Contributors

ael-g avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.