AWS-EC2-3

Auto Scaling

The purpose we need to use the auto-scaling is to dynamically scale-out the number of services to satisfied for handling the incoming traffic.

Launch Configuration/Template

When the auto-scaling scale-out the auto-scaling group, it will use the launch configuration or launch template to launch a new instance.

Launch Configuration

  • Configurations
    • Instance Type
    • AMI
    • Key Pair
    • Block Storage
    • Security Group
    • User Data
    • IAM Role
    • ...

Launch Template

  • Support versioning
  • Generating template by using the currently running EC2 instance

Auto Scaling Group

The group which contains one or more EC2 instances, which can help to scale-out or scale-in the number of instances, but it cannot do scale-up and scale-down
  • The auto-scaling group is existing in a single regionsame to ELB
  • But it can do auto-scaling cross AZ
  • Trying to balance the amount of the instances in different AZs by some scenarios
    • If launching a new instance from an AZ failed, then it will try to launch a new instance in a different AZ from VPC of the region
    • Scale-out priority in the AZ which has less instance against to other AZs
    • Scale-in priority in the AZ which has the most instances against to other AZs
  • The scenarios which will trigger to rebalance the instances for ASG
    • User tries to modify the AZs from ASG
    • User tries to manually remove or launch instance from ASG
    • AZ gets back to on-live from insufficient capacity
    • The price of Spot Instance is under the re-defined price in the AZ from ASG
  • ReBalancing the instances will launch a new instance first and then terminate the old instance at the next
  • Manually attach a new instance into ASG
    • If the attaching the new instance will exceed the capacity, then the attaching will be failed
    • Scenarios
      • Instance status is running
      • Instance AMI is existing
      • Instance is not in the other ASG
      • Instance is in the AZ which is defined by ASG
    • StandBy instances
      • User can set the status of instances to StandBy from ASG
      • The standby instances still existing in ASG and being charged as normal
      • The standby instances are not counted as the ASG living instances
      • The standby instances will not be doing the health check

Health Check

  • Instances Health Check
    • By using the instance itself health check to check the health of instances
    • By using the load balancer health check to check the health of instances
  • Grace Period
    • By default, the health check will wait for 300s for starting doing the health check
    • During this period, the instance will do like installing an operating system, start the operating system, install packages, execute the script from user data, etc.
    • Once the health result is unhealthy, ASG will terminate unhealthy instances first and then launch a new instance at the next.]

Binding ELBs

  • Classic Load Balancer - directly binding to the auto-scaling group
  • Application/Network Load Balancer - assign a Target Group which has been bonded with an ALB/NLB. (Autoscaling Group is the role who control the Target Group by adding the new-launched instance into Target Group)
  • Summary
    • ALB/NLB: distribute traffic to each of the instances in Target Group
    • ASG: control scale-out(Launch and attach new) or scale-in(Terminate and move out) the instances in Target Group

Scaling Policy

Keywords

  • Min - The minimum amount of the ASG allowed, keep the min number of instances
  • Max - The maximum amount of the ASG allowed, keep the max number of instances
  • Desired - According to the scaling policy to adjust the desired amount for ASG instances, treat it like the current best-balanced amount
* If making Min == Max == Desired, the auto-scaling is disabled but will always keep the amount of the amount (only the fault-tolerant feature is enabled)

Policy

  • Dynamic
    • Amount-Based (Keywords) - according to the amount of min, max, desired which the user has defined to do auto-scaling
    • Event-Based - based on the event alarm to trigger the ASG to do the auto-scaling
  • Scheduled
    • Time-Based - according to the schedule plan to trigger the ASG to do the scaling
      • Each timestamp only allow one schedule plan to execute

Target Tracking (metrics value of the instance from CloudWatch)

One of the ways to do the event-based auto-scaling, the easiest way. According to the value from metrics to implement auto-scaling the instances

Metrics Catagories

  • The number of requests (traffic)
  • The average CPU utilization
  • The average network-in (bytes)
  • The average network-out (bytes)

Warm-Up time

Before the time expired, the information on the new instance won't be attached to the ASG Metrics calculation range. (When a new instance being initialization, the CPU utilization is not working for network workload, instead, it is working for launching the new instance.)

Scale-out only

AWS allows setting only the scale-out policy without setting the scale-in policy.

Async Activity

Only one activity could be executing at the same time (scale-out/scale-in)

Auto-Scaling Alarm

The activity will be triggered by the CloudWatch Alarm when the value of the certain item, like the CPU utilization, Disk R/W bytes, Disk R/W count, Network-in, Network-out, etc. reach the threshold value defined by the user.

Simple Scaling

According the a alarm to trigger a action with cool-down time period

Cool-Down time

The time between the previous scaling activity down to the starting of the next scaling activity. (The scaling activity including the instances scaled-out/in to complete and the health check to complete)

Actions

  • The Number / Adding-number/ Removing-number of instances
  • The percentage of instances

Example

  • There is an auto-scaling alarm which keeps reading the value of metrics from the CloudWatch (set reading interval time)
  • Once reach the threshold, the alarm will be raised up
  • ASG received the alarm, like scale-out, it will launch the certain of instances. 
  • At this time, the alarm still reading the value of metrics from CloudWatch, but the launching instances still in initializing and have not ready for use yet. The metrics of the CloudWatch still exclude the new-launching instances, so that alarms keep sending to ASG. [Cool-Down time usage]
* Both ASG and Target group are logic grouping, ASG has the function like controller to launch or terminate the instances, once ASG launch a new EC2 instance, it will add a tag or label to the EC2 host which just launched which is inside of Target Group.

    Step Scaling

    According the metric's continued range to set different actions, same to the Target Tracking Scaling, it based on the metrics value not alarm

    Warm-Up timer

    [Same to the Target Tracking Scaling], the scaling is based on the metrics value, so that when the metrics data of the new launching instance be counted into the CloudWatch metrics data analysis is the matter.

    Monitoring

    The behavior which the ASG keep sending the metrics data to the CloudWatch. (Different services have different monitoring behavior from the CloudWatch)

    EC2 Monitoring

    • Basic Monitoring: default, cannot be disabled, triggered per 5 mins, for free
    • Detailed Monitoring: need to be enabled manually, triggered per 1 min, not for free
    • Custom Monitoring: defined by launch configuration/template
    • Matching the periods between EC2 and ASG:
      • EC2 record metrics data per 1 min, but ASG read metrics data per 5 mins, so that 4 mins metrics data which EC2 recorded is in van.
    ASG Monitoring
    • Default the monitoring is disabled, need to be enabled manually
    • Sending the metrics data to the CloudWatch
      • GroupMinSize
      • GroupMaxSize
      • GroupDesiredCapacity
      • GroupInServiceInstances
      • GroupPendingInstances
      • GroupStandbyInstances
      • GroupTerminatingInstances
      • GroupTotalInstances

    Scheduled Scaling

    After a auto-scaling group setup completely, the user is able to create a scheduled scaling which is based on time.

    Crontab

    A expression for time and cron jobs

    Comments

    Popular posts from this blog

    Union Find 模板

    Tree的经典题

    Tree DFS