ECS task placement strategy to deploy across group of ec2 instances

0

Scenario - 2 t3.medium machines registered to the ecs cluster. I want to run 9 java microservices containers Should I create a single task definition and have all the containers in it and have a service with placement strategy set to spread across instanceids? - IS ecs smart enough to decide the container placement across instances based on the cpu and memory available in them? OR Should I create a task definition for each microservice? Please advise on what is the better approach and best practices.

asked 2 months ago158 views
2 Answers
0

Hi,

Is it a real requirement for you to run with ECS on your own EC2 instances? If not, I would suggest to switch to Fargate, which is the serverless version of ECS. It will handle scaling, placement, HA, etc. for you.

So, less "heavy lifting" on your side.

See https://aws.amazon.com/fargate/

Additionally, for some use cases, Fargate may prove cheaper then EC2: it depends on the utilization of your instances. See this blog post for some calculations to see which one is better: https://aws.amazon.com/blogs/containers/theoretical-cost-optimization-by-amazon-ecs-launch-type-fargate-vs-ec2/

Best,

Didier

profile pictureAWS
EXPERT
answered 2 months ago
  • Hi @Didier_Durand, Thanks for answering for my question If we pick fargate launch type then it will be very expensive. That's because we pick EC2 instead of fargete

    Fargate calculation

    Number of tasks or pods: 1 per day * (730 hours in a month / 24 hours in a day) = 30.42 per month
    Average duration: 30 days = 720 hours
    

    Pricing calculations 30.42 tasks x 2 vCPU x 720 hours x 0.04048 USD per hour = 1,773.22 USD for vCPU hours 30.42 tasks x 4.00 GB x 720 hours x 0.004445 USD per GB per hour = 389.42 USD for GB hours 20 GB - 20 GB (no additional charge) = 0.00 GB billable ephemeral storage per task 1,773.22 USD for vCPU hours + 389.42 USD for GB hours = 2,162.64 USD total Fargate cost (monthly): 2,162.64 USD

0

All containers in a task are run on the same host. If you want to spread those 9 containers over both hosts, you should put them into minimum of 2 tasks, or have task per container if it doesn't make difference where individual container is run (same or different host).

The task definition is a document that describes what container images to run together, and what settings to use when running the container images.

See https://docs.aws.amazon.com/AmazonECS/latest/bestpracticesguide/application.html

profile picture
EXPERT
Kallu
answered 2 months 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.

Guidelines for Answering Questions