AutoScaling is a method to monitor your application and automatically adjust the capacity to maintain the steady-state. we need to define when the server should be launched. when the CPU load goes above certain %. How To configure AutoScaling, we nee
Two types of Scaling:
Vertical scaling: we can increase CPU and RAM but we will have to reboot the machine.
Horizontal scaling: we can increase no of servers and will automatically attach to ELB. It works on a cloud watch.
Note: We will have to create a launch configuration to perform autoscaling. We will require shared storage for autoscaling like EFS or NFS.
This all configuration should be of running server and everything should be the same.
Create an Alarm:
First of all, Now we will create an alarm for High and Low CPU usage.
Instances -> click on Monitoring
Before configuring autoscaling. I will create an alarm for servers and Now click on Create Alarm.
If the server load goes above 70 % CPU usage, it will send me an alert.
In a similar way, if CPU Usage goes down 40 %, it will alert me.
Steps to launch template:
Now I will take backup of the server, EC2 -> select server -> Actions -> images -> Create image
Click on Create image and give it a name
You can see created images under AMI-> images
We have image backup and now I will create a launch configuration for autoscaling.
EC2 -> Auto scaling -> Create launch configuration
It will ask you the AMI image, I have selected the image which I created.
Now, this will ask for volume group and I’m keeping it as free tier.
If you need to enable a cloud watch, you can do this here.
Add the volumes.
Select your security group.
Review the configuration and then click on the Create launch configuration. You have created a launch configuration successfully.
Configure the Auto-Scaling Group:
Auto-scaling -> Click on auto-scaling group
Now Scroll down and select your image
You have to create an auto-scaling group and choose the required filed according to your needs. You can select group size means how many servers you want to launch.
Click on Advanced and select your ELB.
Now select Use scaling policies to adjust the capacity of this group
You have to select your auto-scaling policy for increased group size.
You can change instances to launch. In my case, 2 instances will be launched if CPU usage goes higher than 75 %. You can set more CPU utilization by clicking on the additional step and define the % of CPU. according to the alarm set, these will launch and delete the instances automatically.
Now we will define when CPU usage goes to 45 %, delete the launch instances.
Configure alert notification and choose your mails.