본문 바로가기
[AWS]/Highly Available, Scalable, AWS Stack

20. Setup load balancer

by SAMSUNG CLOUD-OKY 2022. 1. 23.
반응형

 

This video let's see how to create a load balancer so the way we do this is will run through

the launch sequence of the load balancer and there are a few things we'll have to configure.

First we have to make sure that we use the application load balancer which is good for things like http and https

load balancing.

 

OK.

Next we'll have to make sure that the load balancer comes up in the default VPC at this stage of

the course or we are creating everything in the default VPC. Also we will have to choose the subnets.

So the subnets or the availabilility zones because each subnet has to be in a zone

So when we choose a subnet we also choose the availability zone and make sure that you choose them

in such a way that your instances that that you have let's say the instances are in a and b if they are in A

and B then you should choose both those zones because the load balancer will only be able to distribute requests to

subnets that you configure.

Right.

If your instance is in a different subnet and that subnet is not configured with the load balancer

the load balancer will not be able to forward those requests to that particular instance.

In general in this course you should you should pick a couple of zones and just stick to that right.

In all the configurations this could be for the load balancer or this could be when you launch instances, this will also be

be useful the two zones.

You have to configure when you use the auto scaling group as well.

So make sure that you correctly configure the subnet and the availability zones.

Also we use the default security group right once again.

At this stage in the course we are using the default security group throughout for all kinds of resources

as well.

And lastly we have to configure what is called a target group.

Right.

This is sort of a placeholder and it sits between the load balance and the instances.

Right.

And later we'll have to register all the instances to the target group like this.

It's called registration.

And once that happens the load balancer knows about these instances and will start distributing requests

to these instances.

OK.

So we have to take care of these configurations when we create this load balancer.

Let's see how to do this.

OK.

So let's see how to create the load balancer.

Let's go to the AWS management console and from the EC2 service let us find the load balancers section

section over here right.

Remember load balancer is an EC2 feature.

It's not a separate.

Service right.

Let's use this button create load balancer and start configuring the load balancer.

The first thing we do is choose application load balancer.

OK this is good for applications and.

And let's give this a name something like this.

Right.

Remember this is an Internet facing load balancer because this would be open to the public and the listener

is port 80 by default.

Later you may want to add another one for HTTPS.

But for now let's keep things simple and leave this out. Choose the VPC.

This is the default VPC and we don't have any VPC right now.

So we choose this one.

And in any case in any case we have our instances and the RDS instance as well in this VPC

so we have to choose this one.

And also choose zones but this one you have to do carefully because zones that you select here your EC2

instances that you want to use with this load balancer must be in the same two zones so you have to choose

these carefully.

And in general in this course just pick a couple of zones and stick to that.

just stick to that in every configuration that you do.

OK so so so I'm using one A and one B.

In my in my setup.

OK.

Next let's configure the security group.

This is pretty simple.

We just use the default group that we've been using from the start in this course.

And now let's configure the target group like this is what we have to use later when we register the

EC2 instances with this group.

So let's give this a name as well.

Let's say something like this.

Great and now in this step register targets we can add EC2 instances to the target group right here

while we are creating the load balancer.

But we can also do that later.

Right so let me skip this step.

In any case I don't have any instances at the moment to be to be registered.

OK so here's the review page.

And what we're doing is creating an Internet facing load balancer listening on port 80 not yet

listening on port 443, HTTPS.

But the load balancer is in the default VPC and it is configured to use two subnets or two zones and

those are one A and one B EC2 instances must be in these two zones.

We've also created also used the default security group by the way.

Right.

And we have created a target group and we have to register instances in this target group next.

OK.

So this is how you create the load balancer and what you should do is that the load balancer will initially

be in the provisioning state.

You have to wait for this to become active only then will this start functioning ok.

And this might take.

Maybe a couple of minutes maybe a couple of minutes at the at the max.

Also note that the load balancer has a DNS name a DNS name.

This one and this is what you'll be you'll be using to test your application.

So you can copy this and you can replace the IP address that we've been using thus far to test the

application.

But you can replace the IP address with the load balancers DNS name.

And then test the application that we way right now this won't work because the load balancer is

being provisioned.

And also we have not yet registered instances with this.

load balancer.

But it's important to note that the DNS name of the Load balancer is what we will be using to access the

applications via the load balancer.

OK.

So that's it.

This is how you create the load balancer.

And remember we have selected application load balancer we have created this in the default VPC you're

selected two AZs right.

and the instances must be in these two AZs.

And we also use the default security group the load balancer also has low security group.

But but right now we are just using default and we've also configured a target group.

And this is the target group that we'll be using later to register instances so that those instances

can work with this load balancer.

So.

So good luck with this.

task

in the studio let's take a look at how to register our EC2 instances with the target group that

we have for our load balancer.

Let's remember we should have two instances Okay one and two and these should be in two different zones

and those zones should be configured in the load balancer.

Otherwise the load balancers and not be able to work with these instances.

So I'll assume that you are using zones A and B as well.

Right.

And those are configured in the load balancer and the two instances are also in A and B.

OK.

So these are two instances you can see the first one the first one is in one B

here.

Right.

And the second one is in one A.

So we have two instances in the two zones.

Now let's go to target groups.

And under targets's let's edit right.

This is the this is the target group under the target's tab let's edit.

And you can see there are two servers in two zones one A and one B.

We select both.

And we say add to registered and and then don't forget to say save and this will register

both the instances with the target group which means the load balancer will be able to distribute

requests to these two.

Servers.

And remember wait for the status to turn to healthy ok you can now see these are healthy

both are healthy.

And now you can test the load balancer.

So let's go to the load balancer copy the DNS name like this right.

And let's try out the PHP page right.

So we say load balancers DNS name and then the index.php page.

Right so you can now see the the application is responding right.

And the load balancer will do round robin.

So.

So when we refresh this page the load balancer will send the request to another server another refresh

it will send it back to the first.

That's how the load balancer works.

And you can now go ahead and test the other pages in this application.

All right.

So this is how we have registered the instances.

Right.

Essentially we go to the target group and then there's a targets tab there and from there we simply

select the instance has to be registered and proceed.

OK.

And then you can verify as well that the application is working the load balancer is working and the application

pages should load when you try out the load balancers DNS name.

 

OK.

All right so good.

Good luck with this.

This task.

 

 

 

반응형

'[AWS] > Highly Available, Scalable, AWS Stack' 카테고리의 다른 글

22. Intro: Scalability - app layer  (0) 2022.01.23
21. Configure sticky sessions  (0) 2022.01.23
19. Configure & verify application  (0) 2022.01.20
18. Centralize images in S3  (0) 2022.01.19
17. Separate db tier  (0) 2022.01.19

댓글