Professional Documents
Culture Documents
13 - CT071!3!3-DDAC - Containerization Vs Microservices
13 - CT071!3!3-DDAC - Containerization Vs Microservices
13 - CT071!3!3-DDAC - Containerization Vs Microservices
ng
© 2021, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Module 8: Introducing Containers and Container Serv
ices
Section 1: Introduction
© 2021, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Module objectives
© 2021, Amazon Web Services, Inc. or its affiliates. All rights reserved. 3
Module overview
Sections Lab
1. Introduction • Lab 1: Migrating a Web Application to Docker
Containers
2. Introducing containers
• Lab 2: Running Containers on a Managed Service
3. Introducing Docker containers
4. Using containers for microservices
5. Introducing AWS container services
6. Deploying applications with Elastic Beanstalk
Knowledge check
© 2021, Amazon Web Services, Inc. or its affiliates. All rights reserved. 4
Café business requirement
Frank and Martha recently acquired a coffee bean supplier, and they would like to include the supplier’s
inventory tracking system into the café's application infrastructure. Sofía is thinking about migrating the
application database to containers to complete the integration.
© 2021, Amazon Web Services, Inc. or its affiliates. All rights reserved. 5
Containers as part of developing
a cloud application
© 2021, Amazon Web Services, Inc. or its affiliates. All rights reserved. 6
Module 8: Introducing Containers and Container Serv
ices
© 2021, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Shipping containers
© 2021, Amazon Web Services, Inc. or its affiliates. All rights reserved. 8
A container is a standardized unit of software
© 2021, Amazon Web Services, Inc. or its affiliates. All rights reserved. 9
Evolution of deployment models:
Bare-metal servers
Host OS
© 2021, Amazon Web Services, Inc. or its affiliates. All rights reserved. 10
Evolution of deployment models:
VMs
Isolated applications
VM VM VM
Application Application Application
A B C
Isolated libraries
Libraries Libraries Libraries
More OS maintenance
Guest OS Guest OS Guest OS More server space for OS
Virtualization platform
Better resource
Host OS
utilization
Host server
© 2021, Amazon Web Services, Inc. or its affiliates. All rights reserved. 11
Evolution of deployment models: Containers
Lightweight, efficient,
and fast
Containerization platform
Host server
Better resource
utilization
© 2021, Amazon Web Services, Inc. or its affiliates. All rights reserved. 12
• A container is a standardized unit of
Section 2 key
software that contains everything
takeaways that an application needs to run.
• Containers help to ensure that
applications deploy quickly, reliably,
and consistently regardless of the
deployment environment.
13 © 2021, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Module 8: Introducing Containers and Container Serv
ices
© 2021, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Docker container virtualization platform
© 2021, Amazon Web Services, Inc. or its affiliates. All rights reserved. 15
Docker container benefits
Layer 4
Layer 3
Layer 2
Layer 1
© 2021, Amazon Web Services, Inc. or its affiliates. All rights reserved. 18
Dockerfile example:
Start a Java application
# Start with open JDK version 8 image
FROM openjdk:8
© 2021, Amazon Web Services, Inc. or its affiliates. All rights reserved. 19
Dockerfile example:
Common tasks
# Start with CentOS 7 image
FROM centos:7
CMD ["/run-httpd.sh"]
© 2021, Amazon Web Services, Inc. or its affiliates. All rights reserved. 21
Docker CLI commands
Command Description Command Description
docker stop Stop a running container. Remove one or more images from
docker rmi the host.
docker start Start a container.
Dynamically update the container
docker update configuration.
docker push Push the image to a registry.
Create a new image from a
docker tag Tag an image. docker commit container's changes.
© 2021, Amazon Web Services, Inc. or its affiliates. All rights reserved. 22
Example of docker build command
Task Docker command
Build an image from a docker build --tag node_app .
Dockerfile in the current
directory, and name the Example output
image node_app Sending build context to Docker daemon 9.007MB
© 2021, Amazon Web Services, Inc. or its affiliates. All rights reserved. 23
Example of docker images command
Task Docker command
List the images that your docker images
Docker client is aware of
Example output
REPOSITORY TAG IMAGE ID CREATED SIZE
© 2021, Amazon Web Services, Inc. or its affiliates. All rights reserved. 24
Example of docker run command
Tasks Docker command
• Create a container named docker run -d --name node_app_1 -p 8000:80 node_app
node_app_1 from the
image named node_app
Example output
• Run in the background 5ed1ea04bcb58194100f71b2e7cd0aecab182313692ed833a6a700664994785f
and print the container ID
to the terminal
• Publish container port docker ps
8000 to the host
port CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS
80 to make the "docker-
5ed1ea04bcb5 node_app entrypoint.s 9 seconds Up 7 0.0.0.0:8000-
container available to …"
ago seconds >80/tcp
other services for HTTP
© 2021, Amazon Web Services, Inc. or its affiliates. All rights reserved. 25
Example of docker exec command
Tasks Docker command
• Start an sh docker exec -it node_app_1 sh
terminal session on
a running container
Example output
• List the files in the /usr/src/app #
user/src/app
directory /usr/src/app # ls
• Exit the shell session on Dockerfile README.md app
the running container index.js network.template node_modules
package-lock.json package.json public views
/usr/src/app # exit
© 2021, Amazon Web Services, Inc. or its affiliates. All rights reserved. 26
Example of docker stop and docker rm
commands
Tasks Docker command
• Stop the container docker stop node_app_1 && docker rm node_app_1
• Remove the container
Example output
node_app_1
node_app_1
© 2021, Amazon Web Services, Inc. or its affiliates. All rights reserved. 27
• Docker containers are created from read-
Section 3 key only templates, which are called images.
takeaways • Images are built from a Dockerfile and
often based on other images.
• Containers are runnable instances of an
image with a writable layer.
• A container registry is a repository of
images.
• To manage your Docker images and
containers, you can run Docker command
line interface (CLI) commands from a Bash
terminal.
28 © 2021, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Module 8: Introducing Containers and Container Serv
ices
© 2021, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Comparing monolithic
and microservice architectures
Monolithic Storefront UI
Account service
Cart service
Microservices
Account service (Node.js)
Storefront
Cart service (Python)
UI (Node.js)
Browser Load Shipping service (Java)
balancer
© 2021, Amazon Web Services, Inc. or its affiliates. All rights reserved. 30
Microservices and containers
Microservices design Container characteristics
• Decentralized, evolutionary • Each container uses the language and technology that are best suited for the service.
design • Each component or system in the architecture can be isolated, and can evolve separately,
• Smart endpoints, dumb instead of updating the system in a monolithic style.
pipes
• Independent products, not • You can use containers to package all of your dependencies and libraries into a single,
projects immutable object.
• Designed for failure • You can gracefully shut down a container when something goes wrong and create a new
instance. You start fast, fail fast, and release any file handlers.
• Disposable
• The development pattern is like a circuit breaker. Containers are added and removed,
workloads change, and resources are temporary because they constantly change.
• Development and production • Containers can make development, testing, and production environments consistent.
parity • This consistency facilitates DevOps, in which a containerized application that works on a
developer's system will work the same way on a production system.
© 2021, Amazon Web Services, Inc. or its affiliates. All rights reserved. 31
Module 8: Introducing Containers and Container Serv
ices
© 2021, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Challenges of managing containers at scale
• State of containers
• Scheduling of starts and stops
• Resources available on each server
• Maximizing availability, resilience,
and performance
© 2021, Amazon Web Services, Inc. or its affiliates. All rights reserved. 33
Container orchestration platforms
© 2021, Amazon Web Services, Inc. or its affiliates. All rights reserved. 34
Amazon ECS
© 2021, Amazon Web Services, Inc. or its affiliates. All rights reserved. 35
Amazon ECR
© 2021, Amazon Web Services, Inc. or its affiliates. All rights reserved. 36
Amazon ECS solution architecture
Select the
Amazon launch type AWS
ECR Fargate
Amazon
ECS Define your Manage
application your containers
Other Amazon
container EC2
registry
© 2021, Amazon Web Services, Inc. or its affiliates. All rights reserved. 37
Amazon ECS with Fargate
or Amazon EC2
Containers
Amazon ECS cluster Amazon ECS cluster
backed by Fargate Container instance Container instance Container instance backed by Amazon EC2
1 2 3
© 2021, Amazon Web Services, Inc. or its affiliates. All rights reserved. 39
Amazon EKS
© 2021, Amazon Web Services, Inc. or its affiliates. All rights reserved. 40
Amazon EKS
Fargate
Amazon EKS
Run Kubernetes
Amazon EC2 applications
Provision an Deploy worker Connect to
Amazon EKS nodes for your Amazon EKS
cluster Amazon EKS
cluster
© 2021, Amazon Web Services, Inc. or its affiliates. All rights reserved. 41
• Container orchestration services (or
Section 5 key systems) simplify managing containers
takeaways at scale.
• Amazon ECS is a fully managed
container orchestration service that
you can use to launch containers to
either Fargate or EC2 instances.
• Amazon ECR is a fully managed
container registry service.
• Amazon EKS is a managed service that
you can use to run Kubernetes in the
cloud.
42 © 2021, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Lab 8.1: Migrating a
Web Application to
Docker Containers
43 © 2021, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Lab: Scenario
Recently, the café owners acquired one of their favorite coffee suppliers. The
acquired coffee supplier runs an inventory tracking application on an AWS
account.
In this lab, you again play the role of Sofía, and you will work to migrate the
application to run on containers.
© 2021, Amazon Web Services, Inc. or its affiliates. All rights reserved. 44
Lab: Tasks
© 2021, Amazon Web Services, Inc. or its affiliates. All rights reserved. 45
Lab: Final product
Docker engine
© 2021, Amazon Web Services, Inc. or its affiliates. All rights reserved. 46
~ 90 minutes
© 2021, Amazon Web Services, Inc. or its affiliates. All rights reserved. 47
Lab debrief:
Key takeaways
© 2021, Amazon Web Services, Inc. or its affiliates. All rights reserved. 48
Lab 8.2: Running
Containers on a
Managed Service
49 © 2021, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Lab: Scenario
Sofía has containerized the coffee suppliers application, but wants to reduce
the effort to maintain the application and improve its scalability.
As noted in the previous lab, Sofía wants to move the database to a managed
database service rather than running it in a container.
Based on her research, she has made these decisions:
• Use AWS Elastic Beanstalk to deploy the application website.
• Use Amazon Aurora Serverless for the database. Sofía must retire the container-
based MySQL database and load the required user, tables, and data into an Aurora
Serverless database.
© 2021, Amazon Web Services, Inc. or its affiliates. All rights reserved. 50
Aurora Serverless
© 2021, Amazon Web Services, Inc. or its affiliates. All rights reserved. 52
Lab: Final product
Region
VPC
Public subnet 1
Deployment AWS
Aurora Serverless Cloud9
EC2 hosting IDE
website image
Data
API
© 2021, Amazon Web Services, Inc. or its affiliates. All rights reserved. 53
~ 90 minutes
© 2021, Amazon Web Services, Inc. or its affiliates. All rights reserved. 54
Lab debrief:
Key takeaways
© 2021, Amazon Web Services, Inc. or its affiliates. All rights reserved. 55
Module 8: Introducing Containers and Container Serv
ices
Module wrap-up
© 2021, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Module summary
© 2021, Amazon Web Services, Inc. or its affiliates. All rights reserved. 57
Complete the knowledge check
© 2021, Amazon Web Services, Inc. or its affiliates. All rights reserved. 58
Sample exam question
A cloud architect wants to migrate a web application to containers. The team does not have much
experience with AWS or containers, but the architect wants to get them started quickly to be ab le to
experiment.
© 2021, Amazon Web Services, Inc. or its affiliates. All rights reserved. 59
Additional resources
• Blog posts
• Building Container Images on Amazon ECS on AWS Fargate:
https://aws.amazon.com/blogs/containers/building-container-images-on-amazon-
ecs-on-aws-fargate/
• Developing Twelve-Factor Apps Using Amazon ECS and AWS Fargate:
https://aws.amazon.com/blogs/containers/developing-twelve-factor-apps-using-
amazon-ecs-and-aws-fargate/
• Amazon ECS Workshop: https://ecsworkshop.com/
© 2021, Amazon Web Services, Inc. or its affiliates. All rights reserved. 60
Thank you
© 2021, Amazon Web Services, Inc. or its affiliates. All rights reserved. This work may not be reproduced or redistributed, in whole or in part, without prior written permission from
Amazon Web Services, Inc. Commercial copying, lending, or selling is prohibited. Corrections, feedback, or other questions? Contact us at
https://support.aws.amazon.com/#/contacts/aws-training. All trademarks are the property of their owners.
Module 8: Introducing Containers and Container Serv
ices
© 2021, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Elastic Beanstalk
© 2021, Amazon Web Services, Inc. or its affiliates. All rights reserved. 63
Elastic Beanstalk components
Component Description
Application Logical collection of Elastic Beanstalk components. Conceptually similar to a folder.
Application
Specific, labeled iteration of deployable code for a web application.
version
Environment Collection of AWS resources that run an application version.
Designation of the type of application that the environment runs. Determines what resources Elastic Beanstalk
Environment tier provisions to support it.
Environment
Collection of parameters and settings that define how an environment and its associated resources behave.
configuration
Saved
Template that you can use as a starting point for creating unique environment configurations.
configuration
Combination of an OS, programming language runtime, web server, application server, and Elastic Beanstalk
Platform components. You design and target your web application to a platform.
Elastic Beanstalk CLI for Elastic Beanstalk. Provides interactive commands that simplify creating, updating, and monitoring
CLI environments from a local repository.
© 2021, Amazon Web Services, Inc. or its affiliates. All rights reserved. 64
IAM permissions in Elastic Beanstalk
environments
IAM roles assigned during environment creation
© 2021, Amazon Web Services, Inc. or its affiliates. All rights reserved. 65
Service role policy example
AWSElasticBeanstalkEnhancedHealth
"Effect": "Allow",
"Action": [
"elasticloadba
lancing:Descri
beInstanceHeal
th",
"elasticloadbalancing:DescribeLoadBalancers",
"elasticloadbalancing:DescribeTargetHealth",
"ec2:DescribeInstances",
"ec2:DescribeInstanceStatus",
"ec2:GetConsoleOutput",
"ec2:AssociateAddress",
"ec2:DescribeAddresses",
"ec2:DescribeSecurityGroups",
"sqs:GetQueueAttributes",
"sqs:GetQueueUrl",
"autoscaling:DescribeAutoScalingGroups",
"autoscaling:DescribeAutoScalingInstances",
"autoscaling:DescribeScalingActivities",
"autoscaling:DescribeNotificationConfigurations",
"sns:Publish"
],
"Resource": [
"*" All rights reserved.
© 2021, Amazon Web Services, Inc. or its affiliates. 66
]
Elastic Beanstalk simplifies container
deployment
Getting started with Getting started with
Amazon ECS Elastic Beanstalk
1. Create a task definition 1. Write a Dockerrun.aws.json file and
2. Create and configure a cluster provide your zipped code
including: 2. Select the platform for your
• EC2 instances language
• VPC settings 3. Launch your application
• IAM role definition
3. Create a service to run and maintain a
specified number of instances of a task
© 2021, Amazon Web Services, Inc. or its affiliates. All rights reserved. 67
Multicontainer Docker platform
Elastic Beanstalk
Elastic
Load
app1.elasticbeanstalk.com:9000
Balancing
© 2021, Amazon Web Services, Inc. or its affiliates. All rights reserved. 68
Dockerrun.aws.json file
{ "containerDefinitions": [
"AWSEBDockerrunVersion": 2, {
"volumes": [ "name": "php-app",
{ "image": "php:fpm",
"name": "php-app", "environment": [
"host": {
{ "sourcePath "name":
": "Container",
"/var/app/current/ "value": "PHP"
php-app" }
} ],
}, "name": "nginx-proxy-conf", "essential": true,
{ "host": { "memory": 128,
"sourcePath": "mountPoints": [
"/var/app/current/proxy/conf.d" {
} "sourceVolume": "php-app",
} "containerPath": "/var/www/html",
] "readOnly": true
}
… ]
}
…
© 2021, Amazon Web Services, Inc. or its affiliates. All rights reserved. 69
Elastic Beanstalk deployment policies
Faster More control
All at once Rolling Immutable Traffic splitting
• Deploys the new version • Deploys to a batch of • Launches a second Auto • Launches a full set of
to each instance instances at a time Scaling group, and new instances like an
• Requires some • Avoids downtime serves traffic to both old immutable deployment
downtime • Minimizes reduced and new versions until • Tests the health of the
• Quickest deployment availability the new instances pass new version by using a
method • Longer health checks portion of traffic while
deployment • Ensures that the new keeping the rest of the
version always goes on traffic served by the old
Rolling with new instances version
batch • Allows for quick and safe • Supports canary testing
• Launches an extra batch rollback • No interruption of
of instances, then • Longer deployment time service if you must roll
performs a rolling back
deployment
• Avoids reduced
availability
• Longer
© 2021, Amazon Web Services, Inc. or its affiliates. All rights reserved. 70
Deployment option namespaces
aws:elasticbeanstalk:command
• Choose the deployment policy
• Set a timeout
• Choose options for size and type of batches to use
• Choose whether to cancel deployment on a failed health check
aws:elasticbeanstalk:trafficsplitting
• Choose the percentage of traffic to go to new instances
• Choose how long to wait before continuing to shift more traffic
© 2021, Amazon Web Services, Inc. or its affiliates. All rights reserved. 71
Example of traffic splitting
(canary testing)
Example deployment configurations Elastic Beanstalk Health checks: 10 minutes
option_settings:
Auto Scaling group
aws:elasticbeanstalk:command:
DeploymentPolicy: 15%
TrafficSplitting
v1 v1
aws:elasticbeanstalk:trafficsplitting:
ELB
NewVersionPercent: "15"
EvaluationTime: "10" 15%
v2
v2
Temporary Auto Scaling group
© 2021, Amazon Web Services, Inc. or its affiliates. All rights reserved. 72
Blue/green deployments
on Elastic Beanstalk
myapp.useast-1.elasticbeanstalk.com myapp_new.useast-1.elasticbeanstalk.com
3 Swap the
CNAMEs
2 Deploy and
test in the
new
1 Clone the
environment
environment
© 2021, Amazon Web Services, Inc. or its affiliates. All rights reserved. 73
• You can use Elastic Beanstalk to
Section 6 key manage all of the resources that run
takeaways your application as an environment.
• You can quickly launch a Docker
multicontainer environment with
Elastic Beanstalk without worrying
about Amazon ECS configuration
details.
• Deployment options include traffic
splitting and blue/green to support
testing new versions.
74 © 2021, Amazon Web Services, Inc. or its affiliates. All rights reserved.