stockholm - amazon s3decks...php app time of day app. key components: task definitions ......

64
STOCKHOLM ©2015, Amazon Web Services, Inc. or its affiliates. All rights reserved

Upload: dokhue

Post on 14-May-2018

217 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: STOCKHOLM - Amazon S3decks...PHP App Time of day App. Key components: task definitions ... "simple-demo", "image": "my-demo", "cpu": 10, ... STOCKHOLM. Title: Slide 1

STOCKHOLM

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

Page 2: STOCKHOLM - Amazon S3decks...PHP App Time of day App. Key components: task definitions ... "simple-demo", "image": "my-demo", "cpu": 10, ... STOCKHOLM. Title: Slide 1

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

Amazon EC2 Container Service and

AWS CodeDeployJohan Broman

Solutions Architect

Page 3: STOCKHOLM - Amazon S3decks...PHP App Time of day App. Key components: task definitions ... "simple-demo", "image": "my-demo", "cpu": 10, ... STOCKHOLM. Title: Slide 1

Containers

Page 4: STOCKHOLM - Amazon S3decks...PHP App Time of day App. Key components: task definitions ... "simple-demo", "image": "my-demo", "cpu": 10, ... STOCKHOLM. Title: Slide 1

What are containers?

Self contained

Process isolation

OS virtualization

AutomationServer

Guest OS

Bins/Libs Bins/Libs

App2App1

Page 5: STOCKHOLM - Amazon S3decks...PHP App Time of day App. Key components: task definitions ... "simple-demo", "image": "my-demo", "cpu": 10, ... STOCKHOLM. Title: Slide 1

Container advantages

Portable

Server

Guest OS

Bins/Libs Bins/Libs

App2App1

Page 6: STOCKHOLM - Amazon S3decks...PHP App Time of day App. Key components: task definitions ... "simple-demo", "image": "my-demo", "cpu": 10, ... STOCKHOLM. Title: Slide 1

Container advantages

Flexible

Server

Guest OS

Bins/Libs Bins/Libs

App2App1

Page 7: STOCKHOLM - Amazon S3decks...PHP App Time of day App. Key components: task definitions ... "simple-demo", "image": "my-demo", "cpu": 10, ... STOCKHOLM. Title: Slide 1

Container advantages

Fast

Server

Guest OS

Bins/Libs Bins/Libs

App2App1

Page 8: STOCKHOLM - Amazon S3decks...PHP App Time of day App. Key components: task definitions ... "simple-demo", "image": "my-demo", "cpu": 10, ... STOCKHOLM. Title: Slide 1

Container advantages

Efficient

Server

Guest OS

Bins/Libs Bins/Libs

App2App1

Page 9: STOCKHOLM - Amazon S3decks...PHP App Time of day App. Key components: task definitions ... "simple-demo", "image": "my-demo", "cpu": 10, ... STOCKHOLM. Title: Slide 1

Server

Guest OS

Bins/Libs Bins/Libs

App2App1

Page 10: STOCKHOLM - Amazon S3decks...PHP App Time of day App. Key components: task definitions ... "simple-demo", "image": "my-demo", "cpu": 10, ... STOCKHOLM. Title: Slide 1
Page 11: STOCKHOLM - Amazon S3decks...PHP App Time of day App. Key components: task definitions ... "simple-demo", "image": "my-demo", "cpu": 10, ... STOCKHOLM. Title: Slide 1

EC2 Container Service Benefits

Page 12: STOCKHOLM - Amazon S3decks...PHP App Time of day App. Key components: task definitions ... "simple-demo", "image": "my-demo", "cpu": 10, ... STOCKHOLM. Title: Slide 1

Easily manage clusters for any scale

Nothing to run

Complete state

Control and monitoring

Scale

Page 13: STOCKHOLM - Amazon S3decks...PHP App Time of day App. Key components: task definitions ... "simple-demo", "image": "my-demo", "cpu": 10, ... STOCKHOLM. Title: Slide 1

Flexible container placement

Applications

Batch jobs

Multiple schedulers

