Create Auto Scaling Group and Launch EC2 with Load Balancer

Create Auto Scaling Group and Launch EC2 with Load Balancer

Introduction

In AWS it’s very easy to Create Auto Scaling with Load Balancer and EC2 Machine.
Load balancing refers to efficiently distributing incoming network traffic
across a group of backend servers, also known as a server farm or server
pool.
In this manner, a load balancer performs the following functions:
Distributes client requests or network load efficiently across multiple
servers.

Types of Load Balancer:

Application Load Balancers.
Network Load Balancers.
Classic Load Balancers.
Amazon ECS services can use either type of load balancer.
Application Load Balancers are used to route HTTP/HTTPS.

What is the Autoscaling Group?

The Autoscaling group contains a collection of Amazons EC2 instance that is treated as a logical grouping for the purpose of automatic scaling and management.
It also enables you to use health check replacement and scaling policies. To create Auto scaling we cave to create the Load balancer.

How to Create Load Balancer?

  • Login to AWS as Root user
  • In AWS management console go to “services”
  • Go to “EC2”
  • In EC2 dashboard go to “Load Balancer”
Figure1. EC2 Dash board locating Load Balancer.
Figure1. EC2 Dashboard locating Load Balancer.
Figure2. Load Balancer page
Figure2. Load Balancer page
  • Click on “Create Load Balancer”
Figure3. Load Balancer type page
Figure3. Load Balancer type page

As we learn before we have three types of the Load Balancer, Application Load Balancer, Network Load Balancer, Classic Load Balancer.
Application Load Balancer, Network Load Balancer these balancers need to pay for use.
But for your learning purpose, we go with “Classic Load Balancer”
In Classic Load Balancer click on “Create”

Figure4. The first step to create Load Balancer
Figure4. The first step to create Load Balancer
  • Give the load balancer name.
  • Create LB Instance leave it as default.
  • VPC configuration, Internal LB live it unchosen because they will charge.
  • Load Balancer Protocol give as HTTP.
  • Click on “Next”.
Figure5. Assign security group
Figure5. Assign security group
  • Assign Security Group to load balancer.
  • If you want to create a new security group can select create a group.
  • If you want to select from the existing group you can select.
  • Click on “Next”.

Health Check Setup

Figure6. Configuration Health Check
Figure6. Configuration Health Check
  • Health check which your load balancer will automatically perform health checks on your EC2 instances and only route traffic to instances that pass the health check.
  • If an instance fails the health check, it is automatically removed from the load balancer. Customize the health check to meet your specific needs.
  • Ping protocol as “HTTP”.
  • Port “80”.
  • Ping path “/healthy.html”.
  • In Advanced Details give “Response Timeout”, which is used to set time to the website response.
  • “Interval time”, which is used to set time to the website to reload.
  • “Unhealthy threshold”, which checks the instance 2 times and the instance is not responding it is not healthy.
  • “Healthy threshold”, which checks the instance 3 times by refreshing it if it gives an instant response it is healthy.
  • Click on “Next”.

Add EC2 Instances

Figure7. Add EC2 instance
Figure7. Add EC2 instance
  • Select EC2 instance if you have or other wise we can add it later.
  • Click on “Next”.
Figure8. Add tags
Figure8. Add tags
  • Give the tag to the LB.
  • Click on “Review and Create”.
Figure9. Review Page
Figure9. Review Page
  • Review the details which you given.
  • Click on “Create”.
Figure1.0. The Load Balancer created.
Figure1.0. The Load Balancer created.
  • The status bar shows 0 of 2 that means there is no instance is running.
  • If it shows 2 of 2 it means the instance are in service.
  • Let’s check whether the DNS name is working or not.
  • Copy it and open in new tab.
Figure1.1. shows the page is working.
Figure1.1. shows the page is working.
  • When you reload the page, it will send load equally to EC2 instance.
  • To create Autoscaling first we have to launch configuration.

How to Launch AutoScaling Configuration?

  • In EC2 dash board go to “Launch Configuration”.
Figure1.2. Launch Configuration
Figure1.2. Launch Configuration
Figure1.3. Launch configuration page
Figure1.3. Launch configuration page
  • Click on “Create Launch Configuration”
Figure1.4. Create Launch Configuration page
Figure1.4. Create Launch Configuration page
  • Select AMI “Amazon Linux” machine
Figure1.5. Select instance type
Figure1.5. Select instance type
  • Select “t2.micro”.
  • Click on “Next”.
Figure1.6. Launch Configuration page
Figure1.6. Launch Configuration page
  • Give the name to the LC (Launch Configuration), remaining live as it is.
  • Click on “Advanced Details”.
Figure1.7. Advanced Details of LC
Figure1.7. Advanced Details of LC
  • Kernel ID keep it default.
  • RAM Disk ID keep it default.
  • Use Data “write script”, to launch one website.
  • IP Address type keep it as default.
  • Click on “Next”.
