You have multiple applications which are running on multiple AWS compute resources such as EC2 , VPC etc.So , to achieve high availability and fault tolerance of the application/website we should maintain a traffic and divert the requests to the respective EC2 or any AWS compute resources without any delay.
Here we have load balancing feature where we can divert to the traffic/requests to the servers(EC2) based on the request type or etc...
Basically we have three Elastic load balencers in AWS as below
- Application load balancer
- Classic load balancer
- Network load balancer
Now lets see one by one.
Application load balancer:
It functions based on the applications layer,Once load balancer receives the request it evaluates the listener rules based on priority and determine the which rule to apply, then selects a target from the target group for the rule action.
Routing is configured for each target group,even when a target is registered with multiple target groups.You can add and remove targets from target groups based on the need.You can configure routing algorithm used at the target group level.By default application load balancer will use round robin algorithm to select targets.
Source(AWS official Documentation)
Benefits of ALB(Application load balancer):
- You can configure based on path of the request in load balancer to divert the traffic to target groups.Means based on the URL of the request , we can navigate the traffic. So it can be used as "Path based routing".
- Support for host based routing:We can configure rules in the listener, that will route the traffic based on the host field on the header.
- Support for routing based on the fields in the request such as IP addressees,query parameters etc.
- Support for redirecting requests from one URL to another.
- Support for returning a custom HTTP response.
- Support for registering targets by IP address, including targets outside the VPC for the load balancer.
- Support for registering Lambda functions as targets.
- Support for the load balancer to authenticate users of your applications through their corporate or social identities before routing requests.
- Support for containerized applications. Amazon Elastic Container Service (Amazon ECS) can select an unused port when scheduling a task and register the task with a target group using this port. This enables you to make efficient use of your clusters.
- Support for monitoring the health of each service independently, as health checks are defined at the target group level and many CloudWatch metrics are reported at the target group level. Attaching a target group to an Auto Scaling group enables you to scale each service dynamically based on demand.
- Access logs contain additional information and are stored in compressed format.
- Improved load balancer performance.
Setting up a classic load balancer
Create two EC2 instances with a sample website hosted on it , Here load balancer is internet based
So, we can select as subnet with "auto assign public IP"--> enabled.
Create Security group as below
SSH:
We need to connect from our machine only to EC2, Hence we used My IP.
If you want to connect multiple users of your company , probably you can use CIDR block of your company address.
Since we should not allow to the public connection to the EC2 , we are not selecting as "Anywhere" to provide security.
Http:
When we configured our website , public should access the website/application, so it should be "Anywhere".
Then proceed to launch EC2 instance.
Connect EC2 instance and install apache web server in it
sudo yum install httpd -y
to autostart ec2 automatically when changes done in web app
sudo chkconfig httpd on
Create a simple html page in the below location
sudo vi /var/www/html/index.html
write below tag to html page and save it.
<h1>This is simple page web-o1</h1>
Once save it execute the below command to start the webserver.
sudo service httpd start
Copy the public IP and paste in the browser like below
We can launch similar EC2 like below
Click on "Edit tags" , we need to create a tag with "web-02" for easy finding.
Change Instance Details to select subnet as "ap-south-1b" and rest is same.
Connect to the 2nd EC2 instance.
Repeat the same as we did above to configure a page and install apache to the instance.
Once two instances are ready create a load balancer
Select "Classic load balancer"
Load balancer can load balance EC2 instances in a specific VPC.
Select checkbox for "create internal load balancer" check box when there us specific VPC is selected or if you have specific CIDR block with private VPC.
Listener configuration: on which port load balancer should listen
If you want to configure Load balancer on HTTPS protocol, you should have SSL certificates to connect with EC2.But now we are having only HTTP protocol and our EC2 instances are having HTTP , so we will use the HTTP.
You can select check box for "enable advanced VPC configuration" when you have EC2 instances with specific subnet are configured.
As you know we have EC2 with 1A and 1B subnets , lets check this checkbox.
Lets create s SG for LB
Remember we can't SSH to LB , as this is PAAS(Platform as a service).
Since we are having communication only using HTTP and we are not having HTTPS connection and SSL certificates in hand, we are leaving this page as blank.
Configure health check info as below
Select EC2 instances in the next screen
Initially EC2 instances are outofservice as below because it will check instances state after 2 sec, just refresh and check again it will become "Inservice".
copy the DNS name from the below and paste it in the browser
Just refresh your browser multiple times and you can see the navigating traffic b/n EC2 -1 and EC-2.
This is how Classic load balancer works.
Thank you for reading👍👍👍👍👍👍👍👍👍👍
No comments:
Post a Comment