36
12 Factors App with Docker On AWS

12 Factors App and example on AWS7xi8kv.com5.z0.glb.qiniucdn.com/12 Factors App and example on AWS.pdfAMI: Amazon Machine Image ELB: Elastic Load Balancer ASG: Auto Scaling Group Cloudwatch:

  • Upload
    others

  • View
    6

  • Download
    0

Embed Size (px)

Citation preview

Page 1: 12 Factors App and example on AWS7xi8kv.com5.z0.glb.qiniucdn.com/12 Factors App and example on AWS.pdfAMI: Amazon Machine Image ELB: Elastic Load Balancer ASG: Auto Scaling Group Cloudwatch:

12 Factors App with Docker On AWS

Page 2: 12 Factors App and example on AWS7xi8kv.com5.z0.glb.qiniucdn.com/12 Factors App and example on AWS.pdfAMI: Amazon Machine Image ELB: Elastic Load Balancer ASG: Auto Scaling Group Cloudwatch:

ThoughtWorks Senior Consultant

Web/RoR/Java/Scala Developer, 3 years DevOps

Book Translation <Scala Cookbook>

AWS Certified Associate Solution Architect

About Me : Ma Bowen

Page 3: 12 Factors App and example on AWS7xi8kv.com5.z0.glb.qiniucdn.com/12 Factors App and example on AWS.pdfAMI: Amazon Machine Image ELB: Elastic Load Balancer ASG: Auto Scaling Group Cloudwatch:

12facters.net

Page 4: 12 Factors App and example on AWS7xi8kv.com5.z0.glb.qiniucdn.com/12 Factors App and example on AWS.pdfAMI: Amazon Machine Image ELB: Elastic Load Balancer ASG: Auto Scaling Group Cloudwatch:

Methodology for building Web Apps

Use declarative formats for setup automation

Maximum portability between execution environments

Suitable for deployment on modern cloud platforms

keep environment consistence, continuous deployment

Scale with few changes to tooling/architecture etc

Page 5: 12 Factors App and example on AWS7xi8kv.com5.z0.glb.qiniucdn.com/12 Factors App and example on AWS.pdfAMI: Amazon Machine Image ELB: Elastic Load Balancer ASG: Auto Scaling Group Cloudwatch:

One Codebase, Multiple Deploys

Page 6: 12 Factors App and example on AWS7xi8kv.com5.z0.glb.qiniucdn.com/12 Factors App and example on AWS.pdfAMI: Amazon Machine Image ELB: Elastic Load Balancer ASG: Auto Scaling Group Cloudwatch:

Explicitly declare & isolate dependencies

Ruby Gemfile, e.g `bundle install —path=vendor/bundle`

Debian/RPM

Page 7: 12 Factors App and example on AWS7xi8kv.com5.z0.glb.qiniucdn.com/12 Factors App and example on AWS.pdfAMI: Amazon Machine Image ELB: Elastic Load Balancer ASG: Auto Scaling Group Cloudwatch:

Store Config in Environment

Staging ProductionTest

DB_HOST: testdbDB_USR: readwriteDB_PASS:123456

DB_HOST: stgdbDB_USR: stgrwDB_PASS:password

DB_HOST: proddbDB_USR: prodrwDB_PASS:password&

Page 8: 12 Factors App and example on AWS7xi8kv.com5.z0.glb.qiniucdn.com/12 Factors App and example on AWS.pdfAMI: Amazon Machine Image ELB: Elastic Load Balancer ASG: Auto Scaling Group Cloudwatch:

Backing services as attached resources

Page 9: 12 Factors App and example on AWS7xi8kv.com5.z0.glb.qiniucdn.com/12 Factors App and example on AWS.pdfAMI: Amazon Machine Image ELB: Elastic Load Balancer ASG: Auto Scaling Group Cloudwatch:

Build release run

Page 10: 12 Factors App and example on AWS7xi8kv.com5.z0.glb.qiniucdn.com/12 Factors App and example on AWS.pdfAMI: Amazon Machine Image ELB: Elastic Load Balancer ASG: Auto Scaling Group Cloudwatch:

Processes

The app is executed in the execution environment as one or more processes.

Twelve-factor processes are stateless and share-nothing

Page 11: 12 Factors App and example on AWS7xi8kv.com5.z0.glb.qiniucdn.com/12 Factors App and example on AWS.pdfAMI: Amazon Machine Image ELB: Elastic Load Balancer ASG: Auto Scaling Group Cloudwatch:

Port BindingThe twelve-factor app is completely self-contained

and does not rely on runtime injection of a webserver into the execution environment to create

a web-facing service.

