february 2016 webinar series - ec2 container service deep dive

58
© 2015, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Pierre Steckmeyer, Solutions Architect Feb.23, 2016 Amazon EC2 Container Service Deep Dive

Upload: amazon-web-services

Post on 06-Apr-2017

2.644 views

Category:

Technology


1 download

TRANSCRIPT

Page 1: February 2016 Webinar Series - EC2 Container Service Deep Dive

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

Pierre Steckmeyer, Solutions Architect

Feb.23, 2016

Amazon EC2 Container Service Deep Dive

Page 2: February 2016 Webinar Series - EC2 Container Service Deep Dive

Agenda

Containers and Amazon ECS Benefits ECS Clusters ECS Tasks ECS Services Solutions Built on Amazon ECS

Page 3: February 2016 Webinar Series - EC2 Container Service Deep Dive

Why Containers?

Page 4: February 2016 Webinar Series - EC2 Container Service Deep Dive

Container Benefits

Portable

Flexible

Fast

Efficient

Server

Guest OS

Bins/Libs Bins/Libs

App2App1

Page 5: February 2016 Webinar Series - EC2 Container Service Deep Dive

Why Amazon ECS?

Page 6: February 2016 Webinar Series - EC2 Container Service Deep Dive

Amazon ECS Benefits

Easily Manage Clusters for Any Scale Flexible Container Placement Designed for Use with Other AWS Services Extensible

Page 7: February 2016 Webinar Series - EC2 Container Service Deep Dive

Clusters

Regional Resource Pool Grouping of Container Instances Start Empty, Dynamically Scalable

Page 8: February 2016 Webinar Series - EC2 Container Service Deep Dive

Tasks

Unit of Work Grouping of Related Containers Run on Container Instances

Page 9: February 2016 Webinar Series - EC2 Container Service Deep Dive

Services

Good for Long-Running Applications Load Balance Traffic across Containers Automatically Recover Unhealthy Containers Discover Services

Page 10: February 2016 Webinar Series - EC2 Container Service Deep Dive

ECS Clusters

Page 11: February 2016 Webinar Series - EC2 Container Service Deep Dive

ECS Clusters

Setup IAM Roles Monitoring Logging Autoscaling Amazon EC2 Simple Systems Manager (SSM) Provisioning with CloudFormation

Page 12: February 2016 Webinar Series - EC2 Container Service Deep Dive

Setup ECS Cluster with AutoScaling

Create LaunchConfiguration Pick instance type depending on resource requirements, e.g.

memory or CPU Use latest Amazon Linux ECS-optimized AMI, other distros

available

Create AutoScaling Group and Set to Cluster Initial Size

Page 13: February 2016 Webinar Series - EC2 Container Service Deep Dive

ECS IAM Policies and Roles

The ECS agent calls the ECS APIs on your behalf, so container instances require an IAM policy and role that allows these calls.

The ECS service scheduler calls the EC2 and ELB APIs on your behalf to register and deregister container instances with your load balancers.

Use AmazonEC2ContainerServiceforEC2Role and AmazonEC2ContainerServiceRole managed policies (respectively)

Page 14: February 2016 Webinar Series - EC2 Container Service Deep Dive

Monitoring with Amazon CloudWatch

Metric data sent to CloudWatch in 1-minute periods and recorded for a period of two weeks

Available metrics:CPUReservation, MemoryReservation, CPUUtilization, MemoryUtilization

Page 15: February 2016 Webinar Series - EC2 Container Service Deep Dive

Monitoring with Amazon CloudWatch

Page 16: February 2016 Webinar Series - EC2 Container Service Deep Dive

Monitoring with Amazon CloudWatch

Use the Amazon CloudWatch Monitoring Scripts to monitor additional metrics, e.g. disk space:# Edit crontab> crontab -e

# Add command to report disk space utilization to CloudWatch every five minutes*/5 * * * * <path_to>/mon-put-instance-data.pl --disk-space-util --disk-space-used --disk-space-avail --disk-path=/ --from-cron

Page 17: February 2016 Webinar Series - EC2 Container Service Deep Dive

