SlideShare a Scribd company logo
1 of 67
Automating Zero-Downtime Production
Cluster Upgrades for Amazon ECS
Matt Callanan
Engineering Manager/Tech Lead
“Cloud Acceleration Team”
Expedia
Brisbane, Australia
• mcallanan@expedia.com
• linkedin.com/in/matthewcallanan
• @mcallana
Cluster Management
• How to upgrade the EC2 infrastructure underlying a live
production Amazon ECS cluster without affecting service
availability.
• How to safely relocate hundreds of tasks onto new
Amazon EC2 instances with zero-downtime to
applications.
Region 1
Region 2 Region 3 Region 4 Region
5
Expedia ECS Cluster Statistics
2,600 ECS Services (1,100 Applications)
13,000 Containers
860 EC2 Instances (13 ECS Clusters)
Region 1
Region 2 Region 3 Region 4 Region
5
Expedia ECS Cluster Topology
Production Cluster Test Environment Cluster
480 Services
230 Instances
Production Cluster Visualization
230 Instances 480 Services 3,200 Containers
c3vis Open Source: https://github.com/ExpediaDotCom/c3vis
ECS Cluster Creation
Cloud
Formation
Stack
EC2 Instances
Auto Scaling Group
Amazon
ECS Cluster
Immutable Servers
Amazon-provided Base AMI
Standard Chef cookbook
Custom setup baked into AMI
ecs-optimized AMI
Expedia standard image
Docker Config
Daemon containers
Golden AMI
docker ecs-agent
Immutable Servers
ecs-optimized AMI
Expedia standard image
Docker Config
Daemon containers
Golden AMI
docker ecs-agent
ecs-optimized AMI
Expedia standard image
Docker Config
Daemon containers
Cluster Instance
Custom bootstrap:
• ECS Cluster Config
• Start ECS Agent, Docker
• Cron: Restart ECS agent
• Cron: Custom Metrics
docker ecs-agent
Zero-Downtime Cluster Upgrades
First Approach
• CloudFormation Auto-Scaling Rolling Update
Default Cloud Formation Auto-Scaling Rolling Update
Old Instance
New Instance
Terminating Instance
Active Task
Relocated Task
Stopped Task
Default Cloud Formation Auto-Scaling Rolling Update
A
A
Old Instance
New Instance
Terminating Instance
Active Task
Relocated Task
Stopped Task
Default Cloud Formation Auto-Scaling Rolling Update
A
A
Old Instance
New Instance
Terminating Instance
Active Task
Relocated Task
Stopped Task
Problem:
Tasks stop before they are relocated.
Even with tasks on distinct instances, outage can
happen if new instances are not pulling images
fast enough
Default Cloud Formation Auto-Scaling Rolling Update
A
Old Instance
New Instance
Terminating Instance
Active Task
Relocated Task
Stopped Task
Default Cloud Formation Auto-Scaling Rolling Update
A
A
Problem:
Tasks start on instances
about to be terminated
Old Instance
New Instance
Terminating Instance
Active Task
Relocated Task
Stopped Task
Default Cloud Formation Auto-Scaling Rolling Update
A
A
Old Instance
New Instance
Terminating Instance
Active Task
Relocated Task
Stopped Task
Default Cloud Formation Auto-Scaling Rolling Update
A
A
Old Instance
New Instance
Terminating Instance
Active Task
Relocated Task
Stopped Task
Default Cloud Formation Auto-Scaling Rolling Update
A
A
Old Instance
New Instance
Terminating Instance
Active Task
Relocated Task
Stopped Task
Default Cloud Formation Auto-Scaling Rolling Update
A
A
Old Instance
New Instance
Terminating Instance
Active Task
Relocated Task
Stopped Task
Default Cloud Formation Auto-Scaling Rolling Update
A
A
Old Instance
New Instance
Terminating Instance
Active Task
Relocated Task
Stopped Task
Default Cloud Formation Auto-Scaling Rolling Update
A
A
Old Instance
New Instance
Terminating Instance
Active Task
Relocated Task
Stopped Task
Default Cloud Formation Auto-Scaling Rolling Update
A
Old Instance
New Instance
Terminating Instance
Active Task
Relocated Task
Stopped Task
Default Cloud Formation Auto-Scaling Rolling Update
A
Old Instance
New Instance
Terminating Instance
Active Task
Relocated Task
Stopped Task
Default Cloud Formation Auto-Scaling Rolling Update
A
Old Instance
New Instance
Terminating Instance
Active Task
Relocated Task
Stopped Task
Default Cloud Formation Auto-Scaling Rolling Update
A
Old Instance
New Instance
Terminating Instance
Active Task
Relocated Task
Stopped Task
Default Cloud Formation Auto-Scaling Rolling Update
Old Instance
New Instance
Terminating Instance
Active Task
Relocated Task
Stopped Task
Problem:
Service “A” experiences downtime
Default Cloud Formation Auto-Scaling Rolling Update
A
Old Instance
New Instance
Terminating Instance
Active Task
Relocated Task
Stopped Task
Default Cloud Formation Auto-Scaling Rolling Update
A
Old Instance
New Instance
Terminating Instance
Active Task
Relocated Task
Stopped Task
Default Cloud Formation Auto-Scaling Rolling Update
A
A
Old Instance
New Instance
Terminating Instance
Active Task
Relocated Task
Stopped Task
Default Cloud Formation Auto-Scaling Rolling Update
A
A
Old Instance
New Instance
Terminating Instance
Active Task
Relocated Task
Stopped Task
Default Cloud Formation Auto-Scaling Rolling Update
A
A
Old Instance
New Instance
Terminating Instance
Active Task
Relocated Task
Stopped Task
Problem:
Tasks bunch up on first
few new instances
First Approach: Problem Summary
• CloudFormation  AutoScaling
Asynchrony
• Rolling Update not granular enough
• Outside our control
• Rollbacks with no ability for manual
intervention
• Tasks stop before they are relocated
• Service outage can happen if new
instances are not pulling images fast
enough
• Tasks are not evenly spread across new
instances
CloudFormation
Auto Scaling
Second Approach
• Custom Rolling Update automation
• Programmatic Update Script using
Ruby SDK
• But still took 10 (nail-biting) hours to
update a cluster with 100 instances
• Any issues during the process required
manual intervention Auto Scaling
Third Approach
• “PRISM”
• Project Replaced in Sixty Minutes
“PRISM” Goals
• Zero-downtime for applications as their workloads get relocated onto new instances
Safety
• Complete as fast as possible
Speed
• Quickly retreat back to known-good state if anything goes wrong
Rollbackable
• Resumeable if anything goes wrong
Idempotent
• Drain in batches to prevent burden on Docker registry and network
• Avoid having tasks relocated to instances about to be drained
Avoid “thundering herd” scenario
“PRISM” Phases
Phase 1: Expand
Phase 2: Relocate Tasks
Phase 3: Clean Up
Zero-Downtime Cluster Updates
Cloud
Formation
Stack
EC2 Instances
Auto Scaling group
Amazon
ECS
Cluster
Amazon
ECS
Cluster
Cloud
Formation
Stack
EC2 Instances
Auto Scaling group
Cloud
Formation
Stack
EC2 Instances
Auto Scaling group
Zero-Downtime Cluster Updates
Phase 1: Expand Cluster
Zero-Downtime Cluster Updates
Phase 2: Relocate Tasks
Amazon
ECS
Cluster
Cloud
Formation
Stack
EC2 Instances
Auto Scaling group
Cloud
Formation
Stack
EC2 Instances
Auto Scaling group
Draining…
Zero-Downtime Cluster Updates
Phase 3: Clean Up
Amazon
ECS
Cluster
Cloud
Formation
Stack
EC2 Instances
Auto Scaling group
Cloud
Formation
Stack
EC2 Instances
Auto Scaling group
Zero-Downtime Cluster Updates
Phase 3: Clean Up
Amazon
ECS
ClusterCloud
Formation
Stack
EC2 Instances
Auto Scaling group
Old Instance
New Instance
Draining Instance
A
Active Task
Relocated Task
“DRAINING” Task
A
Blue Auto-Scaling Group
Blue CFN Stack
Cluster Update – Phase 1: Expand
AA
Blue Auto-Scaling Group
Blue CFN Stack
Disable Auto-Scaling Processes
Cluster Update – Phase 1: Expand
Old Instance
New Instance
Draining Instance
Active Task
Relocated Task
“DRAINING” Task
AA
Blue Auto-Scaling Group
Blue CFN Stack
Green Auto-Scaling Group
Green CFN Stack
Disable Auto-Scaling Processes Disable Auto-Scaling Processes
Cluster Update – Phase 1: Expand
Old Instance
New Instance
Draining Instance
Active Task
Relocated Task
“DRAINING” Task
AA
Blue Auto-Scaling Group
Blue CFN Stack
Green Auto-Scaling Group
Green CFN Stack
state = ‘pre-drain’
Disable Auto-Scaling Processes Disable Auto-Scaling Processes
Cluster Update – Phase 1: Expand
Old Instance
New Instance
Draining Instance
Active Task
Relocated Task
“DRAINING” Task
AA
Blue Auto-Scaling Group
Blue CFN Stack
Green Auto-Scaling Group
Green CFN Stack
Disable Auto-Scaling Processes
Cluster Update – Phase 2: Relocate Tasks (batches of 3 instances)
Old Instance
New Instance
Draining Instance
Active Task
Relocated Task
“DRAINING” Task
Disable Auto-Scaling Processes
state = ‘pre-drain’
Blue Auto-Scaling Group
Blue CFN Stack
Green Auto-Scaling Group
Green CFN Stack
Disable Auto-Scaling Processes
Cluster Update – Phase 2: Relocate Tasks (batches of 3 instances)
Old Instance
New Instance
Draining Instance
Active Task
Relocated Task
“DRAINING” Task
AA
state = ‘pre-drain’
Disable Auto-Scaling Processes
Blue Auto-Scaling Group
Blue CFN Stack
Green Auto-Scaling Group
Green CFN Stack
Disable Auto-Scaling Processes
Cluster Update – Phase 2: Relocate Tasks (batches of 3 instances)
Old Instance
New Instance
Draining Instance
Active Task
Relocated Task
“DRAINING” Task
A
AAA
state = ‘pre-drain’
Disable Auto-Scaling Processes
Blue Auto-Scaling Group
Blue CFN Stack
A
A
Green Auto-Scaling Group
Green CFN Stack
Disable Auto-Scaling Processes
Cluster Update – Phase 2: Relocate Tasks (batches of 3 instances)
Old Instance
New Instance
Draining Instance
Active Task
Relocated Task
“DRAINING” Task
AA
state = ‘pre-drain’
Disable Auto-Scaling Processes
Blue Auto-Scaling Group
Blue CFN Stack
A
A
Green Auto-Scaling Group
Green CFN Stack
Disable Auto-Scaling Processes
Cluster Update – Phase 2: Relocate Tasks (batches of 3 instances)
Old Instance
New Instance
Draining Instance
Active Task
Relocated Task
“DRAINING” Task
state = ‘pre-drain’
Disable Auto-Scaling Processes
Blue Auto-Scaling Group
Blue CFN Stack
A
Green Auto-Scaling Group
Green CFN Stack
Disable Auto-Scaling Processes
Cluster Update – Phase 2: Relocate Tasks (batches of 3 instances)
Old Instance
New Instance
Draining Instance
Active Task
Relocated Task
“DRAINING” Task
A
state = ‘pre-drain’
Disable Auto-Scaling Processes
Blue Auto-Scaling Group
Blue CFN Stack
A
Green Auto-Scaling Group
Green CFN Stack
Disable Auto-Scaling Processes
Cluster Update – Phase 2: Relocate Tasks (batches of 3 instances)
Old Instance
New Instance
Draining Instance
Active Task
Relocated Task
“DRAINING” Task
A
state = ‘pre-drain’
Disable Auto-Scaling Processes
Blue Auto-Scaling Group
Blue CFN Stack
A
A
Green Auto-Scaling Group
Green CFN Stack
Disable Auto-Scaling Processes
Cluster Update – Phase 2: Relocate Tasks (batches of 3 instances)
Old Instance
New Instance
Draining Instance
Active Task
Relocated Task
“DRAINING” Task
state = ‘pre-drain’
Disable Auto-Scaling Processes
Blue Auto-Scaling Group
Blue CFN Stack
A
A
Green Auto-Scaling Group
Green CFN Stack
Disable Auto-Scaling Processes
Cluster Update – Phase 2: Relocate Tasks (batches of 3 instances)
Old Instance
New Instance
Draining Instance
Active Task
Relocated Task
“DRAINING” Task
state = ‘pre-drain’
Disable Auto-Scaling Processes
A
A
Green Auto-Scaling Group
Green CFN Stack
Disable Auto-Scaling Processes
Cluster Update – Phase 3: Clean Up
Old Instance
New Instance
Draining Instance
Active Task
Relocated Task
“DRAINING” Task
A
A
Green Auto-Scaling Group
Green CFN Stack
Resume Auto-Scaling Processes
Cluster Update – Phase 3: Clean Up
Old Instance
New Instance
Draining Instance
Active Task
Relocated Task
“DRAINING” Task
Enabling Aspects
Pre-flight Checks
• Before Cluster Create/Update
• Check # instances available of target instance type
• Check IP addresses available in target subnets
• Check EBS volume space available of target volume type
Drain on Scale-down with Lifecycle Lambda
• Lambda triggered by AutoScaling
EC2_INSTANCE_TERMINATE SNS events
• Updates instance state to “DRAINING”
• ASG has 30-minute heartbeat to keep instance in
Terminating:Wait state for 30mins
• Allows ECS to safely relocate any tasks that are part of a
service to another instance
AutoScaling Lifecycle Hook
resource "ECSContainerInstanceTerminating",
Type: "AWS::AutoScaling::LifecycleHook",
Properties: {
AutoScalingGroupName: ref("ECSAutoScalingGroup"),
LifecycleTransition: "autoscaling:EC2_INSTANCE_TERMINATING",
DefaultResult: "CONTINUE",
RoleARN: ref("LifecycleHookRoleARN"),
NotificationTargetARN: ref("ECSAutoscalingLifecycleTopic"),
HeartbeatTimeout: 1800 # 30 minutes
},
Avoid Relocating to Old Instance
• Problem:
• Tasks can get rescheduled to another old instance in the ASG that is about to be replaced - so
tasks can get bumped from instance to instance until all instances are replaced
• Solution:
• Deploy services with placement constraint
• This means that a service won’t be placed on an instance that has an attribute named “state” with
value “pre-drain”
• At cluster replacement time, we will stand up all new clusters, place old clusters into the “pre-
drain” state, and terminate the old instances in batches.
• Relocated tasks will only be placed on new instances, avoiding the default “thundering herd”
scenario
placement_constraints = [ {
type: 'memberOf',
expression: 'attribute:state !exists or attribute:state != pre-drain'
}]
Task Definition Placement Constraint
Task Definition Placement Constraint
• “state” is a custom ECS Instance Attribute
• By default, the “state” attribute doesn’t exist on instances
• Set only to “pre-drain” during cluster update
• Prevents ECS scheduling tasks on instances that are about to be drained
• Removed from instance only in case of rollback of cluster update
Instance Launch Considerations
• Worked with AWS Auto-Scaling team to enable more
appropriate Auto-Scaling “Launch Rate”
• Start the ECS agent with exponential backoff
• Throttle on container instance registration rate = 1 per
second/60 max per minute
Gotchas
• Found a number of apps don't relocate easily
• Slows down prod upgrades and old stack decommissions
Related
AWS re:invent 2017: Going Big with Containers: Customer
Case Studies of Large-Scale (ENT209)
• https://www.youtube.com/watch?v=L3l_ZiYRrks
• Covers full scope of Expedia’s ECS deployment
automation platform

