What Is Autoscaling and How Does It Work?

What Is Autoscaling and How Does It Work?

Autoscaling

To increase the count of server is called Autoscaling.

  • Automation in scaling

  • Region specific

  • High Availability

  • Fault Tolerance(0 downtime)

  • Scale out/Scale up

  • Scale in/ Scale down

  • Cost management

Types of scaling -

  • Vertical scaling- upgrading one server like increasing size of RAM or CPU.

    It doesn’t support Autoscaling

  • Horizontal scaling- Adding more identical servers

    It supports autoscaling

While auto scaling servers need to follow certain rules

  1. Minimum one server must define

  2. Need to define desired capacity

  3. Need to define maximum size

Autoscaling Components-

  1. Launch configuration(description of your server if is it ubuntu or size of server or software installed etc)

  2. Autoscaling group(Number of servers)

  3. Autoscaling Policy(rules to add servers)

  • Things to remember-
  1. Health check happened in every 300 sec by default.

  2. Instance can not be a part of multiple autoscaling groups

  3. For balancing you can exceed 10% or 1 instance. If you have 21 servers-> 10% of 21 is 2.1 -> approx 23 servers
    21+2.1=23 EC2 are running - Autoscaling

  4. ELB, auto scaling and VPC must be in the same region.

  5. You can not edit launch configuration once you created the same.

Scaling Policies -

1. Static -> you have to set exceed limit eg. 70%, if cpu exceeds beyond 70%, 2 EC2 instances will add automatically

2. Dynamic - It has three types as below

A. Target Tracking policy -

You have to set target limit eg. 70%, if load exceeds beyond 70%, EC2 instances will add automatically and 70% average is maintained

And if load is less, instance will terminate automatically and 70% average is maintained

70% CPU -> EC2 - 10

B. Simple Scaling policy -

It is similar to Static policy. you have to set exceed limit eg. 70%, if cpu exceeds beyond 70%, any no of EC2 instances will add automatically

After 70% add 4 EC2

C. Step Scaling policy -

In simple or step scaling we can define min and max

It gradually increases the number of servers as per requirement.

D. Predictive Scaling -

This policy will analyse the historical pattern.

It uses machine learning to predict VMs

2020 - oct - 4 lakh

2021 - oct - 8 lakh

2022 - oct - 12 lakh

2023 - oct - 15 lakh

2024 - oct - 18 lakh

2025 - oct - 22-30 lakh -> prediction of 2025

  • Steps to achieve Autoscaling-

  1. Autoscaling - Name

  1. Launch template- Create a launch template

  1. Add below script and launch

  1. Duplicate tab

    EC2 instance - Actions - Image and template- create Image

  1. Give image name

  1. You can see created image as below

  1. Launch template - give names

  1. My AMIs - Owned by me - create launch template

  1. Select created image - next

  1. Network - select default vpc - select availablity zones

  1. Desired capacity 2 Max 4 and min 1

  1. Give policy name as below

  1. You can see your 2 desired instances running

  1. Even if you terminate any, it will re run automatically

  1. To delete autoscaling-

    Autoscaling groups- select group - delete