Logging with Amazon CloudWatch Logs

Logging container with syslogd and CloudWatch Logs Agent

Attach /var/log Volume to Logging container

Link Other Containerssyslogd

CloudWatch Logs Agent

CloudWatch Logs

Container instance

ECS Cluster

ECS Agent Logs

Docker Logs

Page 18: February 2016 Webinar Series - EC2 Container Service Deep Dive

AutoScaling your Amazon ECS Cluster

Create CloudWatch alarm on a metric, e.g. MemoryReservation

Configure scaling policies to increase and decrease the size of your cluster

Page 19: February 2016 Webinar Series - EC2 Container Service Deep Dive

Amazon EC2 Simple Systems Manager (SSM)

Use Amazon EC2 SSM to execute commands on container instances, e.g. yum update

Add AmazonEC2RoleForSSM to instances IAM role to process Run Commands

Install SSM Agent Create SSM document

Page 20: February 2016 Webinar Series - EC2 Container Service Deep Dive

Cluster Setup with AWS CloudFormation

CloudFormation supports ECS cluster, service and task definition resources

Use AWS::IAM::Role to create ECS service role and container instances role

Launch container instances using AWS:AutoScaling::LaunchConfiguation and AWS:AutoScaling::AutoScalingGroup

Page 21: February 2016 Webinar Series - EC2 Container Service Deep Dive