Page 14: STOCKHOLM - Amazon S3decks...PHP App Time of day App. Key components: task definitions ... "simple-demo", "image": "my-demo", "cpu": 10, ... STOCKHOLM. Title: Slide 1

Designed for use with other AWS services

Elastic Load Balancing

Amazon Elastic Block Store

Amazon Virtual Private Cloud

AWS Identity and Access Management

AWS CloudTrail

Page 15: STOCKHOLM - Amazon S3decks...PHP App Time of day App. Key components: task definitions ... "simple-demo", "image": "my-demo", "cpu": 10, ... STOCKHOLM. Title: Slide 1

Extensible

Comprehensive APIs

Open source agent

Custom schedulers

Page 16: STOCKHOLM - Amazon S3decks...PHP App Time of day App. Key components: task definitions ... "simple-demo", "image": "my-demo", "cpu": 10, ... STOCKHOLM. Title: Slide 1

EC2 Container Service Terminology

Page 17: STOCKHOLM - Amazon S3decks...PHP App Time of day App. Key components: task definitions ... "simple-demo", "image": "my-demo", "cpu": 10, ... STOCKHOLM. Title: Slide 1

Amazon EC2 instances

Docker daemon

Amazon ECS agent

Key components: container instances

Page 18: STOCKHOLM - Amazon S3decks...PHP App Time of day App. Key components: task definitions ... "simple-demo", "image": "my-demo", "cpu": 10, ... STOCKHOLM. Title: Slide 1

Regional

Resource pool

Grouping of container instances

Start empty, dynamically scalable

Key components: clusters

Page 19: STOCKHOLM - Amazon S3decks...PHP App Time of day App. Key components: task definitions ... "simple-demo", "image": "my-demo", "cpu": 10, ... STOCKHOLM. Title: Slide 1

Key components: task definitions

Volume Definitions

Container Definitions

Page 20: STOCKHOLM - Amazon S3decks...PHP App Time of day App. Key components: task definitions ... "simple-demo", "image": "my-demo", "cpu": 10, ... STOCKHOLM. Title: Slide 1

Key components: task definitions

Shared Data Volume

PHP App Time of day App

Page 21: STOCKHOLM - Amazon S3decks...PHP App Time of day App. Key components: task definitions ... "simple-demo", "image": "my-demo", "cpu": 10, ... STOCKHOLM. Title: Slide 1

Key components: task definitions

Container

Instance

Schedule

Shared Data Volume

PHP App Time of day App

Shared Data Volume

PHP

App

Time of

day

App

Page 22: STOCKHOLM - Amazon S3decks...PHP App Time of day App. Key components: task definitions ... "simple-demo", "image": "my-demo", "cpu": 10, ... STOCKHOLM. Title: Slide 1

Key components: task definitions{

"environment": [],

"name": "simple-demo",

"image": "my-demo",

"cpu": 10,

"memory": 500,

"portMappings": [

{

"containerPort": 80,

"hostPort": 80

}

],

"mountPoints": [

{

"sourceVolume": "my-vol",

"containerPath": "/var/www/my-

vol"

}

],

"entryPoint": [

"/usr/sbin/apache2",

"-D",

"FOREGROUND"

],

"essential": true

},

{

"name": "busybox",

"image": "busybox",

"cpu": 10,

"memory": 500,

"volumesFrom": [

{

"sourceContainer": "simple-demo"

}

],

"entryPoint": [

"sh",

"-c"

],

"command": [

"/bin/sh -c \"while true; do

/bin/date > /var/www/my-vol/date; sleep 1; done\""

],

"essential": false

}

Page 23: STOCKHOLM - Amazon S3decks...PHP App Time of day App. Key components: task definitions ... "simple-demo", "image": "my-demo", "cpu": 10, ... STOCKHOLM. Title: Slide 1

{

"environment": [],

"name": "simple-demo",

"image": "amazon/amazon-ecs-sample",

"cpu": 10,

"memory": 500,

"portMappings": [

{

"containerPort": 80,

"hostPort": 80

}

],

"mountPoints": [

{

"sourceVolume": "my-vol",

"containerPath": "/var/www/my-vol"

}

],

"entryPoint": [

"/usr/sbin/apache2",

"-D",

"FOREGROUND"

],

"essential": true

},

