Skip to content

ECS Task Deployment Doesn't Reserve More Capacity

0

When using EC2 instances for ECS capacity and using 'host' networking mode for the containers (not 'awsvpc' because I want to avoid having NAT), setting a target capacity at 100 (Any instances that are not running tasks are scaled in according to the https://repost.aws/knowledge-center/ecs-capacity-provider-scaling), the new instance wouldn't be created to satisfy a pending deployment instead it would just tell me that it failed since the container port is taken already on the already existing ec2 instance. How do I make it so that it either:

  • Shut down the current task and deploy the new version of the task.
  • Use ASG capacity and create a new instance so that the deployment can be done and then scale down the old one.

If this is how I see it currently, I would need to have a spare instance always running for my deployments to work. But there is a major problem with that one task requires two instances to roll the new version. If my tasks scale up and take up two instances, then for an update, I would need four instances on standby, etc.

asked 2 years ago534 views

1 Answer
2
Accepted Answer

The behavior you're experiencing is related to how ECS manages task placement and capacity. To address your concerns and improve your deployment strategy, you have a few options:

  1. Rolling Update Strategy: Instead of trying to deploy all tasks at once, you can use a rolling update strategy. This approach gradually replaces old tasks with new ones, allowing you to update your service without requiring additional capacity. You can configure this in your ECS service by setting a minimum healthy percent and maximum percent. For example, setting minimum healthy percent to 50% and maximum percent to 100% would allow half of your tasks to be replaced at a time.

  2. Capacity Provider Strategies: Ensure you have properly configured your capacity provider strategy. This allows ECS to manage the scaling of your EC2 instances based on task demand. You can set up a capacity provider linked to your Auto Scaling group, which will automatically scale out when there's not enough capacity to run your tasks.

  3. Task Placement Strategies: Review your task placement strategy. The default strategy is to spread tasks across Availability Zones, but you might want to consider using the 'binpack' strategy to maximize resource utilization on each instance before launching new ones.

  4. Draining Instances: Enable managed instance draining in your capacity provider settings. This allows ECS to gracefully remove tasks from an instance that's being scaled in, ensuring that new tasks can be placed on other instances.

  5. Service Auto Scaling: Implement service auto scaling, which can automatically adjust the desired count of tasks based on CloudWatch metrics. This can help ensure you have the right number of tasks running to handle your workload.

  6. Deregistration Delay: Configure a deregistration delay for your target group if you're using an Application Load Balancer. This gives time for in-flight requests to complete before an instance is removed from service.

By combining these strategies, you can create a more flexible and efficient deployment process that doesn't require maintaining excess capacity. The system will scale out when needed for deployments and scale back in when the extra capacity is no longer required, optimizing your resource usage and costs.

Remember to test your deployment strategy thoroughly in a non-production environment to ensure it behaves as expected before implementing it in your production setup.

Sources
ECS with EC2 no working auto-scaling | AWS re:Post
Does ECS have a limitation where only one task can run on the same EC2 instance? | AWS re:Post
Enable Capacity Rebalancing using the AWS Management Console or AWS CLI - Amazon EC2 Auto Scaling

answered 2 years ago

EXPERT

reviewed 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.