More Related Content

What's hot

Keto Diet Recipes
Keto Diet RecipesKeto Diet Recipes
Keto Diet Recipeseizhele
 
10 Healthy Eating Tips | Webinar Wednesday | March 2016
10 Healthy Eating Tips | Webinar Wednesday | March 201610 Healthy Eating Tips | Webinar Wednesday | March 2016
10 Healthy Eating Tips | Webinar Wednesday | March 2016kelseyseybold
 
Nutrition in Chronic Respiratory Diseases.ppt
Nutrition in Chronic Respiratory Diseases.pptNutrition in Chronic Respiratory Diseases.ppt
Nutrition in Chronic Respiratory Diseases.pptDr Riham Hazem Raafat
 
Sports Nutrition for Health Professionals
Sports Nutrition for Health ProfessionalsSports Nutrition for Health Professionals
Sports Nutrition for Health ProfessionalsBrian Levins
 
Diet treatment in liver cirrhosis - di Vincenzo Ostilio Palmieri
Diet treatment in liver cirrhosis - di Vincenzo Ostilio PalmieriDiet treatment in liver cirrhosis - di Vincenzo Ostilio Palmieri
Diet treatment in liver cirrhosis - di Vincenzo Ostilio PalmieriMedOliveOil
 
bariatric nutrition: a way to manage obesity
bariatric nutrition: a way to manage obesitybariatric nutrition: a way to manage obesity
bariatric nutrition: a way to manage obesityDr. Swati Shukla
 
