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
Minimum one server must define
Need to define desired capacity
Need to define maximum size
Autoscaling Components-
Launch configuration(description of your server if is it ubuntu or size of server or software installed etc)
Autoscaling group(Number of servers)
Autoscaling Policy(rules to add servers)
- Things to remember-
Health check happened in every 300 sec by default.
Instance can not be a part of multiple autoscaling groups
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 - AutoscalingELB, auto scaling and VPC must be in the same region.
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-
- Autoscaling - Name
- Launch template- Create a launch template
- Add below script and launch
Duplicate tab
EC2 instance - Actions - Image and template- create Image
- Give image name
- You can see created image as below
- Launch template - give names
- My AMIs - Owned by me - create launch template
- Select created image - next
- Network - select default vpc - select availablity zones
- Desired capacity 2 Max 4 and min 1
- Give policy name as below
- You can see your 2 desired instances running
- Even if you terminate any, it will re run automatically
To delete autoscaling-
Autoscaling groups- select group - delete