43
© 2015, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Eric Holmes & Michael Barrett, Remind October 2015 DVO308 Docker & ECS in Production How We Migrated Our Infrastructure from Heroku to AWS

(DVO308) Docker & ECS in Production: How We Migrated Our Infrastructure from Heroku to AWS

Embed Size (px)

Citation preview

Page 1: (DVO308) Docker & ECS in Production: How We Migrated Our Infrastructure from Heroku to AWS

© 2015, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

Eric Holmes & Michael Barrett, Remind

October 2015

DVO308

Docker & ECS in ProductionHow We Migrated Our Infrastructure from Heroku to AWS

Page 2: (DVO308) Docker & ECS in Production: How We Migrated Our Infrastructure from Heroku to AWS

What to Expect from the Session

• A brief introduction about why we decided to build an

internal platform at Remind, and the lessons we learned

along the way

• An introduction to the open source PaaS we built called

Empire, and how we’re leveraging Amazon ECS

• Demo

• Q&A

Page 3: (DVO308) Docker & ECS in Production: How We Migrated Our Infrastructure from Heroku to AWS

About Us

• Eric Holmes & Michael Barrett

• Infrastructure engineers at Remind

• We build things for developers

• You can find our open source stuff at:

• https://github.com/ejholmes

• https://github.com/phobologic

Page 4: (DVO308) Docker & ECS in Production: How We Migrated Our Infrastructure from Heroku to AWS

Remind

• A messaging platform for teachers.

• Chat/announcements/files

• Over 30 million users

• Used actively in ~50% of U.S. public schools

• Over 2 billion messages delivered

• ~50 employees. ~30 engineers.

Page 5: (DVO308) Docker & ECS in Production: How We Migrated Our Infrastructure from Heroku to AWS

A Little History

Page 6: (DVO308) Docker & ECS in Production: How We Migrated Our Infrastructure from Heroku to AWS

A Little History

• Started as a “monorail”

• Scaling challenges during BTS

• Migrated to an SOA/micro-service architecture

Page 7: (DVO308) Docker & ECS in Production: How We Migrated Our Infrastructure from Heroku to AWS

Heroku was great, but…

• Every app on Heroku is publicly accessible

• Databases need to be exposed to Internet traffic

• Limited visibility and control

Page 8: (DVO308) Docker & ECS in Production: How We Migrated Our Infrastructure from Heroku to AWS

What we want from a PaaS

• AWS

• Flexibility

• Shared patterns for deployment

• Easy service operation

• Containers/Docker

Page 9: (DVO308) Docker & ECS in Production: How We Migrated Our Infrastructure from Heroku to AWS

Why Containers?

• Fast build + deploy iteration cycles

• Isolate dependencies

• Better dev/prod parity

• Immutable images

• Better resource utilization

Page 10: (DVO308) Docker & ECS in Production: How We Migrated Our Infrastructure from Heroku to AWS

Building an Empire

Page 11: (DVO308) Docker & ECS in Production: How We Migrated Our Infrastructure from Heroku to AWS

Design Goals

• Easy to operate

• Open source

• Support 12-factor stateless apps (12factor.net)

• Swappable scheduling back-ends

• Stability!

• Docker images as a unit of deployment

Page 12: (DVO308) Docker & ECS in Production: How We Migrated Our Infrastructure from Heroku to AWS

Components of a PaaS

Scheduler Router Control Plane

Page 13: (DVO308) Docker & ECS in Production: How We Migrated Our Infrastructure from Heroku to AWS

Scheduler :: Cluster Management

Join Leave

Page 14: (DVO308) Docker & ECS in Production: How We Migrated Our Infrastructure from Heroku to AWS

Scheduler :: Task Placement

Find Host Run Job

CPU/

Memory

Container

Cluster

Page 15: (DVO308) Docker & ECS in Production: How We Migrated Our Infrastructure from Heroku to AWS

Scheduler :: Task Placement

type App []Process

type Scheduler interface {

Run(App)

Remove(App)

Scale(Process)

Tasks(App) []Task

Stop(Task)

}

Page 16: (DVO308) Docker & ECS in Production: How We Migrated Our Infrastructure from Heroku to AWS

Empire :: V1

Scheduler Router Control Plane

+ Fleet

etcd + registrator + confd

Heroku Platform API

Spec + hk CLI

Page 17: (DVO308) Docker & ECS in Production: How We Migrated Our Infrastructure from Heroku to AWS

Amazon EC2 Container Service

• Managed cluster manager and scheduler

• Supports Docker

• Built-in service scheduler

• Integrates with Elastic Load Balancing

Page 18: (DVO308) Docker & ECS in Production: How We Migrated Our Infrastructure from Heroku to AWS

Amazon EC2 Container Service :: Resources

• Clusters

• Task definitions

• Tasks

• Services

Page 19: (DVO308) Docker & ECS in Production: How We Migrated Our Infrastructure from Heroku to AWS

Scheduler Interface

Run(App)

Remove(App)

Scale(Process)

Tasks(App) []Task

Stop(Task)

Amazon ECS Scheduler Implementation

Amazon ECS API

RegisterTaskDefinition ->

CreateService/UpdateService

DeleteService

UpdateService

ListTasks

StopTask

Page 20: (DVO308) Docker & ECS in Production: How We Migrated Our Infrastructure from Heroku to AWS

Empire :: V2

Scheduler Router Control Plane

ECS ELB

