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

25. [활용] Setup auto-scaling group

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

 

## 세션관리가 필요한 Auto Scaling 그룹 만들기 !!
( ASG 사용하면 ALB Sticky Session 이용안하고, DynamoDB 이용해야함)

1) Launch Configuration 생성 (Auto Scaling 항목 아래에 있음)
- 기존 AMI 이용
- 기존 IAM Role 이용

2) ASG 그룹 생성 (위의 LC를 이용함)

3) ASG 그룹에서 ALB의 TG그룹을 연동

4) TG그룹에서 인스턴스 확인 가능

5) ALB DNS로 접속 테스트

6) 세션정보를 DynamoDB (중앙저장소) 관리 성공

 

 

OK so in this video let's set up our auto scaling group right.

And we need to go through a series of steps here to create the group here.

So this is the auto scaling group right.

And what we need to do is use the AMI the AMI that we have the one that we created in the first

module.

This was the module one where we deployed our application.

Same same AMI we can use that and we also will have will have to use the IAM role because this

time in this particular module we need our application to talk to dynamodb.

So so the application will be connecting to the dynamodb table for managing session information

and and the application needs IAM permissions it needs permissions to access the DynamoDB table.

So the role is very important but the role has to be has to be there with the appropriate permissions

and when we configure the auto scaling group we will be using the will be using the role as well.

this is an important aspect.

Ok then we will create.

Right.

Then we create the auto scaling groups here and and in the scaling group.

So this is these two.

We will have to configure in the launch configuration right what is called the launch configuration.

This is just a configuration and the auto scaling group uses this configuration to determine what kind

of servers will come up right so.

So we will be using this AMI.

So the autoscaling group knows what software what operating system will be used on the instances

right.

And the launch configuration will have the role so the application in the autoscaling group will also

have those permissions.

OK so the first step is the launch configuration.

The next step will be the auto scaling group itself right.

And initially you know we will just have this group with a fixed number of fixed number of servers which is two right

which is 2.

And we also have to make sure that the group is configured for two availablility zones.

This is for fault tolerance purposes.

We can't have all our servers in a single availability zone.

So we need to make sure that this also is configured and this should match with the zones that we

have configured our load balancer.

So if you are using zones A and B we need to make sure both the load balancer and the auto scaling group

are using the same two zones.

OK so this is something we have to use something that we have to configure.

OK.

Once the auto scaling group comes up right.

We then have to configure the autoscaling group with the target group that the load balancer has

remember the load balancer has a target group which is like a placeholder here right.

So we need to make sure once the group comes up we connect the auto scaling group and the target group.

This way we connect the load balancer and the servers in the auto scaling group and then the load balancer will start distributing

the traffic using round robin.

So this is important.

Otherwise load balancer doesn't know about the autoscaling group.

Right after we have done that we can then verify the application and then verify the application.

via the load balancer the user will have to go to the load balancer.

Right.

And so this is the load balancer's DNS name that we will have to use here.

And then we verify the dynamodb page which dyn session dot PHP right we just have to verify

this page and just check that even though we have an auto scaling group.

the session is maintained and even though the load balancer does not have sticky

sessions remember we dont have sticky sessions here even though we dont have sticky sessions the session

will be maintained right we keep seeing the welcome message right and will not see the form.

Once we have created the session one time.

OK.

Right.

So all this we have to have we have to do let's see step by step how to achieve this.

So the first step is to create the launch configuration.

So let me go to the EC2 instance and here under load balancing.

Let's I'm sorry.

Under autoscaling.

Let's go to launch configurations and let's create a launch configuration.

This is just a configuration right and we need to specify the same details that we specify for individual

instances right.

We need to specify the same details and the only difference is that this configuration will apply to

all the servers in the scaling group.

OK.

So.

So the first step is the AMI and we use our AMI right not Ubuntu but our AMI because in the auto scaling

group we want our PHP application to be be running it.

So we choose our AMI and the other details can be the same.

So we choose micro.

Is this one more step here in the middle let us give this a name something like this.

Right this is the name of the launch configuration and this over here this is a very important step.

which is the IAM role the role has to be configured with the launch configuration just like we con

figure a role with an EC2 instance.

But then we individually see the instance we have to make sure that the role is configured with the

launch configuration so that all the all the servers in the auto scaling group will have this role

as well.

Right.

So this is our IAM role that we are now configuring with the launch configuration OK.

Otherwise it's the same same details you know.

The EBS root volume the security group we are still using the default security group at this stage in the

course.

And just to review we're using our own AMI not ubuntu our own AMI which has our

PHP application.

And the second thing is we also have configured the role we have configured the role which is absolutely

important in this particular Module.

So let's create the launch configuration and also the private key the private key as usual we

use the same same one that we've been using throughout this course.

OK.

