Friday, July 10, 2020

Auto Scaling

     
Auto Scaling
-         https://docs.aws.amazon.com/autoscaling/ec2/userguide/what-is-amazon-ec2-auto-scaling.html
-         Ensures you have the sufficient number of EC2's at ALL TIMES
-         collections of EC2 instances, called Auto Scaling groups
-         Can be configured from Console, CLI, SDKs, APIs
-         Can span multi-AZ, REGIONAL
-         Always tries to distribute EC2's evenly across AZ's
-         Have control over which subnets are in scope for launching EC2's
-         If Auto Scaling (AS) fails to launch an instance in an AZ, it will attempt another AZ
-         No additional cost for using AS Groups, pay for EC2's only
-         Works well w ELB, Cloud Watch, Cloud Trail
-         Can use Spot OR Reserved capacity, not a mix of both
-         Spot - will only Auto-Scale across AZ's where Bid is accepted
Launch Configuration
-         Template used to create new EC2. Parameters: instance family/type/AMI. Key pair. Block devices, Sec Gr.
-         Can be launched from scratch OR off an existing running EC2 (instance tags don't get carried along)
-         Can be Copied or Deleted only
-         CAN NOT be edited after creation – need to create new configuration and use it with an AS Group

Auto Scaling Groups
-         Logical grouping of E2 instances. Includes:
          §  min size
          §  desired capacity
          §  max size.
-         CAN be edited after creation

Scaling Policy (plan)
-         determine when/If how to scale

Re-Balancing
-         If Auto Scaling finds nd that EC2 distribution is uneven across AZ's, will attempt to fix
          §  launch new instances in AZ where they were lacking
          §  if the launch is successful, only then terminate EC2 in AZ that had extra's
          §  in the process, AWS will allow AS to be temporarily over the desired capacity by 10% or 1 EC2 (whichever is greater)
-         What can cause a disbalance:
          §  Manual change in an AZ under ASG (add/remove AZ)
          §  Manual request to terminate an EC2 from ASG
          §  AZ did not have enough capacity and now it has
          §  AZ with Spot Instances met market bid price
-         To ADD a running EC2 to ASG, the prerequisites are:
          §  EC2 is running (not stopped/terminated)
          §  AMI used to launch EC2 still exists
          §  EC2 is not part of another ASG
          §  EC2 is in same AZ as ASG
          §  If the ASG is at max (adding another EC2 will tip it over limit), the Add will fail

Instance States
-         Once added, state is Pending – waiting for EC2 Status Health Check
-         Once running – can have EC2 Health Checks monitoring AND optionally multiple ELB Health Check’s (off by default). Either one failing prompts EC2 Termination – even if only a single EBS is complaining
-         Health Check Grace Period – Auto Scaling waits 300 sec default. Can set to 0.
-         You can put an EC2 in Stand By mode – for maintenance/upgrades etc. EC2 remains chargeable but not counted towards available for work. Add it back in – becomes Pending, etc.
-         Deleting Auto Scaling Group – terminates all EC2's. If need to keep EC2's – detach them first
-         Once deemed unhealthy – can't regain health automatically. Can use AWS command line during a very short period begins to re-set health manually - after the instance is deemed for Termination and before Termination. Alternatively – put instance in StandBy before it terminates and fix it
IMPORTANT:
-         Unlike rebalancing, first Terminate unhealthy then add a new EC2
-         Elastic IPs and EB Storage volumes get detached during termination – will need to re-attach manually
-         If using Bid instances and bid price isn’t meeting in one of the AZ’s, AS will pile up EC2 in other AZ’s where the price is met. Once bid moves – will rebalance.
-         The only way to update the bid price is to create new Launch Configuration and then edit the group to attach it
-         Can leverage SNS to inform on events

Auto Scaling and ELB
-         Must be in same region
-         ELB automatically registers any new EC2 spawned off by Auto Scaling Group
-         ELB and EC2's must be in same VPC
-         Detach an instance from ELB – de-registers it from ASG, but ASG will honor ELB's connection draining

Merging Auto Scaling Groups
IMPORTANT:
-         Can do from CLI only
-         Can merge multiple single AS groups into a single Multi-AZ group
          §  Re-zone an existing group to cover multiple AZ's
          §  Delete the other ASG's
          §  Can be done with or w/out ELB attached
o   The resulting ASG (one that’s being spread into a new AZ) must be one of the pre-existing ASG's, not a new one

      
			An illustration of a basic Auto Scaling group.

No comments:

Post a Comment