Heroku Platform API

Spec + emp CLI

Page 21: (DVO308) Docker & ECS in Production: How We Migrated Our Infrastructure from Heroku to AWS

Empire :: V2

An open-source, self-hosted PaaS for running

twelve-factor Docker apps backed by AWS

services

Page 22: (DVO308) Docker & ECS in Production: How We Migrated Our Infrastructure from Heroku to AWS

Twelve-Factor

Page 23: (DVO308) Docker & ECS in Production: How We Migrated Our Infrastructure from Heroku to AWS

Twelve-Factor Tenants

I. Codebase

II. Dependencies

III. Config

IV. Backing Services

V. Build, release, run

VI. Processes

VII. Port binding

VIII.Concurrency

IX. Disposability

X. Dev/prod parity

XI. Logs

XII. Admin processes

Page 24: (DVO308) Docker & ECS in Production: How We Migrated Our Infrastructure from Heroku to AWS

12factor :: Dependencies

“Explicitly declare and isolate dependencies”

FROM rubyRUN apt-get install imagemagickRUN bundle install

Page 25: (DVO308) Docker & ECS in Production: How We Migrated Our Infrastructure from Heroku to AWS

12factor :: Build, release, run

“Strictly separate build and run stages”

Empire

Page 26: (DVO308) Docker & ECS in Production: How We Migrated Our Infrastructure from Heroku to AWS

12factor :: Build

$ git push

Page 27: (DVO308) Docker & ECS in Production: How We Migrated Our Infrastructure from Heroku to AWS

12factor :: Release, Run

Config{}

Release

Amazon ECS

Page 28: (DVO308) Docker & ECS in Production: How We Migrated Our Infrastructure from Heroku to AWS

12factor :: Release, Run

$ cat Procfile

web: ./bin/web

worker: ./bin/worker

$ aws ecs list-services

arn:aws:ecs:us-east-1:***:service/api--web

arn:aws:ecs:us-east-1:***:service/api--worker

$ emp deploy org/api:latest

Status: Created v1 release.

Page 29: (DVO308) Docker & ECS in Production: How We Migrated Our Infrastructure from Heroku to AWS

Service Discovery

$ aws ecs describe-services --service api--web

"loadBalancers": [{

"containerName": "web”,

"containerPort": 9001,

"loadBalancerName”: "2888...a31d4c”

}]

$ curl http://api

Ok

Page 30: (DVO308) Docker & ECS in Production: How We Migrated Our Infrastructure from Heroku to AWS

12factor :: Concurrency

“Scale out via the process model”

$ emp scale web=10

$ aws ecs describe-service --service api--web

“desired-count”: 10

Page 31: (DVO308) Docker & ECS in Production: How We Migrated Our Infrastructure from Heroku to AWS

12factor :: Dev/prod parity

“Keep development, staging, and production as similar as

possible”

$ docker run --env-file <(emp env -a api) org/api

Page 32: (DVO308) Docker & ECS in Production: How We Migrated Our Infrastructure from Heroku to AWS

12factor :: Logs

“Treat logs as event streams”

$ emp log

“GET / HTTP/1.1” 200

STDOUT Amazon Kinesis

Page 33: (DVO308) Docker & ECS in Production: How We Migrated Our Infrastructure from Heroku to AWS

12factor :: Admin processes

“Run admin/management tasks as one-off processes”

$ emp run rake db:migrate

Migrated

Page 34: (DVO308) Docker & ECS in Production: How We Migrated Our Infrastructure from Heroku to AWS

Demo

Page 35: (DVO308) Docker & ECS in Production: How We Migrated Our Infrastructure from Heroku to AWS

Pain Points & Lessons Learned

Page 36: (DVO308) Docker & ECS in Production: How We Migrated Our Infrastructure from Heroku to AWS

Container Instance Rollout

1. Update AMI in AWS CloudFormation stack.

2. Kill 1 host

3. Wait for new Amazon ECS services to start running on

new host

4. Rinse and repeat

Page 37: (DVO308) Docker & ECS in Production: How We Migrated Our Infrastructure from Heroku to AWS

Logging

Logspout

Page 38: (DVO308) Docker & ECS in Production: How We Migrated Our Infrastructure from Heroku to AWS

Logging

SOURCE=<app>.<process>.<version>

SYSLOG_STRUCTURED_DATA=app={{ .Container.Config.Env "SOURCE" }}

Page 39: (DVO308) Docker & ECS in Production: How We Migrated Our Infrastructure from Heroku to AWS

Docker Monolith

= Bad Times

Page 40: (DVO308) Docker & ECS in Production: How We Migrated Our Infrastructure from Heroku to AWS

Docker Performance

• Early versions of Docker had abysmal push/pull

performance

• Use Docker >= 1.8.1

• Make your Dockerfile’s use the layer cache efficiently

• https://github.com/remind101/conveyor

Page 41: (DVO308) Docker & ECS in Production: How We Migrated Our Infrastructure from Heroku to AWS

This space moves fast!

• Containers have been around, but Docker made them

accessible

• New tools coming out ever day

• AWS’s offerings have been incredibly stable and feature

rich

Page 42: (DVO308) Docker & ECS in Production: How We Migrated Our Infrastructure from Heroku to AWS

Remember to complete

your evaluations!

Page 43: (DVO308) Docker & ECS in Production: How We Migrated Our Infrastructure from Heroku to AWS

Thank you!