So that's our launch configuration.

Let me let me exit this for a moment because I want to show you the launch configuration as a separate

entity.

The launch configuration is just a configuration right.

You can have many configurations as well.

And the auto scaling group is a separate thing.

It is a separate thing.

And the auto scaling group may use one launch configuration today it may use some other configuration

tomorrow.

Right.

So so it's important to understand that the configuration is different from the autoscaling group itself and nothing

happens when we create a configuration.

it's just just a configuration.

OK.

Our next step is to use this configuration and to create our auto scaling group.

Right.

And and here we will let us give this a name.

Something like this right.

Let's start with two.

OK it always makes sense to have a minimum two instances for a fault tolerant architecture.

So let's not start with two.

And let's also configure the zones that we want to use.

I remember in the balance we had used for Zones 1 A and 1 B zones 1 A and 1 B

is configured in the load balancer so therefore let's make sure the auto scaling group also is

using the same two zones so that the two are lined up together should be lined up.

And this is also important configuration.

OK.

So so otherwise let's keep this group at an initial fixed size.

Right.

And and let's go ahead and create the autoscaling group i have just skipped the notifications and tags page.

That's not very important at this stage.

Okay.

So basically we're creating an autoscaling group using the launch configuration that we had created earlier.

And the launch configuration has our AMI and it has our role and the autoscaling group here we have configured.

The zones the two zones one A and one B that the load balancer users we use the same zones in the auto scaling

group as well.

Right.

And we're launching two servers as part of this auto scaling group.

OK.

So that's it.

He is our auto scaling group and the group will create two instances automatically.

So we have set a desired capacity of two and auto scaling will launch those two servers automatically right

we don't have to create servers in auto scaling groups.

now you can see the two servers are coming up and auto scaling groups are intelligent so we know that we have to use

two zones.

So the group will create one server in each zone for fault tolerance purposes OK.

All right so these are coming up.

And also we have to make sure that we configure the target group in the auto scaling group.

remember this is how we can connect the auto scaling group servers to the load balancer.

So here we configure the auto scaling group to the target group.

This is how they load balancer knows that these EC2 instances are there and the load balancer has to work

with these instances.

So.

So let's do that now.

And what we do is we edit the auto scaling group and in the target group filed we select our target group

select our target group.

OK so that's it very simple.

And now the load balancer is connected with our auto scaling group.

OK.

So if you go to the load balancers target group here right you can.

You can now see that the two instances the two auto scaling group instances will show up as targets

in the target group.

Right so so any moment now let's see let's wait for this

it so any moment now because we've just we've just connected the two so you can now see the two

of servers both belonging to the autoscaling group have have now been registered with the target group.

And the status is initial we should wait for both of these to become healthy right like this.

And now we can test ok now can verify the application.

So for that we go to the load balancers DNS name.

Right.

This is the DNS name of the load balancer.

And let me copy this and and let's test it like this.

Right.

You can see the PHP application is visible via the load balancer right.

And in this module we are only interested in the dynamodb sessions page.

So let me click on that and let's see if this page.

OK.

So let's see.

Let's test our dynamodb sessions page using the load balancer and here is the PHP application.

via the load balancer and let me enter my name here.

And let's see if the session is created.

Right now you can see the session is indeed created and we see the welcome message.

Let me refresh this page and.

And you can see the session holds by the session holds.

And remember we are using a load balancer here and we also using an auto scaling group with two

servers in two different zones.

Right.

But the number of servers we have.

And whether those are new servers or not doesn't matter because.

Because we're using a centralized store for our sessions.

In summary in this video what we've seen is how to how to create an auto scaling group with sessions

centralized in dynamodb.

And we went through a few steps here.

The first step was to create the launch configuration and remember using the AMI that we had created

in module one like this one.

And then also the role is absolutely important because without the role the auto scaling groups servers will

not have the permissions to talk to the dynamodb table.

After the launch configuration was created we used that configuration to create our auto scaling group

with two servers and we had to make sure that the zones matched the zones of the load balancer

so match with these zones that we configure in the auto scaling group as well essentially line up the

load balancer and the autoscaling group properly so so so so we have to make sure this is done and then

we simply connect the auto scaling group with the load balancer by adding the target group of the

balance or in the auto scaling group's configuration.

So we have to edit the autoscaling group and supply the supply the target group there.

This is how we connect to the autoscaling group with the load balancer and we saw that shortly after we did that

in the target group for Target listing we saw the two auto scaling groups servers there.

And once those groups that once those instances change to a healthy state we can verify we can

verify the application using the domain name the DNS name of the load balancer.

So the ELB DNS name we can use this.

And of course the dynamodb session page and see if the whole set up the whole set up is working or not.

And we did verify that we were able to create a session and when we refreshed multiple times the session

 

 

 

반응형

댓글