Fertility diet
Fertility dietFertility diet
Fertility dietsunitafeme
 
Healthy Eating Habits
Healthy Eating HabitsHealthy Eating Habits
Healthy Eating HabitsRitchenMadura
 
How to gain weight
How to gain weightHow to gain weight
How to gain weightMedisys Kart
 
Canada's Food Guide
Canada's Food GuideCanada's Food Guide
Canada's Food GuideMelodyLi15
 
Healthy Eating on a Budget
Healthy Eating on a BudgetHealthy Eating on a Budget
Healthy Eating on a BudgetJamie Luu
 
Importance of nutritional management during hospitalization
Importance of nutritional management during hospitalizationImportance of nutritional management during hospitalization
Importance of nutritional management during hospitalizationBushra Tariq
 
Alimentação na Gestação
Alimentação na GestaçãoAlimentação na Gestação
Alimentação na GestaçãoJulio Cesar Dessoy
 
TPM For lean manufacturing chp3 | kobetsu kaizen for production efficiency...
TPM For lean manufacturing  chp3 |   kobetsu kaizen for production efficiency...TPM For lean manufacturing  chp3 |   kobetsu kaizen for production efficiency...
TPM For lean manufacturing chp3 | kobetsu kaizen for production efficiency...博行 門眞
 

