Hello Readers! In this blog we will see How to Setup an Application with an Elastic Load Balancer. In my previous blog you have seen how to deploy and run your docker container in AWS Elastic Container service in AWS using the launch type EC2 instances.. The reference blog link is: https://blog.knoldus.com/elastic-container-service-using-ec2-instance-and-how-to-deploy-and-run-your-docker-container-in-aws-elastic-container-service-in-aws-using-the-launch-type-ec2-instances/
What is Load Balancing?
Load balancer are servers that forward internet traffic to multiple servers ( EC2 instances) downstream.
Firstly let’s see in short why we use Load Balancing?
- Spread load across multiple downstream instances.
- Expose a single point of access (DNS) to your application.
- Seamlessly handle failures of downstream instances.
- Do regular health checks to your instances.
- Provide SSL termination (HTTPS) for your websites.
- Enforce stickiness with cookies.
- High availability across Zones.
- Separate public traffic from private traffic.
Types of load balancer on AWS
Aws has 3 kinds of Elastic Load Balancer
- Classic Load Balancer
- Application Load Balancer
- Network Load Balancer
- Overall, it is recommended to use the newer/ v2 generation load balancers as they provide more features
- you can setup internal (private) or external (public) ELBs
Let’s get started !
Step 1: Firstly you must have logged into AWS Management Console account before starting. So, Create an AWS account if you don’t have one. After that Login to your AWS Management Console and Click on Services menu > Choose Load Balancers.
Before creating a load balancer you have to need to launch a EC2 instance, if you want to know how to launch EC2 instance you can go through this below link:https://blog.knoldus.com/aws-ec2-instance/
Step 2: First we will choose the Application Load Balancers and configure load balancers, once you choose it, you need to give it to name is web-app-elb and the scheme is going to be internet facing because we want public, if you want private you can choose private option and the ip address i will choose here ipv4.
And the listeners is basically a list of protocols and ports that are ELb listen on port 80 on HTTP and I’m going to select all the Availability Zones.
Step 3: Next i will configure security groups and basically i create a new security group, we are going to call it my-first-load-balancers and at last in Description is My First ALB, if you want to write more description than you can write but right now i will choose this.
Inbound rules and Outbound rules
You can set Inbound rules and Outbound rules according to your configuration but now i’m going to add more outbound rules for port 22 and click on create security group.
Step 4: Let’s move for the routing so load balancing is configured but we have to need to route, Now we will create one target for a application load balancer, So click on create a target group and i’m going to call it My-first-target so you can configure target type is the ip instance in lambda function, we are moving the for the instance but you can create for the ip or also lambda function and the protocol is 80.
Health check is by default it works on root path and health checks it also works on 200 that is a success code, if you want to change health check than you can change here but i’m going to leave all as default and at last click on Next.
Step 5: Here we will add the target group so where it want to route on which instance so, we have created one instance over here just adding this instance to our target group so this instance we have added and after that click on next and Done.
Step 5: It’s creating the Security Group, Authorised security groups, Load Balancer, Target group, Add to registered, Create Listener and all internal step will be done and our load balancer is ready so you can see it’s giving the state of the provisioning here and our load balancing is created this is the all information about the load balancer and Load Balancer will give the one DNS name.
Congrats! 👏 so let’s copy the DNS name and try to access the DNS name is accessible through the load balancer so we are able to access this elb load balancer DNS and we are also able to access with the directly IP.