How to scale ecs cluster with autoscaling? - amazon-web-services

I think you have 2 scaling
1 for ec2 instance
1 for ecs task
So I think flow goes like
You get more requests
Your tasks need more resources (cpu/memory)
Your ecs task autoscaling kicks in and creates more task
your ec2 autoscaling also kicks in and creates more ec2
Questions
your ecs needs to know newly launched ec2 (from ec2 autoscaling group) is the host that it can run on (how?)
I want the number of ec2 instance starts from one.
I think one instance is already running in the ecs cluster
Do I make ec2 autoscaling group start from 0?
ec2 autoscaling group has pricing option to use spot instance, but I didn't see such option when I created ecs cluster instances. To be clear, can I make ecs cluster with 0 ecs-instance, and let ec2 autoscaling group starts with 1 instance?

Your ecs task autoscaling kicks in and creates more task
your ec2 autoscaling also kicks in and creates more ec2
Your ECS task scale if there is a memory so fine it will scale and launch new container, if not enough memory then it will not launch an instance, you need to configure cloud watch alarm to scale ECS cluster based on the task scaling.
Tutorial: Scaling Container Instances with CloudWatch Alarms
your ecs needs to know newly launched ec2 (from ec2 autoscaling group)
is the host that it can run on (how?)
ECS agent registers the new instance with the same cluster, and the new task can be placed in any instance that have available resources to handle and launch the container.
I want the number of ec2 instance starts from one. I think one
instance is already running in the ecs cluster Do I make ec2
autoscaling group start from 0?
You should start from 1 otherwise no container will launch and will throw error no instance found in the cluster. if you do not want run container for now then you can start from 0.
ec2 autoscaling group has pricing option to use spot instance, but I
didn't see such option when I created ecs cluster instances. To be
clear, can I make ecs cluster with 0 ecs-instance, and let ec2
autoscaling group starts with 1 instance?
You can read about spot ECS cluster instance here.
Amazon ECS is a highly scalable, high performance, container
management service that supports Docker containers and allows you to
run applications on a managed cluster of Amazon EC2 instances easily.
ECS already handles the placement and scheduling of containers on EC2
instances. When combined with Spot fleet, ECS can deliver significant
savings over EC2 on-demand pricing.

Related

EKS and ECS Pricing confusion

I have one confusion, did we need to pay for ECS separately, if i had already EKS cluster with t3.medium EC2 instance as worker node. Because in documentation i found that there is no addition charge for ECS if we have EC2 instance.
EKS (Elastic Kubernetes Service) and ECS (Elastic Container Service) are two distinct services on AWS. Both are used for container orchestration. EKS, as the name suggests, is a managed Kubernetes cluster whereas ECS is an AWS-native solution.
Both EKS and ECS can be used on top of either EC2 instances or on Fargate. Fargate is a “serverless” solution in the sense that it manages the underlying servers and the autoscaling for you.
If you run ECS on EC2 instances instead of Fargate, you will only pay for the EC2 instances, just like normal. There is no additional cost for the fact that you run an ECS cluster on top of them. EKS however does charge you for the cluster itself, regardless of the underlying launch type.

Does Fargate need HA

I have an auto scaling ECS cluster backed by fargate. The lower bound is 1 instance. Would i need to worry about HA? Lets say an AZ crashes, wouldnt the cluster logic spawn it in another AZ, does this imply that among other benefits, Fargate cuts out the HA/redundancy cost as well, with some service degrade of course
Only if you run your ECS service in vpc with subnets in more then one AZ. If you just run a single ECS task (not ECS service), you will not have HA.

Differences between EC2 Auto Scaling Group (EC2 ASG) and Elastic Container Service (ECS)

From what I've read so far:
EC2 ASG is a simple solution to scale your server with more copies of it with a load balancer in front of the EC2 instance pool
ECS is more like Kubernetes, which is used when you need to deploy multiple services in docker containers that works with each other internally to form a service, and auto scaling is a feature of ECS itself.
Are there any differences I'm missing here? Because ECS is almost always a superior choice to go with if they work as I understand.
You are right, in a very simple sense, EC2 Autoscaling Groups is a way to add/remove (register/unregister) EC2 instances to a Classic Load Balancer or Target Groups (ALB/NLB).
ECS has two type of scaling as does any Container orchestration platform:
Cluster Autoscaling: Add remove EC2 instances in a Cluster when tasks are pending to run
Service Autoscaling: Add/remove tasks in a service based on demand, uses Application AutoScaling service behind the scenes

aws ecs autoscaling instances

Currently I am struggling with AWS auto scaling.
Do I need to create instance Auto Scaling Group in parallel to ECS Service Auto Scaling to provision necessary resources for services/tasks, or it is managed automatically by the latter one?
edit:
I am using api/cloudformation only, no web interface.
ECS service scaling and And EC2 instance scaling are independent entities. EC2 instance scaling is not handled if you configure ECS service scaling. It is required(Mandotory) to configure EC2 Instance scaling and maintain enough resources in the cluster if you are opting ECS Service scaling, otherwise ECS service fails to place new Tasks during service scaling activities. In general, it is recommended to scale EC2 Instances based on CPUReservation and MemoryReservation cloudwatch alarms.
EC2 Container Instance scaling tutorial: https://docs.aws.amazon.com/AmazonECS/latest/developerguide/cloudwatch_alarm_autoscaling.html

AWS EC2 Container Service Scale In Empty Container Instances

Let's suppose that i have an ECS cluster running a service, this service has some autoscaling policies applied to it. When this Service Scales Out, a new task is created, an alarm is then triggered for the AutoScaling group to Launch a new EC2 instance for the Task to Run. I have no troubles on that side.
On the other side, when this service scales In, a task is stoped and deleted. and alarm for Scaling In is triggered for the Autoscaling Group to Terminate an EC2 Instance.
To my knowledge, an AWS Autoscaling Group terminates an EC2 instance (within the group) Randomly in the case of DownScale. Is that so ?
If that's Correct ! is it possible to target only the empty Container Instances to be terminated in the case of DownScale ?