Please note that this content is targeted for solutions architects and 1
SysOps administrators. If you're a developer you may want to skip over this 2
one. Welcome back to back space Academy in this lab we'll be 3
implementing a network load balancer and we'll also be putting it in front of an 4
auto scaling group of ec2 instances so first off we'll create a target group 5
for that network load balancer and then we're going to also create an auto 6
scaling group and that will automatically launch ec2 instances based 7
upon demand and then once we have done that will create a network load balancer 8
and we'll set that up so that it can forward requests to the target group and 9
then on to the auto scaling group ec2 instances okay so here I am in the ec2 10
console just scroll down to target groups and we're just going to create a 11
target group in the same way that we would for an application load balancer 12
so he create target group will give that target group a name and our protocol is 13
going to be TCP because a network load balancer cannot support HTTP or HTTPS 14
we'll leave port 80 as it is there and we'll leave target type as instance 15
because we have a choice error instance or IP and we're going to be directing it 16
to instances and their health checks will also be on TCP as well so we just 17
create that target group now okay so that's created that for us now what 18
we'll do is we'll now create our auto scaling group so the first thing we need 19
to do is we're going to jump into launch configurations so what a launch 20
configuration is it describes how our ec2 instances are to be launched what am 21
i they're going to be using what instance type and all that sort of thing 22
just the same as you would manually launch an ec2 instance it will it will 23
do that automatically for us so we just click on create an auto scaling group 24
and then we can create our launch configuration first we're just going to 25
use the Amazon Linux AMI these servers are not going to be doing anything as 26
such we're just going to get them up and running and register them in this auto 27
scaling group 28
ok so we'll select t2 micro we'll give this a name we'll leave everything there 29
as it is and we'll just go to add storage will leave storage as it is now 30
with our security group we're going to create a new security group but we need 31
to add a rule to this fund so we need have TCP traffic on port 80 and we'll 32
just select anywhere for that and now we've finished our launch configuration 33
we can review that and create launch configuration we just select a key pair 34
so now we have defined our launch configuration so our auto scaling group 35
knows now how to launch these ec2 instances what key pair to use what 36
instance type to use what am I to use and what security group to use so what 37
we're going to do now is actually create this auto scaling group now so we'll 38
give it a name and we're going to start with one instance that will be fine 39
and now we're at our subnets so we're just going to add all of a sudden it's 40
in here 41
and we click on advanced details and what we do is we're going to receive 42
traffic from a load balancer and our target group will be our NetworkELB 43
target group that we created previously and our health check type it will be 44
from the elastic load balancer so we select that as well 45
and we leave the rest as it is and we click configure scaling policies so now 46
we're going to use a scaling policy to adjust the capacity of the group so what 47
a scaling policy is going to do for us as demand increases on our ec2 instances 48
they're more of these ec2 instances will be launched and as it goes down it will 49
scale in and reduce a number of ec2 instances so the metric we're going to 50
use for that will be the average CPU utilization and we're going to scale 51
between 1 and say 6 instances and our target value we're going to put in there 52
50% which will be 50% utilization is what we want all of our ec2 instances to 53
to be around and we're going to give it 300 seconds or five minutes to warm up 54
after a scaling event has occurred now we can just jump now to review and 55
create auto scaling group and that successfully created that for us ok so 56
now we can see we've got our group the old beam the name for our auto scaling 57
group and it's using the launch lb launch configuration that we named it 58
launch lb to launch ec2 instances so we've got here our desired is one our 59
minimum and maximum that we're going to have available depending on what the 60
demand is up to 6 so we currently have no instances so we just refresh 61
that and we've got one instance now being created so we go in two instances 62
we should see that one has been created by the auto scaling group 63
and there we can see it's running and it's still going through it's 64
initializing checks so what we can do now is that we've got our auto scaling 65
group up and running we've got our ec2 instances being launched we can 66
now look at creating that elastic load balancer or that network at elastic load 67
balancer and start associating that to this target group so let's go to load 68
balancers and create a load balancer and this time we're going to select the 69
network load balancer and we'll give our load balancer a name I'll leave it as 70
internet-facing and we can see there we've got our listeners so TCP so it's 71
receiving traffic on port 80 and that's TCP traffic only and we can see there 72
that is all that is available for us a network load balancer doesn't do HTTP or 73
HTTPS and the availability zones I'm going to select all of those 74
availability zones and next and now is where we select our target group that 75
we're going to be directing our request to so and it won't be new tugger it'll 76
be our existing a target group and that is our network lb that we created 77
previously and that will be forwarding it over on TCP on port 80 and our health 78
checks again will be on TCP as well so next we register targets now there is 79
already a target registered there so the auto scaling group already created this 80
isn't instance for us and that was already inside that target group because 81
we have associated the auto scaling group with this target group already so 82
there we have a instance ready to go we can review this and we can create it and 83
that's finished okay so let's have a look at what's going on here so we've 84
got our net yield the load balance that we created and here's a description of 85
it and it's got its availability zones there it's saying 86
network elastic load balancer and if we if we click on listeners we can see 87
there that we've got a listener on port 80 for TCP and all requests are going to 88
be forwarded to the network yield the target group so trick click on that 89
network ELB target group but can you have a look at and see how that works 90
and there's that network ELB target group that we created and remember we 91
also associated our auto scaling group with this target group and so if we look 92
at the the targets here we should see a target in there and we can see there 93
we've got a registered target so it has been the auto scaling group has 94
automatically created an ec2 instance and it is automatically registered that 95
that that instance with this target group then one thing to notice here it 96
is saying that it is unhealthy now the reason it is saying that is unhealthy is 97
because all I've done is is launched a Linux AMI it doesn't have any 98
application on it so it's not responding to any TCP requests on port 80 at all 99
and so those health checks that are going out to check whether it's alive 100
they're coming back they're not get being returned so that's why it's saying 101
status unhealthy but in obviously in a real application you would have an 102
application there that would be responding to those TCP requests ok so 103
now that we've finished lab we need to clean it all up to make sure that we 104
don't get a bill at the end of the month so we work backwards so the first thing 105
we need to remove will be the load balancer so we just select that and then 106
delete that and that's god quick as that the next thing we need to remove will be 107
the auto scaling group 108
and we'll delete that and the next thing we need to remove will be the target or 109
the target group 110
and we'll delete that so we just go and check those instances are starting to 111
terminate and it still hasn't quite kicked in yet 112
so it's still deleting that and so after period of time the instance will be 113
removed from from our so from our instances so that brings us to an end of 114
the lab there are quite detailed lab notes for this so make sure that you 115
download the lab notes and do it all yourself once you've done that I'll see 116
you in the next lecture