running microservices and docker on aws elastic beanstalk - august 2016 monthly webinar series
TRANSCRIPT
© 2015, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Brandon Chavis | Solutions Architect
08/25/2016
AWS Elastic Beanstalk (EB)Deploying Containers on EB
Agenda
Elastic Beanstalk vs DIY
How to use Elastic Beanstalk
Multi-Container Docker with AWS Elastic Beanstalk
Recently added features
Developer Challenges
Complexity of deploying code, provisioning and managing infrastructure
Expertise and time needed to manage and configure servers, databases, load balancers, firewalls, and networks
How to automate application scaling
What is Elastic Beanstalk?
AWS Elastic Beanstalk is an easy-to-use service for deploying and scaling web applications and services.
AWS Elastic Beanstalk vs. Do It Yourself
Your code
HTTP Server
Application Server
Language Interpreter
Operating System
Host
Elastic Beanstalk configures each EC2 instance in your
environment with the components necessary to run applications for the selected
platform.
Focus on building your application
Provided by you
Provided and managed by AWS Elastic Beanstalk (EB)
On-instance configuration
AWS Elastic Beanstalk vs. Do It Yourself
Preconfigured Infrastructure Single Instance (Dev, Low Cost) Load Balanced, Auto Scaling (Production)
Web & Worker tiers Elastic Beanstalk provisions necessary
infrastructure resources such as the load balancer, auto scaling group, security groups, database (optional), etc.
Provides a unique domain name for your application(e.g.: youapp.regionx.elasticbeanstalk.com)
Infrastructure stack
Common Use Cases
Websites
API backends
Mobile backends
Asynchronous workers
Customers
Elastic Beanstalk Benefits
Fast & simple to begin
Developer productivity
Impossible to outgrow
Complete resource control
No additional charge to use. You only pay for underlying AWS resources (i.e.: EC2 instances, S3, etc.)
How do I get startedwith Elastic Beanstalk
01
02
03
04
Region
Stack (container) type
Single Instance Load Balanced with auto-scaling
OR
Database (RDS) Optional
Your code Supported Platforms
Information required to deploy application
Building applications with Elastic Beanstalk
Application: api
Environmentprod-api V1
Environmentdev-api V1.1
EnvironmentbrowserClient V2
EnvironmentbrowserClient V2.1
Environmentdev-api V1.2
EnvironmentbrowserClient V3
Application: browser
How to deploy applications
1. Via AWS Management Console
2. Via AWS Toolkit for Eclipse and Visual Studio IDE
3. Via AWS SDK’s and CLI
4. Via EB command line interface$ eb deploy
Deploy Sample Application (EB CLI)Initial application deployment workflow
$ git clone https://github.com/awslabs/eb-node-express-sample.git
Download sample application02
$ eb initCreate your Elastic Beanstalk app0
3
Follow the prompts to configure the environment
04
05 Create the resources and launch the
application$ eb create
$ pip install --upgrade awsebcli
Install the AWS Elastic Beanstalk command line interface (EB CLI)
01
Update Sample Application (EB CLI)Update application workflow
Update your code01
$ git add .$ git commit –m “v2.0”$ eb deploy
Add & commit code to repository02
Open application once deployment completes.
03
$ eb open
Docker with AWS Elastic Beanstalk
Benefits of using Multi-Container Docker with Elastic Beanstalk
Automation of capacity provisioning, load balancing, scaling, and application health monitoring
One stop management of your application in an environment that supports range of services that are integrated with Elastic Beanstalk, including but not limited to VPC, RDS, and IAM.
I’ve built my containers, how do I…?
Store my container images? Configure containers for Beanstalk? Test my config? Deploy to Beanstalk? Update my application?
Store your container images: Amazon ECR
Beanstalk can interact with any Docker Repository Options include Dockerhub, Amazon ECR, and private
repos Amazon ECR allows access control via IAM for fine-
grained permissions Elastic Beanstalk can automatically authenticate with
ECR
Amazon ECR Registry Usage
Dockerrun.aws.json: Introduction
Specifies the version number as the value "2" for multicontainer Docker environments
AWSEBDockerrunVersion01
An array of container definitionsContainerDefinitions03
Mount points in the container instance that a container can use
Volumes02
"volumes": [ { "name": "volumename", "host": { "sourcePath": "/path/on/host/instance" } } ],
Format:
Dockerrun.aws.json: A snippet "AWSEBDockerrunVersion": 2, "volumes": [ { "name": "php-app", "host": { "sourcePath": "/var/app/current/php-app" } }, { "name": "nginx-proxy-conf", "host": { "sourcePath": "/var/app/current/proxy/conf.d" } } ], "containerDefinitions": [ { "name": "php-app", "image": "php:fpm", "environment": [ { "name": "Container", "value": "PHP" } ], "essential": true, "memory": 128, "mountPoints": [ { "sourceVolume": "php-app", "containerPath": "/var/www/html", "readOnly": true } ] },
{ "name": "nginx-proxy", "image": "nginx", "essential": true, "memory": 128, "portMappings": [ { "hostPort": 80, "containerPort": 80 } ], "links": [ "php-app" ], "mountPoints": [ { "sourceVolume": "php-app", "containerPath": "/var/www/html", "readOnly": true }, { "sourceVolume": "nginx-proxy-conf", "containerPath": "/etc/nginx/conf.d", "readOnly": true }, { "sourceVolume": "awseb-logs-nginx-proxy", "containerPath": "/var/log/nginx" } ] } ] }
Multi Container requires version 2
VolumeContainer Definition
The container definition and volumes sections of Dockerrun.aws.json use the same formatting as the corresponding sections of an Amazon ECS task definition file.
Test your Beanstalk application locally
Use EB “eb local run” command to run and test dockerrun.aws.json application locally
Choose the right Beanstalk container platform
Single Container Docker
Multi-Container Docker
Multi Container: Architecture
Each environment has its own ECS Cluster Supports a single ECS Task definition per environment The ECS Task is defined in the Dockerrun.aws.json file Uses a flood scheduling mechanism Provides out of the box auto scaling for ECS Tasks
Elastic Beanstalk Environment
Auto Scaling Group / ECS Cluster
Instance 1 Instance 2
app1.elasticbeanstalk.com
Elastic Load Balancing
Container 2Container 1
Container 3
Container 2Container 1
Container 3
Multi Container with Elastic Beanstalk
Nginx Proxy ExampleCode at: https://github.com/awslabs/eb-docker-nginx-proxy
Update your application: Application Deployment
Update your application: Deployment Policies All at once: Deploy new version to all instances
simultaneously
Rolling: Deploy new version in batches
Rolling with additional batch: Deploy in batches, +1 extra batch
Immutable: Deploy to fresh group of instances
All At Once Deployments
Step 0: All At Once
Auto Scaling Group
Elastic Beanstalk Environment
v1 v1
myapp.elasticbeanstalk.com
v1v1
Step 1: All At Once
Auto Scaling Group
Elastic Beanstalk Environment
v2 v2
myapp.elasticbeanstalk.com
v2v2
Rolling with Additional Batch
Step 0: Rolling with Additional Batch
Auto Scaling Group
Elastic Beanstalk Environment
v1 v1
myapp.elasticbeanstalk.com
v1v1
Step 1: Rolling with Additional Batch
Auto Scaling Group
Elastic Beanstalk Environment
v2 v2 v1 v1
myapp.elasticbeanstalk.com
v1v1
Step 2: Rolling with Additional Batch
Auto Scaling Group
Elastic Beanstalk Environment
v2 v2 v1 v1
myapp.elasticbeanstalk.com
v1v1
Step 3: Rolling with Additional Batch
Auto Scaling Group
Elastic Beanstalk Environment
v2 v2 v1 v1
myapp.elasticbeanstalk.com
v1v1
Step 4: Rolling with Additional Batch
Auto Scaling Group
Elastic Beanstalk Environment
v2 v2 v2 v2
myapp.elasticbeanstalk.com
v1v1
Step 5: Rolling with Additional Batch
Auto Scaling Group
Elastic Beanstalk Environment
v2 v2 v2 v2
myapp.elasticbeanstalk.com
v1v1
Step 6: Rolling with Additional Batch
Auto Scaling Group
Elastic Beanstalk Environment
v2 v2 v2 v2
myapp.elasticbeanstalk.com
v1v1
Step 7: Rolling with Additional Batch
Auto Scaling Group
Elastic Beanstalk Environment
v2 v2
myapp.elasticbeanstalk.com
v2v2
Update your application: Blue/Green
Update your application: Blue/Green Pros:
Fast rollback because the previous environment is still running
Cons: Slower deployment (5 minutes) due to new environment spin-up Potential of DNS caching by mobile clients after CNAME swap
Step 0: Blue/Green
Auto Scaling Group
Elastic Beanstalk Environment
v1 v1
myapp.elasticbeanstalk.com
v1v1
Step 1: Blue/Green
Auto Scaling Group
Elastic Beanstalk Environment
v1 v1
myapp.elasticbeanstalk.com
v1v1
Auto Scaling Group
v2
Step 2: Blue/Green
Auto Scaling Group
Elastic Beanstalk Environment
v1 v1
myapp.elasticbeanstalk.com
v1v1
Auto Scaling Group
v2
Step 3: Blue/Green
Auto Scaling Group
Elastic Beanstalk Environment
v1 v1
myapp.elasticbeanstalk.com
v1v1
Auto Scaling Group
v2 v2 v2v2
Step 4: Blue/Green
Auto Scaling Group
Elastic Beanstalk Environment
v1 v1
myapp.elasticbeanstalk.com
v1v1
Auto Scaling Group
v2 v2 v2v2
Step 5: Blue/Green
Auto Scaling Group
Elastic Beanstalk Environment
v1 v1
myapp.elasticbeanstalk.com
v1v1
Auto Scaling Group
v2 v2 v2v2
Step 6: Blue/Green
Auto Scaling Group
Elastic Beanstalk Environment
v2 v2
myapp.elasticbeanstalk.com
v2v2
Demo!
New Features
Recently added features
• Support for Application Load Balancer - Learn more
• Support for ASP.NET Core and Multi-App .NET deployment -
Learn more
• Support for EC2 Container Registry - Learn more
• Managed Updates - Learn more
Questions?
How to get in touch with the EB team?
Forum:https://forums.aws.amazon.com/forum.jspa?forumID=86
Twitter@aws_eb