What's hot (20)

Keto Diet Recipes
Keto Diet RecipesKeto Diet Recipes
Keto Diet Recipes
 
Food nutrition
Food nutritionFood nutrition
Food nutrition
 
Healthy Eating
Healthy EatingHealthy Eating
Healthy Eating
 
10 Healthy Eating Tips | Webinar Wednesday | March 2016
10 Healthy Eating Tips | Webinar Wednesday | March 201610 Healthy Eating Tips | Webinar Wednesday | March 2016
10 Healthy Eating Tips | Webinar Wednesday | March 2016
 
NUTRIÇÃO NO IDOSO
NUTRIÇÃO NO IDOSONUTRIÇÃO NO IDOSO
NUTRIÇÃO NO IDOSO
 
Nutrition in Chronic Respiratory Diseases.ppt
Nutrition in Chronic Respiratory Diseases.pptNutrition in Chronic Respiratory Diseases.ppt
Nutrition in Chronic Respiratory Diseases.ppt
 
Sports Nutrition for Health Professionals
Sports Nutrition for Health ProfessionalsSports Nutrition for Health Professionals
Sports Nutrition for Health Professionals
 
Diet treatment in liver cirrhosis - di Vincenzo Ostilio Palmieri
Diet treatment in liver cirrhosis - di Vincenzo Ostilio PalmieriDiet treatment in liver cirrhosis - di Vincenzo Ostilio Palmieri
Diet treatment in liver cirrhosis - di Vincenzo Ostilio Palmieri
 
bariatric nutrition: a way to manage obesity
bariatric nutrition: a way to manage obesitybariatric nutrition: a way to manage obesity
bariatric nutrition: a way to manage obesity
 
Fertility diet
Fertility dietFertility diet
Fertility diet
 
Healthy Eating Habits
Healthy Eating HabitsHealthy Eating Habits
Healthy Eating Habits
 
Palestra diabetes
Palestra diabetes Palestra diabetes
Palestra diabetes
 
How to gain weight
How to gain weightHow to gain weight
How to gain weight
 
Canada's Food Guide
Canada's Food GuideCanada's Food Guide
Canada's Food Guide
 
5S Methodology
5S Methodology5S Methodology
5S Methodology
 
Healthy Eating on a Budget
Healthy Eating on a BudgetHealthy Eating on a Budget
Healthy Eating on a Budget
 
Importance of nutritional management during hospitalization
Importance of nutritional management during hospitalizationImportance of nutritional management during hospitalization
Importance of nutritional management during hospitalization
 
Diet in ckd
Diet in ckdDiet in ckd
Diet in ckd
 
Alimentação na Gestação
Alimentação na GestaçãoAlimentação na Gestação
Alimentação na Gestação
 
TPM For lean manufacturing chp3 | kobetsu kaizen for production efficiency...
TPM For lean manufacturing  chp3 |   kobetsu kaizen for production efficiency...TPM For lean manufacturing  chp3 |   kobetsu kaizen for production efficiency...
TPM For lean manufacturing chp3 | kobetsu kaizen for production efficiency...
 

Similar to Automating Zero-Downtime Production Cluster Upgrades for Amazon ECS

Docker Cluster Management with ECS
Docker Cluster Management with ECSDocker Cluster Management with ECS
Docker Cluster Management with ECSMatt Callanan
 
Deep Dive on Microservices and Amazon ECS
Deep Dive on Microservices and Amazon ECSDeep Dive on Microservices and Amazon ECS
Deep Dive on Microservices and Amazon ECSAmazon Web Services
 
Running Containerised Applications at Scale on AWS
Running Containerised Applications at Scale on AWSRunning Containerised Applications at Scale on AWS
Running Containerised Applications at Scale on AWSAmazon Web Services
 
Building a CICD Pipeline for deploying on Containers
Building a CICD Pipeline for deploying on ContainersBuilding a CICD Pipeline for deploying on Containers
Building a CICD Pipeline for deploying on ContainersAmazon Web Services
 
Deep Dive with Amazon EC2 Container Service Hands-on Workshop
Deep Dive with Amazon EC2 Container Service Hands-on WorkshopDeep Dive with Amazon EC2 Container Service Hands-on Workshop
Deep Dive with Amazon EC2 Container Service Hands-on WorkshopAmazon Web Services
 
(DVO401) Deep Dive into Blue/Green Deployments on AWS
(DVO401) Deep Dive into Blue/Green Deployments on AWS(DVO401) Deep Dive into Blue/Green Deployments on AWS
(DVO401) Deep Dive into Blue/Green Deployments on AWSAmazon Web Services
 
Automating Management of Amazon EC2 Instances with Auto Scaling - March 2017 ...
Automating Management of Amazon EC2 Instances with Auto Scaling - March 2017 ...Automating Management of Amazon EC2 Instances with Auto Scaling - March 2017 ...
Automating Management of Amazon EC2 Instances with Auto Scaling - March 2017 ...Amazon Web Services
 
Netflix presents at MassTLC Cloud Summit 2013
Netflix presents at MassTLC Cloud Summit 2013Netflix presents at MassTLC Cloud Summit 2013
Netflix presents at MassTLC Cloud Summit 2013MassTLC
 
