简体   繁体   中英

How Autoscaling works in ECS?

I am new to the AWS ECS. I am trying to understand Tasks and EC2 instances in the context of ECS Autoscaling. I have one Task definition. This means that when the Task is created under a service, there will be one EC2 instance. Suppose if the service needs to be scaled out through autoscaling. What happens in this scenario?. Following are my queries:

1) If I have mentioned 1 EC2 instance in the Cluster setting, what will happen to the autoscaling? Will it create a new EC2 instance?

2) Can autoscaling create two tasks in the same EC2 instance if there is enough free resource in the 1st EC2 instance? If so, What will happen to the port, because now there will be two tasks with the same port mapping.

3) This is not related to the Autoscaling, but if I have two different task definition with the same port name. Does it mean that these tasks will run on two different EC2 instances in the cluster?

1) If I have mentioned 1 EC2 instance in the Cluster setting, what will happen to the autoscaling? Will it create a new EC2 instance?
A)If you have configured ec2-autoscaling and scaling policy. Based on that it will create the new ec2 instance.

2) Can autoscaling create two tasks in the same EC2 instance if there is enough free resource in the 1st EC2 instance? If so, What will happen to the port, because now there will be two tasks with the same port mapping.
A)So In ECS, two task of the same service will not run on the same instance because of the High Availability.

3) This is not related to the Autoscaling, but if I have two different task definition with the same port name. Does it mean that these tasks will run on two different EC2 instances in the cluster?
A) No, if the resource is available it will run on the same or different ec2-instance. Don't worry about the port number as whatever you have defined on task definition that is the container port number and each container run on the same port. So it can be same across task definition.

Elaborating a bit more on the same containers running on the same host. No, auto-scaling is not going to launch more of the same containers on the same EC2 instance (unless you have more tasks than EC2 instances, and the tasks don't have overlapping ports). If you worry about container ports being the same for copies of the same container then what you can do is to specify dynamic port mapping in your task configuration. Then your containers will receive randomly picked up outbound port from the range of ephemeral ports. You can place those containers into a single target group which can be targeted by Application Load Balancer.

You can run multiple same/different tasks per cluster and even per EC2 instance but the underlying containers can't share the same outbound port. If your instance already runs a container which is listening on port 80, launching another container that would listen on the same port will automatically fail. So the answer to your 3rd question is yes, they will need to run on different instances.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM