Tech Junkie Blog - Real World Tutorials, Happy Coding!: Iaas With AWS: Setup Auto Scaling With Application Load Balancer

Monday, December 14, 2020

Iaas With AWS: Setup Auto Scaling With Application Load Balancer

 In this pose we are going to implement auto scaling on our instances.  Auto scaling is a feature on AWS that automatically scaled horizontally either based on metrics or the health of an instance. In this post we are going to setup auto scaling on an Application Load Balancer.  

1. The first thing we have to do is setup an Auto Scaling Group under "Auto Scaling" click on "Auto Scaling Groups"

2. Click on the "Create Auto Scaling group" button

3. Give your auto scaling group a name, then click on the "Create a launch template"



3. Give your template a name, then scroll down to AMI type


4. Select Amazon Linux 2 as the image, t2.micro as the instance type, and specify the "Key pair(login)"

5.  Accept the default VPIC, and expand "Advance Details" and paste the following into the "User Data" to install Apache Web Server, then click on "Create launch template"

#cloud-boothook
#!/bin/bash
#Use this for your user data (script without newlines)
# install httpd (Linux 2 version)

yum update -y 
yum install -y httpd.x86_64 
systemctl start httpd.service 
systemctl enable httpd.service 
echo "Hello world from $(hostname -f)" > /var/www/html/index.html
cd /var/www/html/
cp index.html contacts.html

6. Click on "Create Auto Scaling Group"

7. Continue creating your Auto Scaling Group, as you will see the template has been selected for you, click "Next", accept the default then click "Next"



8. Accept the default, and then select the subnets you want your instances to be created in, then click "Next"
9. On the group size, type following value. We basically say we want 3 capacity, and the max an min instances is between 2 and 4.

10.  For scaling policies, set a policy to scale when the CPU is 50% or more
11. Click "Next" until you see the "Review" page, then click on  "Create Auto Scaling group" then click on the button.

12. If you select the Auto Scaling group and click on the "Activity" tab you will see that it is in the process of creating three instances that we specified as our desired capacity.


13. If you look at the instance you will see that three new instances have been created


14.  So now we can create our load balancer to tie all of this together
15. Create an Application Load Balancer, when choosing the subnet, make sure you choose the same subnets as the ones you used for your Auto Scaling Group.  If you need directions on how to create an Application Load Balancer, you can go to this post.

16.  Choose the Security Group that has HTTP traffic on port 80
17. For routing create a new Target group and accept the default
18.Under "Advanced health check settings" change the "Healthy threshold" value to 3, then click "Next"

19. Skip the "Register Targets" because we want the load balancer to pick up the instances that the Auto Scaling group creates, click "Next" until you see the "Create" button, click on it.
20.  Go back to the Auto Scaling group page, then select the Auto Scaling group and click on the "Edit" button.




20.  Under  "Load balancing" select the Target group that you created in the load balancer, then click "Save"

21. Now we can test to see if the Auto Scaling work, the easiest way to test it is to terminate one of the instances.  Since we specify that we desired at least 2 (the minimum), a new instance should be created automatically

22. As you can see a new instance is automatically created

If you want to test the CPU utilization metrics you can follow the instruction here to put stress on your server https://acloudxpert.com/install-stress-utility-on-amazon-linux-2/
 





3 comments:

  1. Thank you for sharing your info. I really appreciate your efforts and I am waiting for your further write ups thank you once again. And know Mimz International Merchandising Company provides services to clients to Make their Vision a Reality and to help companies to improve business performance. merchandising

    ReplyDelete
  2. Wow, impressive!!! Amazing post, I found a lot of interesting information here. I really appreciate your article. Going to read more new posts.

    Find out Dream 11 predictions for today's match & fantasy cricket tips. We Provides 100% true match prediction with free fantasy tips. We cover all major cricket tournaments and matches.

    ReplyDelete
  3. Food and recipes
    Thank you admin for your useful information . I think your dedication is inspiring. This note is just an extension of what we all already know. We couldn’t do it without you.

    ReplyDelete

Search This Blog