{"id":54960,"date":"2022-04-30T13:05:04","date_gmt":"2022-04-30T07:35:04","guid":{"rendered":"https:\/\/www.tothenew.com\/blog\/?p=54960"},"modified":"2022-05-19T14:28:18","modified_gmt":"2022-05-19T08:58:18","slug":"ecs-cluster-auto-scaling","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/ecs-cluster-auto-scaling\/","title":{"rendered":"Beginner&#8217;s Guide to ECS"},"content":{"rendered":"<h2><strong>Introduction<\/strong><\/h2>\n<p>Amazon ECS (Elastic Container Service) is a highly scalable &amp; fully managed container orchestration service that allows us to easily run, manage and scale containerized applications on AWS.<\/p>\n<p>With ECS, it\u2019s not required to manually install or operate any container orchestration software, or even to schedule containers on a set of computing machines.<\/p>\n<p>Also, there\u2019s a concept of ECS Capacity Providers which is configured to provide the resources\/infrastructure that will be used by the workloads run within the cluster. In a cluster, it\u2019s possible to have multiple capacity providers and an optional default capacity provider strategy.<\/p>\n<p>The capacity provider strategy determines how the workloads are spread across the cluster&#8217;s capacity providers. We can opt for the strategy depending on our requirements when we run any task. There are some different types of capacity providers as well, depending on whether we\u2019ve our workloads hosted on EC2 or Fargate.<\/p>\n<h2><strong>Problem Statement<\/strong><\/h2>\n<p>Running containers without using any container orchestration service would lead us to manage a lot of extra tasks such as:<\/p>\n<ol>\n<li>Configuring Auto Scaling of containers would have to be managed externally.<\/li>\n<li>It\u2019s highly possible that we might be deprived of some very good services provided by managed cloud providers such as the ability to use serverless services (like Fargate by AWS ECS).<\/li>\n<li>Also, we\u2019ll have to set up alternatives related to the integration with log configuration systems, and file systems such as NFS\/EFS.<\/li>\n<\/ol>\n<h2><strong>Solution Approach<\/strong><\/h2>\n<p>In our case, since most of the client\u2019s infrastructure was already running over AWS, therefore, we opted for ECS as the container orchestrator which is a proprietary technology provided by AWS.<br \/>\nOne of the primary reasons for choosing ECS is its tight integrations with a variety of other AWS Services such as Dynamic Port Mapping, CloudWatch, EFS, etc.<\/p>\n<p>In ECS, we\u2019re provided with 2 different launch type options from AWS, that goes as follows:<\/p>\n<ol>\n<li><em>Fargate<\/em>: A serverless compute engine, with us not required to manage servers.<\/li>\n<li><em>EC2<\/em>: Self-managed infrastructure using Amazon EC2 Instances.<\/li>\n<\/ol>\n<p>With Auto-Scaling, the main benefit is that it eliminates the need for us to continuously monitor &amp; respond to real-time traffic spikes, &amp; rather, this workload is performed automatically using the CloudWatch service that further leads to the creation of new resources.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"size-full wp-image-54954 aligncenter\" src=\"\/blog\/wp-ttn-blog\/uploads\/2022\/04\/imgonline-com-ua-resize-RXmVWC7Xf4jA.jpg\" alt=\"\" width=\"752\" height=\"360\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2022\/04\/imgonline-com-ua-resize-RXmVWC7Xf4jA.jpg 752w, \/blog\/wp-ttn-blog\/uploads\/2022\/04\/imgonline-com-ua-resize-RXmVWC7Xf4jA-300x144.jpg 300w, \/blog\/wp-ttn-blog\/uploads\/2022\/04\/imgonline-com-ua-resize-RXmVWC7Xf4jA-624x299.jpg 624w\" sizes=\"(max-width: 752px) 100vw, 752px\" \/><\/p>\n<p>The 3 values that we need to provide the value in ASG are Minimum, Desired, and a Maximum number of tasks, and then, it\u2019s required to create a Scaling Policy. (It defines what action to take when the associated CloudWatch alarm is in ALARM state, or in reference to metric(s) being monitored)<\/p>\n<p>Auto-Scaling is an optional feature that comes with ECS Service and can be enabled even while modifying the already existing service.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"size-full wp-image-54955 aligncenter\" src=\"\/blog\/wp-ttn-blog\/uploads\/2022\/04\/Screenshot-from-2022-04-28-12-31-12.png\" alt=\"\" width=\"713\" height=\"254\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2022\/04\/Screenshot-from-2022-04-28-12-31-12.png 713w, \/blog\/wp-ttn-blog\/uploads\/2022\/04\/Screenshot-from-2022-04-28-12-31-12-300x107.png 300w, \/blog\/wp-ttn-blog\/uploads\/2022\/04\/Screenshot-from-2022-04-28-12-31-12-624x222.png 624w\" sizes=\"(max-width: 713px) 100vw, 713px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"size-full wp-image-54956 aligncenter\" src=\"\/blog\/wp-ttn-blog\/uploads\/2022\/04\/Screenshot-from-2022-04-28-12-31-46.png\" alt=\"\" width=\"741\" height=\"492\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2022\/04\/Screenshot-from-2022-04-28-12-31-46.png 741w, \/blog\/wp-ttn-blog\/uploads\/2022\/04\/Screenshot-from-2022-04-28-12-31-46-300x199.png 300w, \/blog\/wp-ttn-blog\/uploads\/2022\/04\/Screenshot-from-2022-04-28-12-31-46-624x414.png 624w\" sizes=\"(max-width: 741px) 100vw, 741px\" \/><\/p>\n<p><strong>Step by Step Procedure:<\/strong><\/p>\n<p>Under Automatic task scaling policies, when we click on \u201cAdd Scaling Policy\u201d, we get 2 types as mentioned below:<\/p>\n<ol>\n<li>Target Tracking<\/li>\n<li>Step Scaling<\/li>\n<\/ol>\n<p><em>Target Tracking:<\/em><\/p>\n<p>With target tracking scaling, we select a scaling metric and set a target value. CloudWatch alarms that are associated with the target tracking scaling policies are managed by AWS and deleted automatically when no longer needed, so, we\u2019re not managing the alarms, in this case.<\/p>\n<p>We get the option to be monitoring among 3 service metrics during its configuration, which goes as follows:<\/p>\n<ol>\n<li>ECSServiceAverageCPUUtilization<\/li>\n<li>ECSServiceAverageMemoryUtilization<\/li>\n<li>ALBRequestCountPerTarget<\/li>\n<\/ol>\n<p>Under this, we would be required to provide the Target Value for the metric when scaling action would get triggered.<\/p>\n<p>Also, we get 2 types of cooldown periods to be configured here:<\/p>\n<ol>\n<li>Scale-Out Cooldown Period (The number of seconds in b\/w 2 scale-out activities)<\/li>\n<li>Scale-In Cooldown Period (The number of seconds in b\/w 2 scale-in activities)<\/li>\n<\/ol>\n<p>However, it\u2019s also possible to \u201cDisable Scale-In\u201d action, with which this policy would never be used for scale-in within the ASG.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"size-full wp-image-54957 aligncenter\" src=\"\/blog\/wp-ttn-blog\/uploads\/2022\/04\/Screenshot-from-2022-04-28-12-34-15.png\" alt=\"\" width=\"700\" height=\"379\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2022\/04\/Screenshot-from-2022-04-28-12-34-15.png 700w, \/blog\/wp-ttn-blog\/uploads\/2022\/04\/Screenshot-from-2022-04-28-12-34-15-300x162.png 300w, \/blog\/wp-ttn-blog\/uploads\/2022\/04\/Screenshot-from-2022-04-28-12-34-15-624x338.png 624w\" sizes=\"(max-width: 700px) 100vw, 700px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"size-full wp-image-54958 aligncenter\" src=\"\/blog\/wp-ttn-blog\/uploads\/2022\/04\/Screenshot-from-2022-04-28-12-35-09.png\" alt=\"\" width=\"697\" height=\"394\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2022\/04\/Screenshot-from-2022-04-28-12-35-09.png 697w, \/blog\/wp-ttn-blog\/uploads\/2022\/04\/Screenshot-from-2022-04-28-12-35-09-300x170.png 300w, \/blog\/wp-ttn-blog\/uploads\/2022\/04\/Screenshot-from-2022-04-28-12-35-09-624x353.png 624w\" sizes=\"(max-width: 697px) 100vw, 697px\" \/><\/p>\n<p><em>Step Scaling:<\/em><\/p>\n<p>Step scaling is one of the dynamic scaling options available for us to use &amp; requires us to create CloudWatch alarms for the policy, however, we can also use existing alarms if any.<\/p>\n<p>On the ECS Console, we can get a new alarm created by choosing the ECS service metric option to be either \u201cCPUUtilization\u201d or \u201cMemoryUtilization\u201d.<\/p>\n<p>To scale the ECS service with other metrics, we can create our own alarms via the CloudWatch Console.<\/p>\n<p>And finally, the alarm threshold can be set, depending on the application traffic load that can be handled by a single container\/task, for which load testing via the Apache Jmeter tool is recommended.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"size-full wp-image-54959 aligncenter\" src=\"\/blog\/wp-ttn-blog\/uploads\/2022\/04\/Screenshot-from-2022-04-28-12-36-16.png\" alt=\"\" width=\"711\" height=\"359\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2022\/04\/Screenshot-from-2022-04-28-12-36-16.png 711w, \/blog\/wp-ttn-blog\/uploads\/2022\/04\/Screenshot-from-2022-04-28-12-36-16-300x151.png 300w, \/blog\/wp-ttn-blog\/uploads\/2022\/04\/Screenshot-from-2022-04-28-12-36-16-624x315.png 624w\" sizes=\"(max-width: 711px) 100vw, 711px\" \/><\/p>\n<p><strong>Debugging:<\/strong><\/p>\n<p>Initially, there were a few cases when CloudWatch Alarms were not configured appropriately due to which containers were not scaling in the desired manner.<\/p>\n<p>Apart from this, as per our architecture, it was required to know, when the FileSystem mounting is going to actually take place within the container among the multiple steps that are involved, so this was surely something that we&#8217;d to look over.<\/p>\n<p><strong>Conclusion:<\/strong><\/p>\n<p>Hence, the powerful simplicity of Amazon ECS enables us to grow from a single Docker container to managing an entire enterprise application portfolio. It\u2019s recommended to take advantage of the Auto Scaling option provided under ECS, which makes the application infrastructure to be highly automated.<\/p>\n<div class=\"ap-custom-wrapper\"><\/div><!--ap-custom-wrapper-->","protected":false},"excerpt":{"rendered":"<p>Introduction Amazon ECS (Elastic Container Service) is a highly scalable &amp; fully managed container orchestration service that allows us to easily run, manage and scale containerized applications on AWS. With ECS, it\u2019s not required to manually install or operate any container orchestration software, or even to schedule containers on a set of computing machines. Also, [&hellip;]<\/p>\n","protected":false},"author":1457,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":8},"categories":[1174,4308,2348,1],"tags":[4965],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/54960"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/1457"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=54960"}],"version-history":[{"count":4,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/54960\/revisions"}],"predecessor-version":[{"id":55013,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/54960\/revisions\/55013"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=54960"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=54960"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=54960"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}