Okay hello lagers and welcome to this lecture in this lecture we're going to look at load balances and
health checks.
So this is a lab and you will need to log into the eight IBS console.
Okay so here I am in the adobe us console.
I'm gonna go over to services and I'm gonna start with easy to and what we're gonna do is we're gonna
go ahead and launch an instance we're going to launch two different instances in two different Availability
Zones.
So we're just gonna use a T2 micro and go ahead and configure my instance details to do it into my default
VPC scroll down and I am gonna give this a bootstrap script.
So here's my bootstrap script here it is available in the resources section of the course and essentially
all it's doing is it's running a yum update.
It's installing Apache it's starting the Apache service and then it's making sure Apache starts back
up if this easy to instance reboots that's going over to var dub dub dub H2 male directory and it's
writing a little web page and the web page just says this is Web server 1 and actually I'll just fix
it so that ends our header and it ends our HMO and then we go and then it's going to output that to
each tier melt index not metal case I'm going to paste that in there and then I'm gonna go ahead and
add my storage and then I'm gonna go ahead and add my tags in terms of tags I'm going to make this a
Web 0 1 and sorry let's just go back and make sure that we put it in a specific availability zone so
I am going to put this into a specific subnet I'm going to do this into EU w 1 A so do 1 A for whichever
region that you're using and then I'm gonna go and I'm gonna change this to name and then it's going
to be web 0 1 and then we're gonna add our security groups configure our security groups if you just
use your Web DMZ security group that's fine.
Review and launch and then I'm gonna go ahead and launch it and just acknowledge that you've got your
key pair then we're gonna do exactly the same thing except we're going to change the bootstrap script
to having webs web server too.
So it's go to Amazon Linux to EMI T2 micro scroll down and in here or paste out bootstrap script and
just change this web server to web server 2 and then also make sure that this goes into a separate availability
zone.
So we're gonna go back up and we're gonna go over to our subnet and we're going to put this into us
a W one B next are going to add my storage and I'm going to add my tags and again I'm gonna change my
name and there'll be web 0 2 and there we go gonna add by security group use an existing security group
and we're going to use our Web DMZ security group and go ahead and review and launch and launch and
hit that.
So those two instances are now launching Well you should just be able to navigate to the public IP address
and to check that the that the web server has worked all the bootstrap scripts has worked.
Just got a piece that in here and we can see that web server 1 works.
And if I grab this one here just gonna grab the IP address and just open up a new tab and type in the
IP address and then we go got web server to target web server 1 and web server 2.
So they are definitely in different availability zones as you can see there.
So what we're going to do now is we're going to go over and create our first load balance so load balancer
is here under load balancing we're going to go in and create a load balancer.
So again there's three different types of load balances application load balancer network load balancer
and classic load balancer in this lab we're just going to use classic an application.
I don't particularly want to use network because they are expensive.
So let's go ahead and create a classic load balance of first I'm going to call it my classic L.B. and
then in here were going to do it inside our default VPC.
You can have internal load balances.
This means that they're inside private subnets.
We're not gonna do that.
You can also enable advanced VPC configurations and this basically allows you to select which subnets
that your elastic load balancer is going to be deployed into.
And you should always have a minimum of two.
Again I'm not really going to worry about that in here we can figure out listener configuration so we
could do it on port 80.
You could do it on each piece.
So in Port 443 I'm just going to leave it as port 80.
Gonna go and use our existing security group.
So I'm gonna use my web DMZ and then I'm gonna go ahead and just hit next.
And then this is where we can figure our health check.
So we want it to be checking index not hasty mail because that is our Web page.
It's gonna be doing this using each GDP on port 80.
Now our response time out if you ever want to know what these are just sort of hover the mouse over
the info but this is the time to wait when a response from the health check.
So we want this to be passing or failing health checks really really quickly.
So I'm going to make this as to.
And then the interval is the amount of times between health checks I'm gonna to make this of five seconds
so every five seconds it's going to it's going to wait and see if it's passed a health check.
So down here the unhealthy threshold is the number of consecutive health check failures before declaring
an easy two instances unhealthy.
So I want that as a minimum of two.
Here's our healthy threshold.
Let's go ahead and make this three.
So essentially in 10 seconds it will detect whether or not our easy to incidence has gone down and it
will take 15 seconds for it to go ahead and become healthy.
Next let's go ahead and add our two easy two instances are going to add web 0 1 and web 0 2.
In here you got enable Cross's own load balancing.
This basically distributes traffic evenly across all targets in the availability zones that it's enabled
for the load balancer.
So we definitely do want that in here.
This is connection draining so this is the number of seconds to allow existing traffic to continue flowing
so that's down for five minutes.
Next I'm going to go in and add our tags.
I don't particularly want to tag for this and now I'm going to go ahead and create my lead balancer.
Now just remember loop balances do take you out of free tier nine times out of 10.
This is where you're going to get a cost is when you create a lead balance and then you forget about
it.
So do just bear that in mind.
And in here we've got our classic load balance has now been created and we're given a DNS address record
or a DNS name.
Now note that we're never given an IP address for an elastic load balancer.
So what I want you to do is copy that DNS record into your clipboard before you navigate to that what
you might want to do is just go and make sure that your instances are in service.
So we've got in here right now my instances are out of service so it needs to go ahead and pass that
health check.
So I'm just going to wait for a couple of minutes while this our instances come into service.
OK.
So those instances are now in service you can see it in here.
So all we need to do is now browse to the DNS address of our elastic load balancer.
Go ahead and put that in your browser.
I guess I'm just going to paste it into my browser.
We're gonna go ahead and hit enter and then we go.
Got web server to if I do a hard refresh you'll see that sometimes a hit web server 1 Sometimes a hit
web server too.
So what we're gonna do now we're gonna go back over to the Adobe's console going to go over too easy
to and I'm going to go ahead and shut down web server 1 so I'm going to go to my actions instant states
and I'm just going to stop it.
I'm not going to terminate it.
So that is now stopping the instance.
And of course as soon as this instance has stopped it's going to stop serving each TTP traffic to my
load balancer.
So my load balancer is going to detect that using the health check.
And essentially what it's going to do is it's going to mark the instances unhealthy and take it out
of the load balancing pull.
So just going to pause a video while this stops.
Okay.
So that has now stopped.
Now if we go back over to our Elastic Load balancers and we click on here we can click on our instances
and you can see that one is in service and the other one is out of service.
If I go back to my browser tab and I hit refresh I'm now only going to get web server too I'm not going
to get web server one so our load balancer has detected that web server one has gone down and now it's
sending all our traffic to web server too.
So that's all that classic load balancers do.
You can also do some monitoring in here with the cloud watch.
You can have some cloud Watch metrics for your load balancer but you can see that it's not very intelligent.
It's basically a dumb dumb left balancer is the best way to put it.
So let's go ahead and create a new load balancer before I do that.
Let's just go over too easy too and I'm just going to power up my web server one second to go over to
my actions and I'm going to go ahead and head start and Head Start again.
And then what we're going to do is we'll go in and delete our elastic load balancer our classic balance
or I should say because we're not going to use it anymore.
And so I've deleted that.
And then what I want to do is I want to go in and go to target groups.
I'm going to go ahead and create a target group and a target group is basically where your load balance
is going to request to the targets in that target group and using the target group that you specify
and perform health checks.
So it's basically you could have a group of easy two instances for your European customers.
Then you could have different ones for your American customers which have different language settings
et cetera and you can actually create application load balances that detect it and send it to the right
groups.
So I'm just going to call this web group one is the name of my target group target type we're going
to do it by instance.
You can also do it by IP or by Lambda but because we're using easy two instances right now we're going
to go ahead and just use instances IP address.
You could basically have the web servers that are not inside eight of us.
And you just have the public IP addresses and then lambda we're going to cover off in the service section
of course.
We're just going to do it on port 80.
So in each TTP and then down here it's asking us for our health checks settings.
So the path we're going to look for is indexed each Timo and we can go in here and do our advance health
checks settings so again I'm just going to change the threshold so I'm going to have the healthy threshold
as to unhealthy threshold as three time out is the amount of time in seconds during which no response
means a failed health check.
So let's just do it at five and our interval I'm gonna do this at five as well.
And then the success code down here this is a hate TTP code so 200 or it means it's been successful.
So go ahead and hit create.
It's saying the health check time out must be smaller than the interval.
So let's increase this to six and go ahead and hit create.
And that has now created our target group.
So we've got our target group.
But the next thing we need to do is go in and add our targets you need to go in and add to our instances.
I'm going to go in and hit targets and then in here we're going to go edit and then what we can do is
we can go in and add web 0 1 and web 0 2 and go ahead and hit save and that now adds it into our target
group.
So the next thing we need to do is go in and create our load balancer.
So let's create a load balancer.
This time we're going to use our application load balancer gonna call this my Albee.
So my Albee in here is gonna make it Internet facing we're going to do it overheat GDP and here you
specify the availability zones.
I want it in every availability zone.
Going to go ahead and hit next.
And it's just giving us a warning that it's not using HDTV s but that's fine we don't need to do that
at this stage.
Going to put it into our web DMZ security group.
So it's going to go into there and now we're going to configure our ratings so we can use the new target
group or we can use our existing target group.
So we're gonna use the existing one that we just set up so web group one is done by instance it's using
protocol each ADP on port 80 and it's looking for our index not each team.
So go ahead and hit next register targets.
It doesn't have any registered targets just yet.
We go in and do that in a second.
Let's go ahead and review and go ahead and hit create so has now created our application load balancer
what we need to do is just go over to our target groups and go into our targets.
Right now we have no registered targets but what we need to do is go ahead and add them.
So just hit edit click in here and say add to registered and then go ahead and hit save and then that
will add it to our registered group.
And then basically what we need to do is just pause the video and wait for this status to change from
initial into registered.
So let's go ahead and refresh the page and you can see that the status has changed from initial to healthy.
So our targets are now behind our application load balancer.
Now you might be wondering how is this more intelligent than the other load balancer.
Well if you go into load balances and you go down to here you can see in here you've got your listeners
you've got your GDP listener I.D. and you can go in and view and edit rules and so you can go in and
create rules.
And it basically builds out this if then sort of tree so beyond the scope of this course to show you
this in a lot of detail but you should if you just have a play around with it.
I mean look you can go in and say add condition you can do it on a host header or you can do it on a
path then add an action forward to redirect it turn fixed response et cetera et cetera.
You can build this out.
Now if you do want to learn this in a lot of detail we do have a dedicated course to application load
balances on the a cloud platform.
But for your exam basically what you need to know is that application load balances are much more intelligent
than classic load balances you use application load balances if you want to do intelligent writing like
something like this you'd use network load balancers if you need a fixed IP address for your load balance
or if you need ultra high performance and then you'd use classic low balance or if you just need really
simple routing and you don't need any allegiance behind it and you want to keep your costs down.
Now let's go and check that this is actually working so we just go over to our application load balancer.
We go over to our description you might want to make this a bit bigger so you can see it down here we've
got our DNS name.
Copy that into your clipboard and I'm just gonna pasted in here.
So this is my new application load balancer.
There we go.
Got a web server to a web server one web server to web server one web server too.
So it is definitely working.
So on to my exam tips will just remember the three different types of load balances application load
balances for intelligent rooting network load balances for very high performance and then classic load
balances where you want to keep your costs down you don't need any intelligence built in.
Remember that a 5 0 4 error means that the Gateway has timed out and this means that the application
is not responding within the idle time out period.
So what should you do.
Well you should troubleshoot the application is this going to be the web server or the database server.
Also remember that if you need the IP four of your end user inside your classic load balancers you need
to look for the X forwarded for header.
And then finally just remember that instances are monitored by MLB either in service or out service
and health checks check the instances health by talking to them and load balancers always have their
own DNS names you're never given an IP address do read the elastic load balancer F.A. queue for classic
load balancers in fact I just read the FAA Q For all of load balances because they do come up they will
come up probably 10 questions in your exam will be on the different load balances so bear that in mind
as well and if you want to do a deep dive on application load balancers check out our deep dive course
on a cloud.
So that's it for this lecture everyone.
In the next lecture we're going to look at some more advanced concepts with elastic load balances.
Then going to move on to auto scaling groups and we're then going to look at how we can create highly
available architectures or hake a architectures and what we'll do is we'll go through and create a highly
available WordPress site.
So if you've got the time please join me in the next lecture.
Thank you.