Building a CICD Pipeline for Container Deployment to Amazon ECS
Building a CICD Pipeline for Container Deployment to Amazon ECSBuilding a CICD Pipeline for Container Deployment to Amazon ECS
Building a CICD Pipeline for Container Deployment to Amazon ECSAmazon Web Services
 
Continuous Delivery to Amazon ECS
Continuous Delivery to Amazon ECS Continuous Delivery to Amazon ECS
Continuous Delivery to Amazon ECS Amazon Web Services
 
Deep Dive into Container Scheduling with Amazon ECS - CON404 - re:Invent 2017
Deep Dive into Container Scheduling with Amazon ECS - CON404 - re:Invent 2017Deep Dive into Container Scheduling with Amazon ECS - CON404 - re:Invent 2017
Deep Dive into Container Scheduling with Amazon ECS - CON404 - re:Invent 2017Amazon Web Services
 
SRV412 Deep Dive on CICD and Docker
SRV412 Deep Dive on CICD and DockerSRV412 Deep Dive on CICD and Docker
SRV412 Deep Dive on CICD and DockerAmazon Web Services
 
Building A CICD Pipeline for Deploying to Containers
Building A CICD Pipeline for Deploying to ContainersBuilding A CICD Pipeline for Deploying to Containers
Building A CICD Pipeline for Deploying to ContainersAmazon Web Services
 
Building CI/CD Pipelines for Serverless Applications
Building CI/CD Pipelines for Serverless ApplicationsBuilding CI/CD Pipelines for Serverless Applications
Building CI/CD Pipelines for Serverless ApplicationsAmazon Web Services
 
Building a CICD Pipeline for Container Deployment to Amazon ECS - May 2017 AW...
Building a CICD Pipeline for Container Deployment to Amazon ECS - May 2017 AW...Building a CICD Pipeline for Container Deployment to Amazon ECS - May 2017 AW...
Building a CICD Pipeline for Container Deployment to Amazon ECS - May 2017 AW...Amazon Web Services
 
Building a CI/CD Pipeline For Container Deployment to Amazon ECS
Building a CI/CD Pipeline For Container Deployment to Amazon ECSBuilding a CI/CD Pipeline For Container Deployment to Amazon ECS
Building a CI/CD Pipeline For Container Deployment to Amazon ECSAmazon Web Services
 
Building a CICD Pipeline for Deploying to Containers
Building a CICD Pipeline for Deploying to ContainersBuilding a CICD Pipeline for Deploying to Containers
Building a CICD Pipeline for Deploying to ContainersAmazon Web Services
 
Deploy, scale and manage your application with AWS Elastic Beanstal
Deploy, scale and manage your application with AWS Elastic BeanstalDeploy, scale and manage your application with AWS Elastic Beanstal
Deploy, scale and manage your application with AWS Elastic BeanstalAmazon Web Services
 
[AWS Dev Day] 실습워크샵 | Amazon EKS 핸즈온 워크샵
 [AWS Dev Day] 실습워크샵 | Amazon EKS 핸즈온 워크샵 [AWS Dev Day] 실습워크샵 | Amazon EKS 핸즈온 워크샵
[AWS Dev Day] 실습워크샵 | Amazon EKS 핸즈온 워크샵Amazon Web Services Korea
 

Similar to Automating Zero-Downtime Production Cluster Upgrades for Amazon ECS (20)

Docker Cluster Management with ECS
Docker Cluster Management with ECSDocker Cluster Management with ECS
Docker Cluster Management with ECS
 
Deep Dive on Microservices and Amazon ECS
Deep Dive on Microservices and Amazon ECSDeep Dive on Microservices and Amazon ECS
Deep Dive on Microservices and Amazon ECS
 
Running Containerised Applications at Scale on AWS
Running Containerised Applications at Scale on AWSRunning Containerised Applications at Scale on AWS
Running Containerised Applications at Scale on AWS
 
Building a CICD Pipeline for deploying on Containers
Building a CICD Pipeline for deploying on ContainersBuilding a CICD Pipeline for deploying on Containers
Building a CICD Pipeline for deploying on Containers
 
Deep Dive with Amazon EC2 Container Service Hands-on Workshop
Deep Dive with Amazon EC2 Container Service Hands-on WorkshopDeep Dive with Amazon EC2 Container Service Hands-on Workshop
Deep Dive with Amazon EC2 Container Service Hands-on Workshop
 
(DVO401) Deep Dive into Blue/Green Deployments on AWS
(DVO401) Deep Dive into Blue/Green Deployments on AWS(DVO401) Deep Dive into Blue/Green Deployments on AWS
(DVO401) Deep Dive into Blue/Green Deployments on AWS
 
Automating Management of Amazon EC2 Instances with Auto Scaling - March 2017 ...
Automating Management of Amazon EC2 Instances with Auto Scaling - March 2017 ...Automating Management of Amazon EC2 Instances with Auto Scaling - March 2017 ...
Automating Management of Amazon EC2 Instances with Auto Scaling - March 2017 ...
 
Netflix presents at MassTLC Cloud Summit 2013
Netflix presents at MassTLC Cloud Summit 2013Netflix presents at MassTLC Cloud Summit 2013
Netflix presents at MassTLC Cloud Summit 2013
 
Building a CICD Pipeline for Container Deployment to Amazon ECS
Building a CICD Pipeline for Container Deployment to Amazon ECSBuilding a CICD Pipeline for Container Deployment to Amazon ECS
Building a CICD Pipeline for Container Deployment to Amazon ECS
 
Testing Framework on AWS Cloud - Solution Set
Testing Framework on AWS Cloud - Solution SetTesting Framework on AWS Cloud - Solution Set
Testing Framework on AWS Cloud - Solution Set
 
Continuous Delivery to Amazon ECS
Continuous Delivery to Amazon ECS Continuous Delivery to Amazon ECS
Continuous Delivery to Amazon ECS
 
