- Newest
- Most votes
- Most comments
To achieve the desired auto scaling behavior for your ECS cluster with EC2 launch type, you'll need to configure both service auto scaling and cluster auto scaling. Here's how you can set this up:
-
Service Auto Scaling:
- Use Application Auto Scaling to manage your ECS service scaling.
- Set up a target tracking scaling policy based on memory utilization with a target value of 85%.
- Configure the scale-out and scale-in cooldown periods. For scale-in, set it to 3 minutes to match your requirement.
-
Cluster Auto Scaling:
- Create an ECS Auto Scaling group capacity provider.
- Set the target capacity to 100% as you've already done.
- The capacity provider will automatically create CloudWatch alarms and a target tracking scaling policy for the EC2 Auto Scaling group.
-
EC2 Auto Scaling Group Configuration:
- Use Launch Templates or Launch Configurations to define the EC2 instances.
- Set appropriate minimum and maximum capacity limits.
To address your specific questions:
-
Controlling EC2 instance termination during scale-in: You can influence which EC2 instances get terminated by using termination policies. Options include terminating the oldest or newest instances, or instances closest to the next billing hour. However, you can't precisely control which specific instance gets terminated.
-
Keeping a buffer EC2 instance ready: Unfortunately, there isn't a way to keep a "ready" EC2 instance without incurring charges. However, you can optimize instance launch times by:
- Using Amazon ECS-optimized AMIs
- Pre-pulling container images
- Using instance warm-up periods in your Auto Scaling group
Best practices:
- Regularly monitor and adjust your scaling policies based on observed patterns.
- Use the CapacityProviderReservation metric in CloudWatch to track cluster utilization.
- Set appropriate cooldown periods to prevent rapid fluctuations.
- Ensure the instanceWarmupPeriod is sufficient for new instances to be ready.
By implementing these configurations, your ECS cluster should scale out when memory usage reaches 85%, launching new tasks and EC2 instances as needed. It will scale in when memory usage stays below 85% for 3 minutes, first by stopping tasks and then terminating EC2 instances when capacity allows.
Sources
Amazon ECS EC2-backed auto scale-out and scale-in | AWS re:Post
Configuring service auto scaling - Amazon Elastic Container Service
Optimize Amazon ECS service auto scaling - Amazon Elastic Container Service
Scaling - Containers on AWS
Relevant content
- asked 3 years ago
- asked 2 months ago
- AWS OFFICIALUpdated 5 months ago
- AWS OFFICIALUpdated 3 months ago