AWS Auto Scaling enables us to configure automatic scaling for the AWS resources. In the traditional IT world, there is a limited number of servers to handle the application load. When the number of requests increases the load on the servers also increases, which causes latency and failures. AWS provides Amazon EC2 Auto Scaling services to overcome this failure. AWS Auto Scaling is a service that automatically monitors and adjusts compute resources to maintain performance for applications hosted in AWS.
We can create an auto-scaling group which contains a collection of EC2 instances. We can specify a minimum number of EC2 instance in that group and auto-scaling will maintain and ensure the minimum number of EC2 instances. We can also specify a maximum number of EC2 instances in each auto-scaling group so that auto-scaling will ensure instances never go beyond that maximum limit.
Fig: Auto Scaling |
It automatically discovers and tracks the performance of all the scalable resources, like; Auto Scaling groups, Amazon Elastic Container Service (ECS) components, EC2 Spot Fleets, DynamoDB global secondary indexes or tables, and Aurora replicas or clusters. As a demand, the AWS Auto Scaling service can automatically scale up those resources and also can scale them back down if not needed.
Types of Scaling:
There are two types of Scaling:1. Vertical Scaling (means that we scale by adding more power (CPU, RAM) to an existing machine)
2. Horizontal Scaling (means that we can add machines in the pool of existing resources)
For more details go to URL:
https://aws.amazon.com/blogs/database/scaling-your-amazon-rds-instance-vertically-and-horizontally/
Practical:
In this practical, we are going to configure Amazon EC2 Auto Scaling.Steps we need to follow:
1. Create an Auto Scaling group2. Add a new alarm
3. Create an Elastic Load Balancer (CLB, ALB or NLB)
4. Attach this ELB to Auto Scaling Group
5. Increase the load of one system to verify if Auto Scaling creating another instance or not
6. Verify Activity History
Step 1: Create an Auto Scaling group:
AWS ➔ Services ➔ EC2 ➔ Auto Scaling Groups ➔ Get started ➔ Create Auto Scaling Group ➔ Launch Configuration ➔ Create a new launch configuration ➔ select AMI (I am using Amazon Linux 2 AMI (HVM) AMI, from free tier) ➔ Instance type: t2.micro ➔ Name: launch-web-instance-template ➔ Advanced Details: provide the below-mentioned script in User data:
#!/bin/bash
yum install -y httpd
echo "*** This page is coming from IP ***" >> /var/www/html/index.html
echo $(hostname) >> /var/www/html/index.html
systemctl --now enable httpd
…IP Address Type: [*] Assign a public IP address to every instance ➔ Add storage (I used default) ➔ Security group: create or select an existing security group, but make sure port number 80 and 22 (if using Linux) should be enabled in this security group ➔ Review ➔ Create Launch Configuration ➔ Create or select an existing key-pair…
Create an Auto Scaling group:
Group name: auto-scaling-grp1 ➔ Group size: 2 (means minimum how many instances we should start) ➔ Network: webshack-vpc (select your VPC) ➔ Subnet: select all public subnets ➔ Next: Configure scaling policies ➔ [*] Use scaling policies to adjust the capacity of this group ➔ Scale between 2 to 3 instances (this will be the minimum and maximum size of your group)
(we can use Decrease Group Size to terminate the instances also, if not needed. For this use Application Load Balancer or Network Load Balancer)
➔ Scale Group Size: click on the blue line in the bottom "Scale the Auto Scaling group using step or simple scaling policies"…
Step 2: Add a New Alarm:
Auto Scaling Group works based on alarm, so first create the alarm by clicking on 'Add new alarm':
…click on Add new alarm (this will open a pop-up window to create alarm) ➔ Send a notification to: if you do not have any existing topic, you can also create a new topic by clicking on 'Create topic'…
(You can specify more step actions based on your load. But here, I am creating an alarm based on CPU utilization above 30%. If CPU utilization crosses 30% the auto scaling will launch new instance/s)
…Whenever: Average ➔ of: CPU Utilization ➔ is: >= 30 percent ➔ For at least: 1 consecutive period(s) of 5 minutes ➔ Name of alarm: (provide any name) ➔ Create Alarm ➔ Next: Configure Notifications.
Fig: Create Alarm |
Take the action: Add 1 instance when 30 <= CPU Utilization <+infinity ➔ Instance need: 120 seconds ➔ Add notifications if you want to ➔ add some Tags to it for better understanding ➔ Review ➔ Create Auto Scaling group.
Now, navigate to EC2 instances. We can see two instances are about to start.
Step 3: Create an Elastic Load Balancer:
We can create any load balancer among Classic Load Balancer, Application Load Balancer, and Network Load Balancer. In this practical, I am creating a Classic Load Balancer for round-robin purpose.
AWS ➔ Services ➔ EC2 ➔ Load Balancers ➔ Create Load Balancers ➔ Classic Load Balancer: Create ➔ Load Balancer name: web-CLB ➔ Create LB Inside: webshack-vpc (select your VPC) ➔ in my case, there is no change in Listener part ➔ Select Subnet: (here, select all public subnets, so that in future Auto Scaling can create instances in multiple AZ) ➔ Next ➔ create a new Security Group or select an existing one which opens port number 22 and 80 ➔ Next
Configure Health Check:
Ping protocol: HTTP ➔ Ping Port: 80 ➔ Ping path: /index.html
Advanced Details:
Response Timeout: 5 seconds ➔ Interval: 10 seconds ➔ Unhealthy threshold: 2 ➔ Healthy threshold: 2 ➔ Next…
…Add EC2 instances: (do not add any instance here, otherwise Auto scaling will not work and traffic will move only between instances selecting from here. Auto Scaling will automatically select instances) ➔ Next ➔ Review ➔ Create.
For better understanding go to URL:
https://redhatpanacia.blogspot.com/2019/07/clb.html
Step 4: Attach this CLB to Auto Scaling Group:
AWS ➔ Services ➔ EC2 ➔ Auto Scaling Group ➔ Select the group we created named 'auto-scaling-grp1' ➔ Actions ➔ Edit ➔ navigate to Classic Load Balancers: as we click in text bar, a list of classic load balancers will display. Select the CLB named 'web-CLB' which we created ➔ Save.
Fig: Add Load Balancer with Auto Scaling Group |
As a result, we will get a domain in Description of Load Balancer:
AWS ➔ Services ➔ EC2 ➔ Load Balancers ➔ Select Load Balancer ➔ Description ➔ in DNS name we can see our domain ➔ Copy the link ➔ Open Browser ➔ paste URL and hit enter. In this practical we are using two instances, so, every time when we request (by refresh the page) for home page, we will get service from both instances by alternate time.
Step 5: Increase the load of one system to verify Auto Scaling creating another instance or not:
Login to one instance by PuTTY ➔ By using 'top' command we can see that right now free CPU load is approx 99.7%.Fig: CPU Load |
We created an alarm based on CPU utilization above 30% on the average of all the instances. So, we need to increase the load of CPU to verify, Auto Scaling is creating another instance or not.
Use the below mentioned command to increase CPU Utilization:
$ dd if=/dev/zero of=/dev/null &
Now, use the top command to see that now 'free CPU load' is zero.
Finally, go to EC2 instances, here we can see one more instance is about to run. If it not showing here, verify the activity in Activity History:
Step 6: Verify Activity History
AWS ➔ Services ➔ EC2 ➔ Auto Scaling Groups ➔ Select the group, as I am selecting auto-scaling-grp1 ➔ Activity History (next to Details).
Here, we can see the activity of Auto Scaling.
SPECIAL NOTE:
Now, we have three instances. So, use domain from Load Balancer, paste it into the browser and hit enter. Now every time when we hit enter we can see the site is coming from every 3 instances. We can verify the internal IP of instances from the output of the browser.
Enjoy!
Great blog!!
ReplyDeleteAWS Training
AWS Online Training
AWS Training
AWS certification training
Pretty good post. I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog posts. Any way I'll be subscribing to your feed and I hope you post again soon. Big thanks for the useful info. https://autopartsgh.com/
ReplyDelete