Auto Scaling Group(ASG)

 Auto Scaling Group(ASG)




What is Auto Scaling ?
  • Auto Scaling monitor your application and adjusts capacity automatically to ensure consistent, predictable performance at the lowest possible cost
  • It is simple to set up application scaling for multiple resources across multiple services using AWS autoscaling in minutes
  • Scaling is he process of adding and removing resources as needed
  • Scale out is removing resources and scale in is adding resources
  • Types - Vertical and Horizontal


Vertical Scaling - 
  • We having one single machine and we just increase the capacity of machine by adding more resources likes CPU, Storage etc.

Horizontal Scaling - 
  • We are adding more number of machines or nodes at the same time to existing pool of resources



Lifecycle of Auto Scaling -  



Auto Scaling Components - 

Auto Scaling Groups - 
  • Auto scaling group contains the collection of EC2 instances that are exactly the same 
  • While creating ASG launch configuration must be specified, after specifying the launch configuration cannot be change 
  • New instances are launched using a new configuration 
  • EC2 instances are launched and terminated using scaling policies


Configuration Template - 
  • Launch configuration is a template that is used to to launch EC2 instances for the autoscaling purpose 
  • Launch configuration cannot be modified after creation
  • It can be created in two ways 
  1. From scratch - Image type, instance id, storage etc.
  2. From EC2 Instance - Attributes from the inctance are copied. Block device mapping of AMI is included. Any additional device that are attached after launching the instances is not considered in the launch configuration


Scaling Policies - 

Scheduled Scaling - 
  • Scale based on a schedule
  • Used when the load is predictable
Simple Scaling - 
  • Scale to certain size on a cloudwatch alarm
  • Ex. when CPU > 90%,  then scale to 10 instances
Step Scaling - 
  • Scaling in steps using cloudwatch alarms
  • Specify the instance warmup to scale faster
  • Ex. when CPU 70% >,then add 2 units and when CPU <30%,then remove 1 unit
Traget Tracking Scaling - 
  • ASG maintains the cloudwatch metrics and scale accordingly (automatically creates cloudwatch alarms)
  • Ex. maintain CPU usage usage at 40%
Predictive Scaling - 
  • Historical data is used to predict the load using ML and scaling automatically



Scaling Cooldown - 
  • After a scaling happens, the ASG goes into cooldown period (default 300 sec) during which it does not launch or terminate additional instances (ignore scaling request) to allow the metrics stabilize
  • Use the ready-to-use AMI to launch instances faster to reduce the cooldown period


Health Checks - 
  • By default ASG uses EC2 status check (not the ELB health check). This could explain why some instances that are labelled as unhealthy instances by an ELB are still not terminated by ASG 
  • To prevent ASG from replacing unhealthy instances, suspend the ReplaceUnhealthy process type


Instance Termination ( Termination Policy) - 
  • Select the AZ with most number of instances
  • Delete the instance with the oldest launch configuration 
  • Delete the instance which is closest to the next billing hour
  • Flow diagram




Rebalancing AZs - 
  • ASG ensures that the group never goes below the minimum scale. Actions as changing the AZ for the group or explicity terminating or detaching instances can lead to the ASG becoming unbalanced between AZs. In such cases, ASG compensates by rebalancing the AZs by launching new instance before terminating the old one, so that rebalancing does not compromise performance or availability of the application 


Attach running instances to ann existing ASG -

The running instance must meet the following criteria - 
  • The AMI used to launch the instance still exists
  • The instance is not the member of another ASG 
  • The instance is launched into one of the AZ defined in your ASG
 



Comments

Popular posts from this blog

AWS Instance Store

AWS Identity and Access Management

Elastic Block Storage (EBS)