Key components: task definitions[

{

"image": "mysql",

"name": "db",

"cpu": 10,

"memory": 500,

"essential": true,

"entryPoint": [

"/entrypoint.sh"

],

"environment": [

{

"name": "MYSQL_ROOT_PASSWORD",

"value": "pass"

}

],

"portMappings": []

}

]

Essential to our task

Create and mount volumes

Expose port 80 in container

to port 80 on host

10 CPU units (1024 is full CPU),

500 megabytes of memory

Page 24: STOCKHOLM - Amazon S3decks...PHP App Time of day App. Key components: task definitions ... "simple-demo", "image": "my-demo", "cpu": 10, ... STOCKHOLM. Title: Slide 1

{

"name": "busybox",

"image": "busybox",

"cpu": 10,

"memory": 500,

"volumesFrom": [

{

"sourceContainer": "simple-demo"

}

],

"entryPoint": [

"sh",

"-c"

],

"command": [

"/bin/sh -c \"while true; do

/bin/date > /var/www/my-vol/date; sleep 1; done\""

],

"essential": false

}

Key components: task definitions[

{

"image": "tutum/wordpress-stackable",

"name": "wordpress",

"cpu": 10,

"memory": 500,

"essential": true,

"links": [

"db"

],

"entryPoint": [

"/bin/sh",

"-c"

],

"environment": [

],

"portMappings": [

{

"containerPort": 80,

"hostPort": 80

}

]

},

]

From Docker Hub

Mount volume from other container

Command to exec

Page 25: STOCKHOLM - Amazon S3decks...PHP App Time of day App. Key components: task definitions ... "simple-demo", "image": "my-demo", "cpu": 10, ... STOCKHOLM. Title: Slide 1

Unit of work

Grouping of related containers

Run on container instances

Key components: tasks

Page 26: STOCKHOLM - Amazon S3decks...PHP App Time of day App. Key components: task definitions ... "simple-demo", "image": "my-demo", "cpu": 10, ... STOCKHOLM. Title: Slide 1

Key components: run a task

Good for short-lived

containers, for

example batch jobs

Page 27: STOCKHOLM - Amazon S3decks...PHP App Time of day App. Key components: task definitions ... "simple-demo", "image": "my-demo", "cpu": 10, ... STOCKHOLM. Title: Slide 1

Key components: create a service

Good for long-

running applications

and services

Page 28: STOCKHOLM - Amazon S3decks...PHP App Time of day App. Key components: task definitions ... "simple-demo", "image": "my-demo", "cpu": 10, ... STOCKHOLM. Title: Slide 1

EC2 Container Service

Manages containers

Handles scale

Schedules containers

Integrated with AWS services

Page 29: STOCKHOLM - Amazon S3decks...PHP App Time of day App. Key components: task definitions ... "simple-demo", "image": "my-demo", "cpu": 10, ... STOCKHOLM. Title: Slide 1

AWS at Klarna

Our journey

Page 30: STOCKHOLM - Amazon S3decks...PHP App Time of day App. Key components: task definitions ... "simple-demo", "image": "my-demo", "cpu": 10, ... STOCKHOLM. Title: Slide 1

What we started with

● Microservices

● Mostly Java (Dropwizard)

● Build Pipelines

● Zero downtime deployments

● Teams do (almost) everything

● Internal Cloud

Page 31: STOCKHOLM - Amazon S3decks...PHP App Time of day App. Key components: task definitions ... "simple-demo", "image": "my-demo", "cpu": 10, ... STOCKHOLM. Title: Slide 1

Going AWS

● Almost no prior knowledge in the team

● Simplicity is key

● Help from a ruby team in Tel Aviv

Page 32: STOCKHOLM - Amazon S3decks...PHP App Time of day App. Key components: task definitions ... "simple-demo", "image": "my-demo", "cpu": 10, ... STOCKHOLM. Title: Slide 1

First version

● Manually upload jar files and run them

Page 33: STOCKHOLM - Amazon S3decks...PHP App Time of day App. Key components: task definitions ... "simple-demo", "image": "my-demo", "cpu": 10, ... STOCKHOLM. Title: Slide 1

Automation of machine creation

● Lets build a general cloudformation template for

everyone!

Page 34: STOCKHOLM - Amazon S3decks...PHP App Time of day App. Key components: task definitions ... "simple-demo", "image": "my-demo", "cpu": 10, ... STOCKHOLM. Title: Slide 1

Automation of machine creation

Lets build a general cloudformation template for

everyone!

If statements in json

Page 35: STOCKHOLM - Amazon S3decks...PHP App Time of day App. Key components: task definitions ... "simple-demo", "image": "my-demo", "cpu": 10, ... STOCKHOLM. Title: Slide 1

Automation of machine creation

● Specific cloudformation template for each

service

● Parameter File to differentiate between

environments

Page 36: STOCKHOLM - Amazon S3decks...PHP App Time of day App. Key components: task definitions ... "simple-demo", "image": "my-demo", "cpu": 10, ... STOCKHOLM. Title: Slide 1

Provisioning

● Continue with Chef?

Page 37: STOCKHOLM - Amazon S3decks...PHP App Time of day App. Key components: task definitions ... "simple-demo", "image": "my-demo", "cpu": 10, ... STOCKHOLM. Title: Slide 1

Provisioning

Lets start with bash

● install yum repo

● yum install

● start service

Run it from cloudformation

moved a lot to into the image, packer is great.

Page 38: STOCKHOLM - Amazon S3decks...PHP App Time of day App. Key components: task definitions ... "simple-demo", "image": "my-demo", "cpu": 10, ... STOCKHOLM. Title: Slide 1

Provisioning, upgrading

● Min Instance count 3 (one in each zone)

● Launch new instances

● Let autoscaling kill Oldest

Page 39: STOCKHOLM - Amazon S3decks...PHP App Time of day App. Key components: task definitions ... "simple-demo", "image": "my-demo", "cpu": 10, ... STOCKHOLM. Title: Slide 1

Provisioning, upgrading

● Specify application version as a parameter

● Cloudformation rolling upgrade

Page 40: STOCKHOLM - Amazon S3decks...PHP App Time of day App. Key components: task definitions ... "simple-demo", "image": "my-demo", "cpu": 10, ... STOCKHOLM. Title: Slide 1

Monitoring

● Previously OP5/Nagios

o Hard when replacing machines often

o Hard to know when a service is up

Page 41: STOCKHOLM - Amazon S3decks...PHP App Time of day App. Key components: task definitions ... "simple-demo", "image": "my-demo", "cpu": 10, ... STOCKHOLM. Title: Slide 1

Monitoring

● Finds instances automatically based on tags

● Finds monitoring port automatically based on

security groups

● API to be used from OP5

Page 42: STOCKHOLM - Amazon S3decks...PHP App Time of day App. Key components: task definitions ... "simple-demo", "image": "my-demo", "cpu": 10, ... STOCKHOLM. Title: Slide 1

Current state

● Cloudformation checked in

● Template per service, parameter file per

environment

● Jenkins builds docker image, update-stack

● Provision with bash

● Most services run in docker

Page 43: STOCKHOLM - Amazon S3decks...PHP App Time of day App. Key components: task definitions ... "simple-demo", "image": "my-demo", "cpu": 10, ... STOCKHOLM. Title: Slide 1

Next step

● Docker everything

● Run multiple docker images on same host

● Speed up deployment (currently 10 minutes)

● ECS

Page 44: STOCKHOLM - Amazon S3decks...PHP App Time of day App. Key components: task definitions ... "simple-demo", "image": "my-demo", "cpu": 10, ... STOCKHOLM. Title: Slide 1

AWS CodeDeploy

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

Page 45: STOCKHOLM - Amazon S3decks...PHP App Time of day App. Key components: task definitions ... "simple-demo", "image": "my-demo", "cpu": 10, ... STOCKHOLM. Title: Slide 1

Why use a deployment service?