Page 12: 12 Factors App and example on AWS7xi8kv.com5.z0.glb.qiniucdn.com/12 Factors App and example on AWS.pdfAMI: Amazon Machine Image ELB: Elastic Load Balancer ASG: Auto Scaling Group Cloudwatch:

Concurrency

Twelve-factor app processes should never daemonize or write PID files. Instead, rely on the operating system’s process manager (such as Upstart, a distributed process manager on a cloud

Page 13: 12 Factors App and example on AWS7xi8kv.com5.z0.glb.qiniucdn.com/12 Factors App and example on AWS.pdfAMI: Amazon Machine Image ELB: Elastic Load Balancer ASG: Auto Scaling Group Cloudwatch:

Disposability

Maximize robustness with fast startup and graceful shutdown

Page 14: 12 Factors App and example on AWS7xi8kv.com5.z0.glb.qiniucdn.com/12 Factors App and example on AWS.pdfAMI: Amazon Machine Image ELB: Elastic Load Balancer ASG: Auto Scaling Group Cloudwatch:

Dev/prod parity

Page 15: 12 Factors App and example on AWS7xi8kv.com5.z0.glb.qiniucdn.com/12 Factors App and example on AWS.pdfAMI: Amazon Machine Image ELB: Elastic Load Balancer ASG: Auto Scaling Group Cloudwatch:

Logs

Treat logs as event streams,A twelve-factor app never concerns itself with routing or storage of its

output stream.

Page 16: 12 Factors App and example on AWS7xi8kv.com5.z0.glb.qiniucdn.com/12 Factors App and example on AWS.pdfAMI: Amazon Machine Image ELB: Elastic Load Balancer ASG: Auto Scaling Group Cloudwatch:

Admin processes

ASGScheduled action

Instance

One Off task

Run admin/management tasks as one-off processes

Page 17: 12 Factors App and example on AWS7xi8kv.com5.z0.glb.qiniucdn.com/12 Factors App and example on AWS.pdfAMI: Amazon Machine Image ELB: Elastic Load Balancer ASG: Auto Scaling Group Cloudwatch:

How do we apply this on AWS with Docker

Page 18: 12 Factors App and example on AWS7xi8kv.com5.z0.glb.qiniucdn.com/12 Factors App and example on AWS.pdfAMI: Amazon Machine Image ELB: Elastic Load Balancer ASG: Auto Scaling Group Cloudwatch:

Some Context

Years Ago Now

Dev | Ops DevOps,Cross Functional team

8 teams 40+ teams

monoliths micro services(decomissioning )

2 Data Centers 2 DC + 100 AWS accounts

Ops Deploying TMI && Continuous Delivery

Page 19: 12 Factors App and example on AWS7xi8kv.com5.z0.glb.qiniucdn.com/12 Factors App and example on AWS.pdfAMI: Amazon Machine Image ELB: Elastic Load Balancer ASG: Auto Scaling Group Cloudwatch:

Some Glossaries

AMI: Amazon Machine Image

ELB: Elastic Load Balancer

ASG: Auto Scaling Group

Cloudwatch: AWS Monitoring Service

CloudFormation: Manage AWS resources with JSON template

Newrelic: Application Monitoring

Splunk: Enterprise Log Aggregator

Page 20: 12 Factors App and example on AWS7xi8kv.com5.z0.glb.qiniucdn.com/12 Factors App and example on AWS.pdfAMI: Amazon Machine Image ELB: Elastic Load Balancer ASG: Auto Scaling Group Cloudwatch:

Continuous Delivery Before

Page 21: 12 Factors App and example on AWS7xi8kv.com5.z0.glb.qiniucdn.com/12 Factors App and example on AWS.pdfAMI: Amazon Machine Image ELB: Elastic Load Balancer ASG: Auto Scaling Group Cloudwatch:

Commit CI

Processes

base AMI

RPM

AMIstaging config

Appuser-data

staging

AMIprod config

Appuser-data

production

Page 22: 12 Factors App and example on AWS7xi8kv.com5.z0.glb.qiniucdn.com/12 Factors App and example on AWS.pdfAMI: Amazon Machine Image ELB: Elastic Load Balancer ASG: Auto Scaling Group Cloudwatch:

ConsPackaging twice, RPM/AMI

Duplicated effort for automate deployment

Not good for succession plan

Dev/Test/Staging/Prod different

Page 23: 12 Factors App and example on AWS7xi8kv.com5.z0.glb.qiniucdn.com/12 Factors App and example on AWS.pdfAMI: Amazon Machine Image ELB: Elastic Load Balancer ASG: Auto Scaling Group Cloudwatch:

Docker - FTW

Page 24: 12 Factors App and example on AWS7xi8kv.com5.z0.glb.qiniucdn.com/12 Factors App and example on AWS.pdfAMI: Amazon Machine Image ELB: Elastic Load Balancer ASG: Auto Scaling Group Cloudwatch:

Commit CI Docker Image App

Expected

auto-rollback

logging

monitoring

0-downtime deployment

Page 25: 12 Factors App and example on AWS7xi8kv.com5.z0.glb.qiniucdn.com/12 Factors App and example on AWS.pdfAMI: Amazon Machine Image ELB: Elastic Load Balancer ASG: Auto Scaling Group Cloudwatch:

AIM of shipper

Standardising and simplify the way we deploy

Portable between teams and account

Page 26: 12 Factors App and example on AWS7xi8kv.com5.z0.glb.qiniucdn.com/12 Factors App and example on AWS.pdfAMI: Amazon Machine Image ELB: Elastic Load Balancer ASG: Auto Scaling Group Cloudwatch:

shipper.yml

Page 27: 12 Factors App and example on AWS7xi8kv.com5.z0.glb.qiniucdn.com/12 Factors App and example on AWS.pdfAMI: Amazon Machine Image ELB: Elastic Load Balancer ASG: Auto Scaling Group Cloudwatch:

<app/>

$CONFIG

ngin

x

log collector

requests

SplunkNew Relic

generic AMI

supporting services

your application

docker-registry

Any web applicationany web-app framework any programming language any Linux variant

Splunk supportcaptures stdout/stderr no app support required

New Relic supportapplication monitoring system monitoring deployment notification

CloudWatch supportalerts you when service is down via email or web-hook

Auto-scalingmultiple servers load-balancing support for scaling schedules

Zero-downtime deploymentssafe upgrades safe config changes

Page 28: 12 Factors App and example on AWS7xi8kv.com5.z0.glb.qiniucdn.com/12 Factors App and example on AWS.pdfAMI: Amazon Machine Image ELB: Elastic Load Balancer ASG: Auto Scaling Group Cloudwatch:

<app/>

$CONFIG

ngin

x

log collector

requests

SplunkNew Relic

generic AMI

supporting services

your application

docker-registry

Page 29: 12 Factors App and example on AWS7xi8kv.com5.z0.glb.qiniucdn.com/12 Factors App and example on AWS.pdfAMI: Amazon Machine Image ELB: Elastic Load Balancer ASG: Auto Scaling Group Cloudwatch:

Actual Process

Page 30: 12 Factors App and example on AWS7xi8kv.com5.z0.glb.qiniucdn.com/12 Factors App and example on AWS.pdfAMI: Amazon Machine Image ELB: Elastic Load Balancer ASG: Auto Scaling Group Cloudwatch:

shipper.yml cf templateshipper cf configupdate

app image

AWS resources

env vars

app image

Page 31: 12 Factors App and example on AWS7xi8kv.com5.z0.glb.qiniucdn.com/12 Factors App and example on AWS.pdfAMI: Amazon Machine Image ELB: Elastic Load Balancer ASG: Auto Scaling Group Cloudwatch:

Immutable Deployment (1/2)

Page 32: 12 Factors App and example on AWS7xi8kv.com5.z0.glb.qiniucdn.com/12 Factors App and example on AWS.pdfAMI: Amazon Machine Image ELB: Elastic Load Balancer ASG: Auto Scaling Group Cloudwatch:

Immutable Deployment (2/2)

Page 33: 12 Factors App and example on AWS7xi8kv.com5.z0.glb.qiniucdn.com/12 Factors App and example on AWS.pdfAMI: Amazon Machine Image ELB: Elastic Load Balancer ASG: Auto Scaling Group Cloudwatch:

Docker V2 registry

Page 34: 12 Factors App and example on AWS7xi8kv.com5.z0.glb.qiniucdn.com/12 Factors App and example on AWS.pdfAMI: Amazon Machine Image ELB: Elastic Load Balancer ASG: Auto Scaling Group Cloudwatch:

Deployed 70+ systems

Page 35: 12 Factors App and example on AWS7xi8kv.com5.z0.glb.qiniucdn.com/12 Factors App and example on AWS.pdfAMI: Amazon Machine Image ELB: Elastic Load Balancer ASG: Auto Scaling Group Cloudwatch:

Next StepSupport batched jobs

ECS/ECR

Swarm/Kubernates

Page 36: 12 Factors App and example on AWS7xi8kv.com5.z0.glb.qiniucdn.com/12 Factors App and example on AWS.pdfAMI: Amazon Machine Image ELB: Elastic Load Balancer ASG: Auto Scaling Group Cloudwatch:

Fin

[email protected]