AWS Architect Certification Training
- 61k Enrolled Learners
- Live Class
In fiction, we find the predictable boring. In real life, we find the unpredictable terrifying. The best possible option is to be prepared for the uncertain. In this Elastic Load Balancer Tutorial, I’ll talk about how Load Balancer comes to the rescue in such vulnerable and uncertain situations.
Agenda for this Elastic Load Balancer Tutorial:
Also, take a look at the course provided by Edureka.
Amazon provides its own service for load balancing known as “Elastic Load Balancer“. Let’s first talk about what is load balancing before digging into Elastic Load Balancer Tutorial.
Suppose you have an application deployed on an EC2 instance which is getting limited traffic and hence you’ve allocated only limited resources to it.
Fig 1 – Elastic Load Balancer Tutorial
But, what if you wake up one day and realize the tables have turned. What if, your application starts getting a lot of unexpected traffic? This is amazing, isn’t it? But is your application ready for it? Can it handle so much traffic?
Fig 2 – Elastic Load Balancer Tutorial
With the load balancing mechanism, yes!
Fig 3 – Elastic Load Balancer Tutorial
The Load Balancer realized that there’s too much traffic on that one service and the application might end up crashing. AWS has the feature of scaling up or scaling down the resources. Load balancer automatically scales up your resource which is sufficient enough to handle the large incoming traffic.
Load Balancing refers to efficiently distributing incoming network traffic across a group of backend servers in a manner that increases speed and performance.
The Elastic Load Balancer is similar to all the other load balancers. It basically serves the purpose of a single point of contact for the client. To make it simple, the client sends a request to the load balancer and it then distributes them to the targets like EC2, lambda function, etc in different Availability Zones.
There are three types of Elastic Load Balancers available. You can use the one best suited for your work.
This is the most basic form of the load balancer, that was used initially for classic EC2 instances. It is operated on connection level as well as request level. The main drawback of this type of load balancer is, it does not support features like host-based routing or path-based routing. Once the load balancer is configured, it balances load across the servers regardless of what is present on the server which might end up reducing the efficiency and performance in certain situations.
This type of Load Balancer is used when there are HTTP and HTTPS traffic routing. I’m sure you guys are aware of the OSI Model. This load balancer works at the Application layer of the OSI Model. It provides advanced routing features such as host-based and path-based routing. It also works well with containers and microservices. I’m going to show a demo on how to create an application load Balancer and demonstrate how the traffic is routed amongst the available servers further in this Elastic Load Balancer Tutorial.
Network Load Balancer works at layer 4 of the OSI Model(connection level). Its mainly used for load balancing TCP traffic. This Load Balancer can handle millions of traffic and is best suited for maintaining low latencies. It’s capable of handling uncertain traffic while maintaining a static IP address.
Now that you know what is a load balancer, let’s get to know why do we need it.
The main use for an Elastic Load Balancer is to make your resources highly available. There are four types of forwarding rules that a user can assign to a load balancer, and they can be broken down as follows:
Now that you understand the working of a load balancer, let’s learn the algorithms that govern load balancing. Let me guide you through each of the algorithms used for load balancing.
Let’s move further and create a Web page and use a load balancer to make it highly available.
It this demo, I will create 2 EC2 instances and will make them work like servers. I will then host a Web page on each of them. By using a load balancer, I will handle the request to my web page. So, let’s dig deep into this load balancer tutorial and find out how to implement the above-said scenario.
Step 1: Create an EC2 Instance.
Choose EC2 in AWS Console like shown below.
Click on “Launch Instance” to launch an instance.
Select the “Amazon Machine Image” best suited for you. For this demo, I’ve used the Amazon Linux 2 image, as highlighted in the image below.
Choose the “Type of Instance“. In this case, I’ve used t2.micro.
Configure the “Instance Details“. Add the number of instances you wish to create and choose the network and the subnet you wish to use.
Now “Add Storage“. You will not require more than 8GB for this Demo.
You can “Add Tags” to identify your instances. This step is optional.
You have to “Configure Security Group” and make sure you have permissions for SSH, TCP & HTTP.
Click on “Review Instance Launch” to launch the instance.
The final step “Choose a Key Pair or create a new key pair“. You can either choose from an existing key pair or create a new key pair which is required to create an instance.
Step 2: Access your Instance.
See how to access your EC2 instance using Putty here.
Step 3: Install “HTTPD” in your instance. Here are the commands you need to run.
$ sudo yum install httpd $ sudo service httpd start $ sudo chkconfig httpd on $ sudo service httpd status
Step 4: Create an HTML file named “index.html”
Here is the code I used.
<html> <head> <h1>Hello Community!</h1> <h2>This is our First Server</h2></head> <body bgcolor="#98fb98"> <a href="https://www.edureka.co/community/"&gt;Visit Edureka | Community /a> </body> </html>
<html> <head> <h1>Hello Community!</h1> <h2>This is our Second Server</h2></head> <body bgcolor="#5DBCD2"> <a href="https://www.edureka.co/community/" Visit Edureka | Community /a> </body> </html>
Use the same file just change the server’s number so that you can understand how is your request served.
Step 5: Create a “Load Balancer“.
Navigate to “Load Balancing” and click on “Create Load Balancer“.
Select the “Load balancer type“. In this case, I’ve used the HTTP/HTTPS.
You have to “Configure your load balancer“. Add name, Schema and IP address type(which is IPV4) in this case.
Select your VPC for “Configure Load Balancer“. Add your VPC and Availability Zones.
Now you have to “Configure Security Settings“. You’ll be prompted a warning as displayed in the picture below. This warning is just to let you know that you should use HTTPS instead of HTTP.
To configure Security Groups, start by assigning a security group.
Now the main part, “Configure Routing“. Configure the routing as shown below in the image.
Now, just add your instance, i.e. “Register Targets“.
The final step “Review” all the settings if they’re fine.
Now, wait for 3-5 mins for the load balancer to configure.
Step 6: Select the DNS from the description. Paste it as a URL in your browser.
And you should see something similar to the above image. It says “This is our First server”, indicating the web page got deployed on the first server. Hit “Refresh” and you’ll find another page(shown in the image below) being displayed which shows that the web page got deployed on the second server.
You can see how Load balancer diverts the traffic to different servers to service the request from users. I hope you liked this blog about “Elastic Load Balancer Tutorial“. For more such blogs, visit “Edureka | Blog“.
If you wish to learn more about Cloud Computing and build a career in Cloud Computing, then check out our Cloud Computing Courses which comes with instructor-led live training and real-life project experience. This training will help you understand Cloud Computing in depth and help you achieve mastery over the subject.
Got a question for us? Please mention it in the comments section and we will get back to you or post your question at Edureka | Community. At Edureka Community we have more than 1,00,000+ tech-fanatics ready to help.