Automate

deployments

Manage

complexity

Avoid

downtime

Page 46: STOCKHOLM - Amazon S3decks...PHP App Time of day App. Key components: task definitions ... "simple-demo", "image": "my-demo", "cpu": 10, ... STOCKHOLM. Title: Slide 1

CodeDeploy

• Scale from 1 instance to thousands

• Deploy without downtime

• Centralize deployment control and monitoring

Staging

CodeDeployv1, v2, v3

Production

Dev

Coordinate automated deployments, just like Amazon

Application

revisions

Deployment groups

Page 47: STOCKHOLM - Amazon S3decks...PHP App Time of day App. Key components: task definitions ... "simple-demo", "image": "my-demo", "cpu": 10, ... STOCKHOLM. Title: Slide 1

Step 1: Package your application (with an AppSpec

file)

version: 0.0

os: linux

files:

- source: chef/

destination: /etc/chef/codedeploy

- source: target/hello.war

destination: /var/lib/tomcat6/webapps

hooks:

ApplicationStop:

- location: deploy_hooks/stop-tomcat.sh

BeforeInstall:

- location: deploy_hooks/install-chef.sh

AfterInstall:

- location: deploy_hooks/librarian-install.sh

ApplicationStart:

- location: deploy_hooks/chef-solo.sh

ValidateService:

- location: deploy_hooks/verify_service.sh

Page 48: STOCKHOLM - Amazon S3decks...PHP App Time of day App. Key components: task definitions ... "simple-demo", "image": "my-demo", "cpu": 10, ... STOCKHOLM. Title: Slide 1

Step 1: Package your application (with an AppSpec

file)

version: 0.0

os: linux

files:

- source: chef/

destination: /etc/chef/codedeploy

- source: target/hello.war

destination: /var/lib/tomcat6/webapps

hooks:

ApplicationStop:

- location: deploy_hooks/stop-tomcat.sh

BeforeInstall:

- location: deploy_hooks/install-chef.sh

AfterInstall:

- location: deploy_hooks/librarian-install.sh

ApplicationStart:

- location: deploy_hooks/chef-solo.sh

ValidateService:

- location: deploy_hooks/verify_service.sh

Page 49: STOCKHOLM - Amazon S3decks...PHP App Time of day App. Key components: task definitions ... "simple-demo", "image": "my-demo", "cpu": 10, ... STOCKHOLM. Title: Slide 1

Step 1: Package your application (with an AppSpec

file)

version: 0.0

os: linux

files:

- source: chef/

destination: /etc/chef/codedeploy

- source: target/hello.war

destination: /var/lib/tomcat6/webapps

hooks:

ApplicationStop:

- location: deploy_hooks/stop-tomcat.sh

BeforeInstall:

- location: deploy_hooks/install-chef.sh

AfterInstall:

- location: deploy_hooks/librarian-install.sh

ApplicationStart:

- location: deploy_hooks/chef-solo.sh

ValidateService:

- location: deploy_hooks/verify_service.sh

Page 50: STOCKHOLM - Amazon S3decks...PHP App Time of day App. Key components: task definitions ... "simple-demo", "image": "my-demo", "cpu": 10, ... STOCKHOLM. Title: Slide 1

Step 2: Set up your target environments

Agent Agent Agent

Staging

Agent Agent

Agent Agent

Agent

Agent

Production

Deployment groupDeployment group

Group instances by:

• Auto Scaling group

• Amazon EC2 tag

• On-premises tag

Page 51: STOCKHOLM - Amazon S3decks...PHP App Time of day App. Key components: task definitions ... "simple-demo", "image": "my-demo", "cpu": 10, ... STOCKHOLM. Title: Slide 1

Step 3: Deploy!

aws deploy create-deployment \

--application-name MyApp \

--deployment-group-name TargetGroup \

--s3-location bucket=MyBucket,key=MyApp.zip

AWS CLI & SDKs

AWS Console

CI / CD Partners

GitHub

Page 52: STOCKHOLM - Amazon S3decks...PHP App Time of day App. Key components: task definitions ... "simple-demo", "image": "my-demo", "cpu": 10, ... STOCKHOLM. Title: Slide 1

Deployment config – Choose speed

v2 v1 v1 v1 v1 v1 v1 v1

v2 v2 v2 v2 v1 v1 v1 v1

v2 v2 v2 v2 v2 v2 v2 v2

One-at-a-time

Half-at-a-time

All-at-once

Page 53: STOCKHOLM - Amazon S3decks...PHP App Time of day App. Key components: task definitions ... "simple-demo", "image": "my-demo", "cpu": 10, ... STOCKHOLM. Title: Slide 1

Rolling update – Deploy without downtime

v1v1 v1

Load Balancer

Page 54: STOCKHOLM - Amazon S3decks...PHP App Time of day App. Key components: task definitions ... "simple-demo", "image": "my-demo", "cpu": 10, ... STOCKHOLM. Title: Slide 1

Rolling update – Deploy without downtime

v1v2 v1

Load Balancer

Page 55: STOCKHOLM - Amazon S3decks...PHP App Time of day App. Key components: task definitions ... "simple-demo", "image": "my-demo", "cpu": 10, ... STOCKHOLM. Title: Slide 1

Rolling update – Deploy without downtime

v2v2 v1

Load Balancer

Page 56: STOCKHOLM - Amazon S3decks...PHP App Time of day App. Key components: task definitions ... "simple-demo", "image": "my-demo", "cpu": 10, ... STOCKHOLM. Title: Slide 1

Rolling update – Deploy without downtime

v2v2v2

Load Balancer

Page 57: STOCKHOLM - Amazon S3decks...PHP App Time of day App. Key components: task definitions ... "simple-demo", "image": "my-demo", "cpu": 10, ... STOCKHOLM. Title: Slide 1

Rolling update – Deploy without downtime

v2v2 v2

Load Balancer

Page 58: STOCKHOLM - Amazon S3decks...PHP App Time of day App. Key components: task definitions ... "simple-demo", "image": "my-demo", "cpu": 10, ... STOCKHOLM. Title: Slide 1

Health Tracking – Catch deployment problems

v2v2 v2

Load Balancer

Page 59: STOCKHOLM - Amazon S3decks...PHP App Time of day App. Key components: task definitions ... "simple-demo", "image": "my-demo", "cpu": 10, ... STOCKHOLM. Title: Slide 1

Health tracking – Catch deployment problems

v3 v2 v2Stop

Load Balancer

Page 60: STOCKHOLM - Amazon S3decks...PHP App Time of day App. Key components: task definitions ... "simple-demo", "image": "my-demo", "cpu": 10, ... STOCKHOLM. Title: Slide 1

Health tracking – Catch deployment problems

v2v2 v2

Load Balancer

Rollback

Page 61: STOCKHOLM - Amazon S3decks...PHP App Time of day App. Key components: task definitions ... "simple-demo", "image": "my-demo", "cpu": 10, ... STOCKHOLM. Title: Slide 1

Health tracking – Catch deployment problems

v2v2 v2

Load Balancer

Page 62: STOCKHOLM - Amazon S3decks...PHP App Time of day App. Key components: task definitions ... "simple-demo", "image": "my-demo", "cpu": 10, ... STOCKHOLM. Title: Slide 1

Product integrations

Page 63: STOCKHOLM - Amazon S3decks...PHP App Time of day App. Key components: task definitions ... "simple-demo", "image": "my-demo", "cpu": 10, ... STOCKHOLM. Title: Slide 1

Useful links

• EC2 Container Service– http://aws.amazon.com/ecs/details/

• AWS CodeDeploy– http://aws.amazon.com/codedeploy/details/

– https://blogs.aws.amazon.com/application-

management/post/Tx33XKAKURCCW83/Automatically-Deploy-

from-GitHub-Using-AWS-CodeDeploy

Page 64: STOCKHOLM - Amazon S3decks...PHP App Time of day App. Key components: task definitions ... "simple-demo", "image": "my-demo", "cpu": 10, ... STOCKHOLM. Title: Slide 1

STOCKHOLM