CREATING AN APPLICATION LOAD BALANCER FOR THE VPC
For creating a load balancer, let's first create a VPC with 4 subnets (2 public and 2 private)
Now create two route tables, one for public subnets and one for private subnets
edit the routes to attatch internet gateway
similarly for private route table, add the route to NAT
now add the subnets to the respective route tables
Add proper vpc and subnet, plus create a security policy
navigate to advanced settings and add following commands in user data
repeat the above steps to create second instance as well.
Now it's time to create load balancer
In security groups tab click on create new a add the following inbound rules

Now choose this security group in the load balancer tab In listeners and routing section create a new target group and add the ec2s previously created into the target group leave the group details section as such and proceed to register targets

add the new security group we have created to the ec-2 to security group that was created earlier

Add the LBSG security group which is new security group that was created for the load balancer to Sg-1 (ec-2 security group) save the changes and look into health status of target group by navigating that respective section once the status of the instances become healthy you are ready to test the load balancer
Navigate to load balancer tab and copy the DNS name, paste the URL in a new tab

You will notice the following website with the following pages after successive reloads now we can confirm that our load balancer is working as expected


Comments
Post a Comment