Provision Clusters with AWS CloudFormation"Resources" : { "ECSCluster": { "Type": "AWS::ECS::Cluster" }, "ECSAutoScalingGroup" : { "Type" : "AWS::AutoScaling::AutoScalingGroup", "Properties" : { "VPCZoneIdentifier" : { "Ref" : "SubnetID" }, "LaunchConfigurationName" : { "Ref" : "ContainerInstances" }, "MinSize" : "1", "MaxSize" : { "Ref" : "MaxSize" }, "DesiredCapacity" : { "Ref" : "DesiredCapacity" } }, […] },

Page 22: February 2016 Webinar Series - EC2 Container Service Deep Dive

Provision Clusters with AWS CloudFormation "ContainerInstances": { "Type": "AWS::AutoScaling::LaunchConfiguration", "Metadata" : { "AWS::CloudFormation::Init" : { "config" : { "commands" : { "01_add_instance_to_cluster" : { "command" : { "Fn::Join": [ "", [ "#!/bin/bash\n", "echo ECS_CLUSTER=", { "Ref": "ECSCluster" }, " >> /etc/ecs/ecs.config" ] ] } } }, […] } } }

Page 23: February 2016 Webinar Series - EC2 Container Service Deep Dive

ECS Tasks

Page 24: February 2016 Webinar Series - EC2 Container Service Deep Dive

ECS Tasks

Task Definition Amazon EC2 Container Registry

Page 25: February 2016 Webinar Series - EC2 Container Service Deep Dive

ECS Tasks

Group containers used for a common purpose in a single task definition

Separate different components into multiple task definitions

Create services from Task Definition to maintain availability

Page 26: February 2016 Webinar Series - EC2 Container Service Deep Dive

Task Definitions

Volume Definitions

Container Definitions

Page 27: February 2016 Webinar Series - EC2 Container Service Deep Dive

Task Definition

{ "containerDefinitions": [ { "name": "wordpress", "links": [ "mysql" ], "image": "wordpress", "essential": true, "portMappings": [ { "containerPort": 80, "hostPort": 80 } ], "memory": 500, "cpu": 10 },

Page 28: February 2016 Webinar Series - EC2 Container Service Deep Dive

Task Definition

{ "environment": [ { "name": "MYSQL_ROOT_PASSWORD", "value": "password" } ], "name": "mysql", "image": "mysql", "cpu": 10, "memory": 500, "essential": true } ], "family": "hello_world"}

Page 29: February 2016 Webinar Series - EC2 Container Service Deep Dive

Tasks

Shared Data Volume

Containers

scheduleContainer Instance

Volume Definitions

Container Definitions

Page 30: February 2016 Webinar Series - EC2 Container Service Deep Dive

Amazon ECR Setup

You have read and write access to the repositories you create in your default registry, i.e. <aws_account_id>.dkr.ecr.us-east-1.amazonaws.com

Repository names can support namespaces, e.g. team-a/web-app.

Repositories can be controlled with both IAM user access policies and repository policies.

Page 31: February 2016 Webinar Series - EC2 Container Service Deep Dive

Amazon ECR Setup

# Authenticate Docker to your Amazon ECR registry> aws ecr get-logindocker login -u AWS -p <password> -e none https://<aws_account_id>.dkr.ecr.us-east-1.amazonaws.com> docker login -u AWS -p <password> -e none https://<aws_account_id>.dkr.ecr.us-east-1.amazonaws.com

# Create a repository called ecr-demo> aws ecr create-repository --repository-name ecr-demo

# Build or tag an image

# Push an image to your repository> docker push <aws_account_id>.dkr.ecr.us-east-1.amazonaws.com/ecr-demo:v1

Page 32: February 2016 Webinar Series - EC2 Container Service Deep Dive

ECR IAM Policies and Roles

ECR uses resource-based permissions to control access. By default, only the repository owner has access to a

repository. You can apply a policy document that allows others to access

your repository. Use managed policies for IAM users or roles that allow

differing levels of control: AmazonEC2ContainerRegistryFullAccess, AmazonEC2ContainerRegistryPowerUser or AmazonEC2ContainerRegistryReadOnly

Page 33: February 2016 Webinar Series - EC2 Container Service Deep Dive

ECS Services

Page 34: February 2016 Webinar Series - EC2 Container Service Deep Dive

ECS Services

Monitoring Logging Scaling Service discovery Deployment

Page 35: February 2016 Webinar Series - EC2 Container Service Deep Dive

Monitoring with Amazon CloudWatch

Metric data sent to CloudWatch in 1-minute periods and recorded for a period of two weeks

Available metrics:CPUReservation, MemoryReservation, CPUUtilization, MemoryUtilization

Page 36: February 2016 Webinar Series - EC2 Container Service Deep Dive

Monitoring ECS Services with CloudWatch

Page 37: February 2016 Webinar Series - EC2 Container Service Deep Dive

Configuring Logging in Task Definition

logConfiguration task definition parameter Requires version 1.18 or greater of the Docker Remote

API Maps to docker run --log-driver option Log drivers: json-file, syslog, journald, gelf, fluentd

Page 38: February 2016 Webinar Series - EC2 Container Service Deep Dive

Scaling ECS Services with AWS Lambda

Page 39: February 2016 Webinar Series - EC2 Container Service Deep Dive

Service Discovery with Services & Route 53

Task

Task TaskTask

ECS Service

Application router, e.g.

nginx

Internal ELB with CNAME, e.g.

api.example.com

Route 53 private zone, e.g.

example.com

Page 40: February 2016 Webinar Series - EC2 Container Service Deep Dive

Deploying ECS Services

Optionally run your service behind a load balancer. One load balancer per service. ELB currently supports a fixed relationship between the

load balancer port and the container instance port. If a task fails the ELB health check, the task is killed and

restarted (until service reaches desired capacity).

Page 41: February 2016 Webinar Series - EC2 Container Service Deep Dive

Deploying ECS Services

Update service’s task definition (rolling update)

Specify a deployment configuration for your service: minimumHealthyPercent: lower limit (as a percentage of the

service's desiredCount) of the number of running tasks that must remain running in a service during a deployment.

maximumPercent: upper limit (as a percentage of the service's desiredCount) of the number of running tasks that can be running in a service during a deployment.

Page 42: February 2016 Webinar Series - EC2 Container Service Deep Dive

Deploying ECS ServicesDeploy using the least space: minimumHealthyPercent = 50%, maximumPercent = 100%

Page 43: February 2016 Webinar Series - EC2 Container Service Deep Dive

Deploying ECS ServicesDeploy quickly without reducing service capacity: minimumHealthyPercent = 100%, maximumPercent = 200%

Page 44: February 2016 Webinar Series - EC2 Container Service Deep Dive

Deploying ECS Services

Blue-Green deployments: Define two ECS services (Blue and Green) Each service is associated with an ELB Both ELBs in Route 53 record set with weighted routing

policy, 100% Primary, 0% Secondary Deploy to Blue or Green service and switch weights

Page 45: February 2016 Webinar Series - EC2 Container Service Deep Dive

Deploying ECS Services

Route 53 record set with weighted routing policy

TaskTask

0%

100%

Page 46: February 2016 Webinar Series - EC2 Container Service Deep Dive

Deploying ECS Services with Jenkins

Build image

Push image

Update service

Page 47: February 2016 Webinar Series - EC2 Container Service Deep Dive

ECS CI/CD Partners

Page 48: February 2016 Webinar Series - EC2 Container Service Deep Dive

Solutions Built on ECS

Page 49: February 2016 Webinar Series - EC2 Container Service Deep Dive

Solutions Built on ECS

AWS Elastic Beanstalk Convox Remind Empire

Page 50: February 2016 Webinar Series - EC2 Container Service Deep Dive

AWS Elastic Beanstalk Uses Amazon ECS to coordinate deployments to

multicontainer Docker environments Takes care of tasks including cluster creation, task definition

and execution

Page 51: February 2016 Webinar Series - EC2 Container Service Deep Dive

AWS Elastic Beanstalk

Elastic Beanstalk uses a Dockerrun.aws.json file that describes how to deploy containers.

The Dockerrun.aws.json file includes three sections: AWSEBDockerrunVersion: Set to "2" for multicontainer

Docker environments. containerDefinitions: An array of container definitions. volumes: Creates mount points in the container instance that

a container can use.

Page 52: February 2016 Webinar Series - EC2 Container Service Deep Dive

Convox

Page 53: February 2016 Webinar Series - EC2 Container Service Deep Dive

Convox

# Initialize your app and create default manifest> convox init

# Locally build and run your app as declared in the manifest > convox start

# Create app> convox apps create my_app

# Deploy app, output ELB DNS name> convox deploy[...]web: http://my_app-1234567890.us-east-1.elb.amazonaws.com

Page 54: February 2016 Webinar Series - EC2 Container Service Deep Dive

Remind Empire

Control layer on top of Amazon ECS that provides a familiar PaaS workflow

Any tagged Docker image can be deployed to Empire as an app

When you deploy a Docker image to Empire, it will extract a Procfile from the WORKDIR

Each process type in the Procfile maps directly to an ECS Service

Page 55: February 2016 Webinar Series - EC2 Container Service Deep Dive

Remind Empire

Routing Layer Backed by Internal ELBs An application that specifies a web process will get an

internal ELB attached to its ECS Service When a new internal ELB is created, an associated CNAME

record is created in Route53 under the internal TLD, enabling service discovery via DNS

Page 56: February 2016 Webinar Series - EC2 Container Service Deep Dive

Thank you!

Page 57: February 2016 Webinar Series - EC2 Container Service Deep Dive

Additional Resources

ECS CloudFormation Template - http://amzn.to/1KH51m5 ECS CloudWatch Metrics - http://amzn.to/1PUR7OU Scaling Container Instances with CloudWatch Alarms -

http://amzn.to/1ORt06b Service Discovery with Consul - http://amzn.to/1JZL5gz

Continuous Delivery to ECS with Jenkins - http://amzn.to/1GbheTp

Elastic Beanstalk Multicontainer Docker Environment - http://amzn.to/1bAkjxG

Page 58: February 2016 Webinar Series - EC2 Container Service Deep Dive

AWS Summit – Chicago: An exciting, free cloud conference designed to educate and inform new customers about the AWS platform, best practices and new cloud services.

Details• April 18-19, 2016 • Chicago, Illinois• @ McCormick Place

Featuring• New product launches• 50+ sessions, labs, and bootcamps• Executive and partner networking

Register Now• Go to aws.amazon.com/summits• Click on The AWS Summit - Chicago … then register.• Come and see what AWS and the cloud can do for you.

Chicago – April 18-19