How do you combine AWS Auto Scaling with a proper load balancer?
AWS / Azure / GCP Published on •8 mins Last updatedBen already wrote an awesome blog about one-click integration with autoscaling. But as one of our eagle-eyed customers politely pointed out - it doesn't actually explain how to configure AWS Auto Scaling in the first place!
So, I wanted to run through the steps in much more detail, my aim being to have a simple quick start guide on how to get auto scaling configured, first in AWS and then on our Advanced Load Balancer ADC for AWS.
Please feel free to comment below if I have failed :-)
This may not be the blog you were looking for...
The Loadbalancer.org appliance automatically detects changes in your auto-scaling groups, with zero configuration and zero downtime. If for some' crazy reason you don't want to pay for our load balancer and want to use Amazons built in one - then checkout the excellent AWS Auto Scaling documentation.
Still with me? Sweet, so what do you have to do?
Firstly, we will start with AWS and get your launch template and auto scaling group setup. Once the auto scaling group is configured and ready to go we will then configure the load balancer and watch the magic happen.
AWS Tasks
1: Create a Launch Template
2: Create an Auto Scaling Group
3: Verify Your Auto Scaling Group
4: (Optional) Delete Your Scaling Infrastructure
Loadbalancer.org Tasks
Configure a virtual service on the load balancer.
Note:
We will be using 2x IIS web server instances for testing (ami-7ff24306) throughout this document.
So let's get started...
Step 1: Create a launch template
- Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/.
![ec2_aws_consoleupdated](ht![ec2_aws_consoleupdated](ht![ec2_aws_consoleupdated](ht
- On the navigation bar, select a region.
Note:
- The Amazon EC2 Auto Scaling resources that you create are tied to the region you specify and are not replicated across regions. For more information, see Example: Distributing Instances Across Availability Zones.
![ec2_regionupdated](https:/![ec2_regionupdated](https:/![ec2_regionupdated](https:/
- On the navigation pane, choose Instances, Launch Templates.
![launch_templates_image3-3]![launch_templates_image3-3]![launch_templates_image3-3]
- Choose Create launch template
![create_launch_template](ht![create_launch_template](ht![create_launch_template](ht
- Provide a name and description for the launch template.
Note:
- The name of a launch template must have 3 to 125 characters, and can include the following characters: ()./_.
- For AMI ID, type the ID of the AMI for your instances.
- For Instance type, select a hardware configuration for your instances that is compatible with the AMI that you specified.
- (Optional) For Key pair name, type the name of the key pair to use when connecting to your instances.
- For Network interfaces, configure Subnet, Auto-assign public IP, and Security group ID. Leave Primary IP and the other fields empty and this creates a primary network interface with IP addresses that we select for your instances.
[
- (Optional) For Storage (Volumes), specify volumes to attach to the instances in addition to the volumes specified by the AMI you specified.
- (Optional) For Tags, specify one or more tags to associate with the instances and volumes.
- Choose Create launch template.
[
- On the confirmation page, choose Create Auto Scaling group.
[
Step 2: Create an Auto Scaling Group
Note:
- An Auto Scaling group is a collection of EC2 instances, and the core of Amazon EC2 Auto Scaling. When you create an Auto Scaling group, you include information such as the launch template, the subnets for the instances, and the number of instances the group must maintain at all times.
To create an Auto Scaling group
-
On the Configure Auto Scaling group details page, do the following:
-
For Launch template version, choose whether the Auto Scaling group uses the default or the latest version of the launch template when scaling out.
-
For Group name, type a name for your Auto Scaling group (for example, my-first-asg).
-
Keep Group size set to the default value of 2 instance for this tutorial.
-
(Optional) To override the network in the launch template, select a virtual private cloud (VPC) for Network.
-
(Optional) To override the subnets in the launch template, select one or more subnets for Subnet.
-
Choose Next: Configure scaling policies.
![create_autoscaling_grp1](h![create_autoscaling_grp1](h![create_autoscaling_grp1](h
- On the Configure scaling policies page, select Use scaling policies to adjust the capacity of this group and input your minimum and maximum instance scale.
- For the purpose of this tutorial I have chosen to scale between 2 and 4 instances.
- Click the Scale the Auto Scaling group using step or simple scaling policies
[
[
- Create a simple scaling policy for increasing and decreasing the instance group size.
- Enter the Name of your policy for example Increase group size and Decrease group size.
[
- At Take the action enter the number of instances that you would like added and removed to and from the group, in this case we will use 1 instance.
- Leave Instances need field empty to default to 300 seconds.
- Click add new alarm to execute the policy when your requirements are met.
- In this case when the server reaches a CPU utilization equal to or greater than 70% for 1 consecutive period of 5 minutes 1 instance will be created.
![create_alarm_high](https:/![create_alarm_high](https:/![create_alarm_high](https:/
- Click Create Alarm
- Click add new alarm of the Decrease group size policy to execute when your requirements are met.
- In this case when the server reaches a CPU utilization less than or equal to 69% for 1 consecutive period of 5 minutes 1 instance will be removed.
- Click Create Alarm
![create_alarm_low](https://![create_alarm_low](https://![create_alarm_low](https://
- Choose Review.
- On the Review page, choose Create Auto Scaling group.
[
- On the Auto Scaling group creation status page, choose Close.
[
Step 3: Verify Your Auto Scaling Group
- Now that you have created your Auto Scaling group, you are ready to verify that the group has launched an EC2 instance.
To verify that your Auto Scaling group has launched an EC2 instance
- On the Auto Scaling Groups page, select the Auto Scaling group that you just created.
- The Details tab provides information about the Auto Scaling group.
[
- On the Activity History tab, the Status column shows the current status of your instance. While your instance is launching, the status column shows In progress. The status changes to Successful after the instance is launched. You can also use the refresh button to see the current status of your instance.
![activity_historyupdated12]![activity_historyupdated12]![activity_historyupdated12]
- On the Instances tab, the Lifecycle column shows the state of your instance. You can see that your Auto Scaling group has launched your EC2 instance, and that it is in the InService lifecycle state. The Health Status column shows the result of the EC2 instance health check on your instance.
![instancesupdated19](https:![instancesupdated19](https:![instancesupdated19](https:
-
(Optional) If you want, you can try the following experiment to learn more about Amazon EC2 Auto Scaling. The minimum size for your Auto Scaling group is 1 instance. Therefore, if you terminate the running instance, Amazon EC2 Auto Scaling must launch a new instance to replace it.
-
On the Instances tab, select the ID of the instance. This shows you the instance on the Instances page.
-
Choose Actions, Instance State, Terminate. When prompted for confirmation, choose Yes, Terminate.
-
On the navigation pane, choose Auto Scaling Groups. Select your Auto Scaling group and chose the Activity History tab. The default cooldown for the Auto Scaling group is 300 seconds (5 minutes), so it takes about 5 minutes until you see the scaling activity. When the scaling activity starts, you'll see an entry for the termination of the first instance and an entry for the launch of a new instance. The Instances tab shows the new instance only.
-
On the navigation pane, choose Instances. This page shows both the terminated instance and the running instance.
Step 4: (Optional) Delete Your Scaling Infrastructure
You can either delete your scaling infrastructure or delete just your Auto Scaling group and keep your launch template to use at a later time.
To delete your Auto Scaling group
- Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/.
- On the navigation pane, under Auto Scaling, choose Auto Scaling Groups.
- Select your Auto Scaling group (for example, Test-asg).
- Choose Actions, Delete. When prompted for confirmation, choose Yes, Delete.
- The Name column indicates that the Auto Scaling group is being deleted. The Desired, Min, and Max columns shows 0 instances for the Auto Scaling group.
Note:
- Skip this procedure if you would like keep your launch template.
To delete your launch template
- On the navigation pane, choose Instances, Launch Templates.
- Select your launch template (for example, my-first-lt).
- Choose Actions, Delete template. When prompted for confirmation, choose Delete launch template.
Loadbalancer.org Tasks
- Configure a virtual service on the load balancer
- Once you have your auto scaling group you can configure your service to load balance. The appliance supports auto scaling groups when using layer 4 TCP/ UDP, layer 7 also with SSL termination. Here I am creating a layer 7 HTTP service listening on 10.0.200 port 80.
![lb_create_l7_VIP](https://![lb_create_l7_VIP](https://![lb_create_l7_VIP](https://
![lb_create_l7_VIP2](https:/![lb_create_l7_VIP2](https:/![lb_create_l7_VIP2](https:/
- After you have added your service you need to modify your new service and this will show you more options. We only need to make a change to one of these options and add our Auto scaling group name and Auto scaling backend server port (if left blank the port will default to the frontend port) to the configuration and update.
![lb_modify_l7_VIP](https://![lb_modify_l7_VIP](https://![lb_modify_l7_VIP](https://
![lb_modify_l7_VIP2](https:/![lb_modify_l7_VIP2](https:/![lb_modify_l7_VIP2](https:/
- Once updated you will be prompted to restart HAProxy and the auto scaling service to complete the configuration. When the services have been restarted the load balancer will start monitoring your auto scaling group and your servers will be shown in the system overview with the server name as the instance id.
[
System overview showing auto scaled servers
- Now when any changes are made to the servers in the auto scaling group the load balancer will automatically be updated to reflect the changes.
![lb_sysoverview_complete](h![lb_sysoverview_complete](h![lb_sysoverview_complete](h
For further details on how to configure the Loadbalancer.org appliance for AWS please see our AWS Quick Start guide here
Additionally if you require any further assistance please contact us directly on support@loadbalancer.org - our engineers will be happy to assist you getting setup.