Optimizing Traffic Flow: Exploring Application Load Balancer Case Studies with Target Groups and EC2 Instances
Case Study:
In this blog we will explore different cases of AWS Application load balancer. Mainly we will see how the traffic flows in private ec2 instances using round robin technique. Also, ALB with Custom domain name with route 53. In addition. ALB with host based based routing.
Pre-requisites for ALB exercise:
1)creating a two ec2 with below configuration.
1.1) Two instances in public subnet as shown in above diagram.
1.2)User data of ec2 instances as mentioned below.
1.3)Open a security group which allow HTTP for 0.0.0.0/0.
1.4)Once the instances are up and running. make sure to stop the two ec2 instances.
1.5)Create an AMI(Amazon Machine Image) for both instances.
1.6)Terminate the instances after creating an AMI's.
2)Setup the Actual configuration with 1 target group and 2 ec2 instances in private subnets.
2.1)creating the VPC and Subnets shown as below.
2.2)Creating security group with vpc source cidr.
2.3)Launch the webserver1 and webserver2 using the AMI created in private subnets. Security group to allow HTTP for VPC CIDR.
2.4)create the ALB target group and add both ec2 instances. Also, configure health check on port 80 with /index.html
ALB-TG group is created as shown below.
2.5)create the load balancer security group with HTTP traffic.
2.6)Create the ALB with HTTP listener and forward the traffic to target group.
Test Cases for the Case Study: Access the ALB over the browser using the AWS provided ALB DNS.
Case-1:Copy paste the load balancer in browser
Output: It is illustrating that user data in one ec2 instance in one private subnet is displayed.
Case-2:Refresh the page
Output: After refreshing the page. It is showcasing the user data present in second ec2 instance which is present in another private subnet.
Conclusion: It is using the round robin technique to navigate the traffic flow.
ALB with Custom Domain Name with same setup
Pre-requisite:
1)Creates public domain name in godaddy.
2)Created public hosted zone with the same name i created in go daddy.
output:
3)Updating my name servers in go daddy.
note:It will take 6 to 12 hours to reflect the changes for our test cases after updating in godaddy.
4)Create the A - record type in created public hosted zone with ALB configuration as below
Test cases for custom domain name configuration setup:
Case-3: Copy paste the custom domain name "blogaws.live" in browser.
Output: we can observer that webserver 1 is displaying with domain name blogaws.live
case-4:Refresh the page
Output: Traffic routed to another ec2 instances and working fine with domain name.
ALB with HOST based routing setup
Pre-requisite:
1)create the two target groups and register one ec2 instance in each target group as per the intended traffic routing webserver 1 for asia and webserver 2 for europe.
output1:asia
output2:europe
2)In ALB listener rule, add a rule for host based routing where traffic with asia.x.x is sent to TG1 and traffic with europe.x.x is sent to TG2.
Output: After a similar procedure for europe, we have three listener rules as below.
case-5: Refresh the browser with asia.blogaws.live
Reason: Since route 53 is not updated with new host names.
3) Create records for asia and europe in route 53.
After creating records we can see the console view as below.
Test cases for host based routing
case-6: copy paste the host based domain name with asia.blogaws.live
case-6: copy paste the host based domain name with europe.blogaws.live
Output: It is observed that whenever host header with asia routing to webserver1 and europe routing to webserver 2.
Summary:
we have finally tested all the cases from ALB DNS to host based domain name via custom domain name.
Reference:
1)AWS VPC and Networking in depth: Learn practically in 8 hrs.
2)AWS Load Balancers | ALB vs NLB vs GWLB | Detailed Comparison | #aws #abhishekveeramalla(youtube.com/watch?v=bCS9m5RVPyo).
3)https://docs.aws.amazon.com/elasticloadbalancing/latest/application/introduction.html