Deep Dive into Container Scheduling with Amazon ECS - CON404 - re:Invent 2017
Deep Dive into Container Scheduling with Amazon ECS - CON404 - re:Invent 2017Deep Dive into Container Scheduling with Amazon ECS - CON404 - re:Invent 2017
Deep Dive into Container Scheduling with Amazon ECS - CON404 - re:Invent 2017
 
SRV412 Deep Dive on CICD and Docker
SRV412 Deep Dive on CICD and DockerSRV412 Deep Dive on CICD and Docker
SRV412 Deep Dive on CICD and Docker
 
Building A CICD Pipeline for Deploying to Containers
Building A CICD Pipeline for Deploying to ContainersBuilding A CICD Pipeline for Deploying to Containers
Building A CICD Pipeline for Deploying to Containers
 
Building CI/CD Pipelines for Serverless Applications
Building CI/CD Pipelines for Serverless ApplicationsBuilding CI/CD Pipelines for Serverless Applications
Building CI/CD Pipelines for Serverless Applications
 
Building a CICD Pipeline for Container Deployment to Amazon ECS - May 2017 AW...
Building a CICD Pipeline for Container Deployment to Amazon ECS - May 2017 AW...Building a CICD Pipeline for Container Deployment to Amazon ECS - May 2017 AW...
Building a CICD Pipeline for Container Deployment to Amazon ECS - May 2017 AW...
 
Building a CI/CD Pipeline For Container Deployment to Amazon ECS
Building a CI/CD Pipeline For Container Deployment to Amazon ECSBuilding a CI/CD Pipeline For Container Deployment to Amazon ECS
Building a CI/CD Pipeline For Container Deployment to Amazon ECS
 
Building a CICD Pipeline for Deploying to Containers
Building a CICD Pipeline for Deploying to ContainersBuilding a CICD Pipeline for Deploying to Containers
Building a CICD Pipeline for Deploying to Containers
 
Deploy, scale and manage your application with AWS Elastic Beanstal
Deploy, scale and manage your application with AWS Elastic BeanstalDeploy, scale and manage your application with AWS Elastic Beanstal
Deploy, scale and manage your application with AWS Elastic Beanstal
 
[AWS Dev Day] 실습워크샵 | Amazon EKS 핸즈온 워크샵
 [AWS Dev Day] 실습워크샵 | Amazon EKS 핸즈온 워크샵 [AWS Dev Day] 실습워크샵 | Amazon EKS 핸즈온 워크샵
[AWS Dev Day] 실습워크샵 | Amazon EKS 핸즈온 워크샵
 

Recently uploaded

Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfSeasiaInfotech2
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesZilliz
 

Recently uploaded (20)

Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdf
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector Databases
 

Automating Zero-Downtime Production Cluster Upgrades for Amazon ECS

  • 2. Matt Callanan Engineering Manager/Tech Lead “Cloud Acceleration Team” Expedia Brisbane, Australia • mcallanan@expedia.com • linkedin.com/in/matthewcallanan • @mcallana
  • 3. Cluster Management • How to upgrade the EC2 infrastructure underlying a live production Amazon ECS cluster without affecting service availability. • How to safely relocate hundreds of tasks onto new Amazon EC2 instances with zero-downtime to applications.
  • 4. Region 1 Region 2 Region 3 Region 4 Region 5 Expedia ECS Cluster Statistics 2,600 ECS Services (1,100 Applications) 13,000 Containers 860 EC2 Instances (13 ECS Clusters)
  • 5. Region 1 Region 2 Region 3 Region 4 Region 5 Expedia ECS Cluster Topology Production Cluster Test Environment Cluster 480 Services 230 Instances
  • 6. Production Cluster Visualization 230 Instances 480 Services 3,200 Containers c3vis Open Source: https://github.com/ExpediaDotCom/c3vis
  • 7. ECS Cluster Creation Cloud Formation Stack EC2 Instances Auto Scaling Group Amazon ECS Cluster
  • 8. Immutable Servers Amazon-provided Base AMI Standard Chef cookbook Custom setup baked into AMI ecs-optimized AMI Expedia standard image Docker Config Daemon containers Golden AMI docker ecs-agent
  • 9. Immutable Servers ecs-optimized AMI Expedia standard image Docker Config Daemon containers Golden AMI docker ecs-agent ecs-optimized AMI Expedia standard image Docker Config Daemon containers Cluster Instance Custom bootstrap: • ECS Cluster Config • Start ECS Agent, Docker • Cron: Restart ECS agent • Cron: Custom Metrics docker ecs-agent
  • 11. First Approach • CloudFormation Auto-Scaling Rolling Update
  • 12. Default Cloud Formation Auto-Scaling Rolling Update Old Instance New Instance Terminating Instance Active Task Relocated Task Stopped Task
  • 13. Default Cloud Formation Auto-Scaling Rolling Update A A Old Instance New Instance Terminating Instance Active Task Relocated Task Stopped Task
  • 14. Default Cloud Formation Auto-Scaling Rolling Update A A Old Instance New Instance Terminating Instance Active Task Relocated Task Stopped Task Problem: Tasks stop before they are relocated. Even with tasks on distinct instances, outage can happen if new instances are not pulling images fast enough
  • 15. Default Cloud Formation Auto-Scaling Rolling Update A Old Instance New Instance Terminating Instance Active Task Relocated Task Stopped Task
  • 16. Default Cloud Formation Auto-Scaling Rolling Update A A Problem: Tasks start on instances about to be terminated Old Instance New Instance Terminating Instance Active Task Relocated Task Stopped Task
  • 17. Default Cloud Formation Auto-Scaling Rolling Update A A Old Instance New Instance Terminating Instance Active Task Relocated Task Stopped Task
  • 18. Default Cloud Formation Auto-Scaling Rolling Update A A Old Instance New Instance Terminating Instance Active Task Relocated Task Stopped Task
  • 19. Default Cloud Formation Auto-Scaling Rolling Update A A Old Instance New Instance Terminating Instance Active Task Relocated Task Stopped Task
  • 20. Default Cloud Formation Auto-Scaling Rolling Update A A Old Instance New Instance Terminating Instance Active Task Relocated Task Stopped Task
  • 21. Default Cloud Formation Auto-Scaling Rolling Update A A Old Instance New Instance Terminating Instance Active Task Relocated Task Stopped Task
  • 22. Default Cloud Formation Auto-Scaling Rolling Update A A Old Instance New Instance Terminating Instance Active Task Relocated Task Stopped Task
  • 23. Default Cloud Formation Auto-Scaling Rolling Update A Old Instance New Instance Terminating Instance Active Task Relocated Task Stopped Task
  • 24. Default Cloud Formation Auto-Scaling Rolling Update A Old Instance New Instance Terminating Instance Active Task Relocated Task Stopped Task
  • 25. Default Cloud Formation Auto-Scaling Rolling Update A Old Instance New Instance Terminating Instance Active Task Relocated Task Stopped Task
  • 26. Default Cloud Formation Auto-Scaling Rolling Update A Old Instance New Instance Terminating Instance Active Task Relocated Task Stopped Task
  • 27. Default Cloud Formation Auto-Scaling Rolling Update Old Instance New Instance Terminating Instance Active Task Relocated Task Stopped Task Problem: Service “A” experiences downtime
  • 28. Default Cloud Formation Auto-Scaling Rolling Update A Old Instance New Instance Terminating Instance Active Task Relocated Task Stopped Task
  • 29. Default Cloud Formation Auto-Scaling Rolling Update A Old Instance New Instance Terminating Instance Active Task Relocated Task Stopped Task
  • 30. Default Cloud Formation Auto-Scaling Rolling Update A A Old Instance New Instance Terminating Instance Active Task Relocated Task Stopped Task
  • 31. Default Cloud Formation Auto-Scaling Rolling Update A A Old Instance New Instance Terminating Instance Active Task Relocated Task Stopped Task
  • 32. Default Cloud Formation Auto-Scaling Rolling Update A A Old Instance New Instance Terminating Instance Active Task Relocated Task Stopped Task Problem: Tasks bunch up on first few new instances
  • 33. First Approach: Problem Summary • CloudFormation  AutoScaling Asynchrony • Rolling Update not granular enough • Outside our control • Rollbacks with no ability for manual intervention • Tasks stop before they are relocated • Service outage can happen if new instances are not pulling images fast enough • Tasks are not evenly spread across new instances CloudFormation Auto Scaling
  • 34. Second Approach • Custom Rolling Update automation • Programmatic Update Script using Ruby SDK • But still took 10 (nail-biting) hours to update a cluster with 100 instances • Any issues during the process required manual intervention Auto Scaling
  • 35. Third Approach • “PRISM” • Project Replaced in Sixty Minutes
  • 36. “PRISM” Goals • Zero-downtime for applications as their workloads get relocated onto new instances Safety • Complete as fast as possible Speed • Quickly retreat back to known-good state if anything goes wrong Rollbackable • Resumeable if anything goes wrong Idempotent • Drain in batches to prevent burden on Docker registry and network • Avoid having tasks relocated to instances about to be drained Avoid “thundering herd” scenario
  • 37. “PRISM” Phases Phase 1: Expand Phase 2: Relocate Tasks Phase 3: Clean Up
  • 38. Zero-Downtime Cluster Updates Cloud Formation Stack EC2 Instances Auto Scaling group Amazon ECS Cluster
  • 39. Amazon ECS Cluster Cloud Formation Stack EC2 Instances Auto Scaling group Cloud Formation Stack EC2 Instances Auto Scaling group Zero-Downtime Cluster Updates Phase 1: Expand Cluster
  • 40. Zero-Downtime Cluster Updates Phase 2: Relocate Tasks Amazon ECS Cluster Cloud Formation Stack EC2 Instances Auto Scaling group Cloud Formation Stack EC2 Instances Auto Scaling group Draining…
  • 41. Zero-Downtime Cluster Updates Phase 3: Clean Up Amazon ECS Cluster Cloud Formation Stack EC2 Instances Auto Scaling group Cloud Formation Stack EC2 Instances Auto Scaling group
  • 42. Zero-Downtime Cluster Updates Phase 3: Clean Up Amazon ECS ClusterCloud Formation Stack EC2 Instances Auto Scaling group
  • 43. Old Instance New Instance Draining Instance A Active Task Relocated Task “DRAINING” Task A Blue Auto-Scaling Group Blue CFN Stack Cluster Update – Phase 1: Expand
  • 44. AA Blue Auto-Scaling Group Blue CFN Stack Disable Auto-Scaling Processes Cluster Update – Phase 1: Expand Old Instance New Instance Draining Instance Active Task Relocated Task “DRAINING” Task
  • 45. AA Blue Auto-Scaling Group Blue CFN Stack Green Auto-Scaling Group Green CFN Stack Disable Auto-Scaling Processes Disable Auto-Scaling Processes Cluster Update – Phase 1: Expand Old Instance New Instance Draining Instance Active Task Relocated Task “DRAINING” Task
  • 46. AA Blue Auto-Scaling Group Blue CFN Stack Green Auto-Scaling Group Green CFN Stack state = ‘pre-drain’ Disable Auto-Scaling Processes Disable Auto-Scaling Processes Cluster Update – Phase 1: Expand Old Instance New Instance Draining Instance Active Task Relocated Task “DRAINING” Task
  • 47. AA Blue Auto-Scaling Group Blue CFN Stack Green Auto-Scaling Group Green CFN Stack Disable Auto-Scaling Processes Cluster Update – Phase 2: Relocate Tasks (batches of 3 instances) Old Instance New Instance Draining Instance Active Task Relocated Task “DRAINING” Task Disable Auto-Scaling Processes state = ‘pre-drain’
  • 48. Blue Auto-Scaling Group Blue CFN Stack Green Auto-Scaling Group Green CFN Stack Disable Auto-Scaling Processes Cluster Update – Phase 2: Relocate Tasks (batches of 3 instances) Old Instance New Instance Draining Instance Active Task Relocated Task “DRAINING” Task AA state = ‘pre-drain’ Disable Auto-Scaling Processes
  • 49. Blue Auto-Scaling Group Blue CFN Stack Green Auto-Scaling Group Green CFN Stack Disable Auto-Scaling Processes Cluster Update – Phase 2: Relocate Tasks (batches of 3 instances) Old Instance New Instance Draining Instance Active Task Relocated Task “DRAINING” Task A AAA state = ‘pre-drain’ Disable Auto-Scaling Processes
  • 50. Blue Auto-Scaling Group Blue CFN Stack A A Green Auto-Scaling Group Green CFN Stack Disable Auto-Scaling Processes Cluster Update – Phase 2: Relocate Tasks (batches of 3 instances) Old Instance New Instance Draining Instance Active Task Relocated Task “DRAINING” Task AA state = ‘pre-drain’ Disable Auto-Scaling Processes
  • 51. Blue Auto-Scaling Group Blue CFN Stack A A Green Auto-Scaling Group Green CFN Stack Disable Auto-Scaling Processes Cluster Update – Phase 2: Relocate Tasks (batches of 3 instances) Old Instance New Instance Draining Instance Active Task Relocated Task “DRAINING” Task state = ‘pre-drain’ Disable Auto-Scaling Processes
  • 52. Blue Auto-Scaling Group Blue CFN Stack A Green Auto-Scaling Group Green CFN Stack Disable Auto-Scaling Processes Cluster Update – Phase 2: Relocate Tasks (batches of 3 instances) Old Instance New Instance Draining Instance Active Task Relocated Task “DRAINING” Task A state = ‘pre-drain’ Disable Auto-Scaling Processes
  • 53. Blue Auto-Scaling Group Blue CFN Stack A Green Auto-Scaling Group Green CFN Stack Disable Auto-Scaling Processes Cluster Update – Phase 2: Relocate Tasks (batches of 3 instances) Old Instance New Instance Draining Instance Active Task Relocated Task “DRAINING” Task A state = ‘pre-drain’ Disable Auto-Scaling Processes
  • 54. Blue Auto-Scaling Group Blue CFN Stack A A Green Auto-Scaling Group Green CFN Stack Disable Auto-Scaling Processes Cluster Update – Phase 2: Relocate Tasks (batches of 3 instances) Old Instance New Instance Draining Instance Active Task Relocated Task “DRAINING” Task state = ‘pre-drain’ Disable Auto-Scaling Processes
  • 55. Blue Auto-Scaling Group Blue CFN Stack A A Green Auto-Scaling Group Green CFN Stack Disable Auto-Scaling Processes Cluster Update – Phase 2: Relocate Tasks (batches of 3 instances) Old Instance New Instance Draining Instance Active Task Relocated Task “DRAINING” Task state = ‘pre-drain’ Disable Auto-Scaling Processes
  • 56. A A Green Auto-Scaling Group Green CFN Stack Disable Auto-Scaling Processes Cluster Update – Phase 3: Clean Up Old Instance New Instance Draining Instance Active Task Relocated Task “DRAINING” Task
  • 57. A A Green Auto-Scaling Group Green CFN Stack Resume Auto-Scaling Processes Cluster Update – Phase 3: Clean Up Old Instance New Instance Draining Instance Active Task Relocated Task “DRAINING” Task
  • 59. Pre-flight Checks • Before Cluster Create/Update • Check # instances available of target instance type • Check IP addresses available in target subnets • Check EBS volume space available of target volume type
  • 60. Drain on Scale-down with Lifecycle Lambda • Lambda triggered by AutoScaling EC2_INSTANCE_TERMINATE SNS events • Updates instance state to “DRAINING” • ASG has 30-minute heartbeat to keep instance in Terminating:Wait state for 30mins • Allows ECS to safely relocate any tasks that are part of a service to another instance
  • 61. AutoScaling Lifecycle Hook resource "ECSContainerInstanceTerminating", Type: "AWS::AutoScaling::LifecycleHook", Properties: { AutoScalingGroupName: ref("ECSAutoScalingGroup"), LifecycleTransition: "autoscaling:EC2_INSTANCE_TERMINATING", DefaultResult: "CONTINUE", RoleARN: ref("LifecycleHookRoleARN"), NotificationTargetARN: ref("ECSAutoscalingLifecycleTopic"), HeartbeatTimeout: 1800 # 30 minutes },
  • 62. Avoid Relocating to Old Instance • Problem: • Tasks can get rescheduled to another old instance in the ASG that is about to be replaced - so tasks can get bumped from instance to instance until all instances are replaced • Solution: • Deploy services with placement constraint • This means that a service won’t be placed on an instance that has an attribute named “state” with value “pre-drain” • At cluster replacement time, we will stand up all new clusters, place old clusters into the “pre- drain” state, and terminate the old instances in batches. • Relocated tasks will only be placed on new instances, avoiding the default “thundering herd” scenario placement_constraints = [ { type: 'memberOf', expression: 'attribute:state !exists or attribute:state != pre-drain' }]
  • 64. Task Definition Placement Constraint • “state” is a custom ECS Instance Attribute • By default, the “state” attribute doesn’t exist on instances • Set only to “pre-drain” during cluster update • Prevents ECS scheduling tasks on instances that are about to be drained • Removed from instance only in case of rollback of cluster update
  • 65. Instance Launch Considerations • Worked with AWS Auto-Scaling team to enable more appropriate Auto-Scaling “Launch Rate” • Start the ECS agent with exponential backoff • Throttle on container instance registration rate = 1 per second/60 max per minute
  • 66. Gotchas • Found a number of apps don't relocate easily • Slows down prod upgrades and old stack decommissions
  • 67. Related AWS re:invent 2017: Going Big with Containers: Customer Case Studies of Large-Scale (ENT209) • https://www.youtube.com/watch?v=L3l_ZiYRrks • Covers full scope of Expedia’s ECS deployment automation platform