Figure1.8. Add volume
Figure1.8. Add volume
  • Add volume to the LC.
  • Click on “Next”.
Figure1.9. Security group
Figure1.9. Security group
  • Give security group to the LC.
  • Click on “Review”.
Figure2.0. Review page
Figure2.0. Review page

Click on “Create LC”.

Figure2.1. Shows Keypair
Figure2.1. Shows Keypair
  • Select keypair already in exist.
  • Click on “Create LC”.
Figure2.2. LC was created.
Figure2.2. LC was created.
  • From this we have to “Create Auto Scaling group”.
Figure2.3. Configure Auto Scaling Group page
Figure2.3. Configure Auto Scaling Group page
  • Give Group name to ASG.
  • Launch configuration which we created before it takes automatically.
  • Give Group size means no of instance we want to launch initially.
  • Give Network default.
  • Give subnet in all regions since we are launching in N.Virginia  it contains 6 Availability Zones means it have 6 default subnets.
  • We can launch ASG in 6 subnets or we can chose as per your need.
  • As per now launch in all subnet because if any region goes down the it send data to another region.
  • Click on “Advanced Details”.
Figure2.4. Advanced Details
Figure2.4. Advanced Details
Figure2.5. Select your created ELB
Figure2.5. Select your created ELB
  • Enable Load Balancing.
  • Give Load balancing which you have created, don’t give Target Group.
  • Give health check type as “ELB”.
  • Give Health check grace period as per your need, remaining leave as it is.
  • Click on “Next”.
Figure2.6. Scaling policies.
Figure2.6. Scaling policies.
Figure2.7. Add Alarm
Figure2.7. Add Alarm
  • Click on “Add Alarm”.
Figure2.8. Alarm details
Figure2.8. Alarm details
  • Click on “Create Topic”.
Figure2.9. Give topic
Figure2.9. Give topic
  • This is to increase the instance.
  • Give name to the notification.
  • Give your email ID.
  • Give percentage to the >=50 means when CPU performance is >50 it will stop the instance and create another instance and pass the load to that instance.
  • Click on “Create Alarm”.
Figure3.0. Scaling policies
Figure3.0. Scaling policies
  • We can give Group at its initial size or use scaling policies to adjust the capacity of this group.
  • As per now we go with “use scaling policies to adjust the capacity of this group”.
  • We can set the scale to instance like minimum 2 instance has to run initially and it can create maximum 6 instance.
  • We can set alarm to the instance.
  • Now Decrease the instance.
  • The process is same as increase group but here we decrease  the instance when the performance is low.
Figure3.1. Decrease Group size
Figure3.1. Decrease Group size
  • If the CPU performance is less than 3 percent it will delete one instance.
  • Click on “Next”.
Figure3.2. Alarm notification setting.
Figure3.2. Alarm notification setting.
  • Click on “Add Notification”.
Figure3.3. Alarm notification setting
Figure3.3. Alarm notification setting
  • Enable all type of instance actions if any of the type is not working it will send notification.
  • Click on “Next”.
Figure3.4. Add tags
Figure3.4. Add tags
  • Give tag to ASG.
  • Click on “Review”.
Figure3.5. Review page
Figure3.5. Review page
  • Click on “Create ASG”.
Figure3.6. ASG created
Figure3.6. ASG created

Let’s see the instances are working or not.

Figure3.7. Shows instance are created
Figure3.7. Shows instance are created
  • It shows that instances are created by ASG.
  • Check-in load balancer whether these instances are working or not.
Figure3.8. Instance are running
Figure3.8. Instance are running
  • Shows the instances are running.
  • Now copy the DNS Name and check whether the webpage is opening or not.
Figure3.9. Webpage
Figure3.9. Webpage
  • Shows that the webpage is working.
  • If we terminate one of the running instances it can create another instance or not.

Let’s terminate instance.

Figure4.0. Instance terminating
Figure4.0. Instance terminating
Figure4.1. Shows instance termination
Figure4.1. Shows instance termination
  • When we have terminated instance, it terminated in ASG.
  • When we terminated it took 1 to 2 minutes and created another instance.
  • So, by this, we can say that if any instance is terminated the ASG will create another instance immediately and share the load this will happen when we create an instance with ASG. 
  • Create Auto Scaling with Load Balancer and EC2 Machine

Conclusion:

By this we came to know how to Create Auto Scaling with Load Balancer and EC2 Machine . Autoscaling is used when instance is overloaded it will create another instance automatically and share the load (for this we attach load balancer in the process of Autoscaling creation) , when the instance is not in use it will shutdown automatically.

2 thoughts on “Create Auto Scaling Group and Launch EC2 with Load Balancer”

  1. Pingback: Enable the Load Balancer Based on Health Check

  2. Pingback: SNS Topic and Subscribe Create a Topic and Subscribe

Leave a Reply

%d bloggers like this: