Okay.
Hello cloud gurus and welcome to this lecture and this lecture we're going to look at how we can add
a bit of resilience and auto scaling.
We're going to go through and hopefully test our highly available WordPress site.
So first of all I just want to show you a network diagram.
This is what it's going to look like.
This is what we're going to do.
This IP address is just the IP address of our current easy to instance.
Yours will obviously be different.
And this is going to be our writer notes every time our marketing team wants to go and write a new blog
article for our WordPress site.
They're going to navigate directly to this IP address this easy to instance would then be configured
to push any changes to us three.
Now we're gonna have a fleet of easy two instances here.
And their job is to constantly just polled the S3 bucket looking for changes and when people visit our
domain.
Hello cloud gurus 2019 dot.com Route 53 is going to send them over to this group of easy two instances
that's going to send it over to this fleet.
It's not going to send it to our writer nodes so it's just going to send a our read notes only.
So let's go in and set this up now.
Okay.
So I mean my bar dub dub dub reached him Al directory on my easy to instance and they just need to go
over to my ATC directory and then when I want to do is I want to edit a file the files called cron tab
so just type in nano chrome tab and chrome tab is essentially like scheduled tasks for Windows it's
a way of running commands at a particular at basically every minute or every hour every day or every
month or every day of the week et cetera et cetera.
So at this easy to instance what we're going to do is we're going to take a snapshot of it.
And this is going to be our base image for our easy two instances that are going to be reader nodes.
So this is going to be the WordPress site that's going to be behind an application load balancer so
that's going to be but behind route 53 on our domain name.
So this will be reader nodes only.
And so what does a reader node want to do.
Or essentially it just wants to scan S3.
We can do it every minute and we're going to look for any changes to our WordPress site.
And if there is a change it's going to download that change to this easy to instance.
So what we're gonna do is gonna do a star.
So we want this command to run every minute and then we want four more stars.
So we want it to run every minute of every hour of every day of the month of every day of the week.
And we want it to run at Route level.
So what's the command that it's going to run.
It's gonna run an AWOL segment.
We're gonna be using S3 and what we're going to be doing is we're going to be sinking to S3 and we want
this to be a perfect copy so we want to delete any files off our easy to instance that aren't in our
buckets.
So we always want this to be a perfect copy of our bucket.
And so then what are we going to sink.
Well we're going to sink our S3 bucket and if you can't remember the name just head over to the console
head over to S3 and you'll be able to see it in here.
So mine was called a cloud guru word press code and you can copy that into your clipboard up here.
So I'm going to piece that in here.
Where do we want to sync it too.
Well we want to sync it to Alvar dub dub dub hitched here male directory and that's all that command
does.
So it's going to look for any changes in S3 and then it's gonna go ahead and essentially download those
changes if we've deleted files in S3.
It will also delete the files from our easy to instance that's the sync command and that's why we use
the delete markup.
So let's go ahead and hit control X if you want to save just hit.
Yes sir.
Yes.
And then hit enter and that has saved your cron tab.
So it is going to run this command every single minute.
If you are really really impatient you want this to start up straight away you can just do it by doing
service Kron D and then restart as soon as you restart the cron service it will automatically just basically
run all the commands.
So what we want to do now is just go ahead and test this some back in S3.
I'm gonna go into my code and then what I'm gonna do is I'm going to just upload a file to S3.
Can add this file and I'm just going to add Hello Dot text he has such as a text file that says hello
cloud gurus so going to go ahead and head open and we're gonna go ahead and hit upload.
So that has now successfully uploaded.
If I just alt tab back over here again I could be really super impatient and just restart the service
and then I could go over to my var dub dub dub reached here Mel directory and then if we type in L S
hopefully we'll be able to see it and there it is Hello Dot text T.
And if we catch our Hello Dot text T and it's case sensitive so if we can't Hello Dot text T and hit
enter we'll be able to see that says hello cloud gurus.
So that is now working now that this is working we want to create an Amazon machine image because this
is going to be our golden template or our gold boot image for our WordPress servers in our auto scaling
groups back in E.C. to what we want to do is just go over to our running instance let's go ahead and
go to actions and let's go ahead and do image and we're going to go ahead and create an image of this
and the image name is this is gonna be my wordpress and then we'll call it read node an image description
is this is the default read node for WP For Wordpress and we're going to just put this on general purpose
SSD and let's go ahead and create our image that is now creating our image.
Now doing that it will reboot your easy to instance if you actually just go back over to assess each
window you'll be able to see that it's been terminated.
There was a no reboot option I probably should attempt it but I didn't.
So I'm just gonna wait for this easy to instance to come back.
Okay so let's go over and click on our e-mails and hopefully we will see our HDMI in there.
Took a couple of minutes but it is definitely there and we can use this EMI in our auto scaling groups.
Now before we go and create our order scaling groups let's just go back over to our easy to instance.
I'm just going to SS each into my easy to instance and it is now connected going to elevate my privileges
to root.
I'm gonna go over to my ATC directory and I'm just going to clear the screen and I'm going to nano Micron
tab and what we're gonna do because we've got our reader nodes now what we want to do is go ahead and
change this command because this is now going to be our right node and essentially all we're doing is
reversing it.
So instead of saying delete here what we're saying what we're gonna say is var Dr. Abdullah hitched
here male.
So essentially what we are doing is we want to sync Alvar dub dub dub reached email to our S3 bucket
and then we'll go through and delete this at the end.
So just gonna go in and delete this at the end.
So we need to run one more command and what this command will do is sync to our other S3 bucket because
we want it so that if any images are uploaded to this easy to instance it's going to be distributed
throughout cloud front as well.
So we're going to do this every minute going to do this of every day of every month whatever etc etc.
Then we're going to do it at root and we're going to run the command NWS S3 and then sync and we want
to use the delete marker as well and then we're gonna do the R dub dub dub reached temple and then forward
slash WP hyphen content and then forward slash uploads and then in terms of the S3 bucket its S3 and
then a cloud guru.
WP And then hyphen media and then hyphen.
RJ k 19 so make sure you get the bucket names right.
Because otherwise this isn't gonna work.
It is also useful to go in and just test that the files have been uploaded to your buckets so go ahead
and save and then go ahead and exit.
Then if we go over 12 dub dub dub each team l directory let's just type echo this is a test and we're
going to output that to test text.
So that has now output at it again if you want to be really super impatient just restart the cron D
service so service cron D restart and because we have done a review you may just want to check your
TPD service and it would check that it has actually come back up.
So we'd do hate to DVD and then status and hopefully yes.
So that is definitely still on.
So let's go back over to S3 and see if our test text has been sent to our S3 bucket some back in the
AWOL management console.
We just go over to services and click on S3 and just go into the buckets.
I'm going to go into my code bucket and then we go we can see my test stock text.
No I did do this yesterday and I went straight in there and it didn't appear and I thought to myself
what's going on.
And it's actually just eventual consistency.
I just had to hit refresh probably like a minute later and it was there.
So if you go in and you can't see the fail like just go away for one or two minutes and come back and
then just refresh it you should be able to see it.
So just a reminder of the architecture of our site.
We wanted to have one right node and this would be a basically a single easy to instance that our bloggers
would go on and create articles for and that's what our easy to instance is right now.
And the reason is that one is because the cron command that we just set up is taking its local copy
so it's all the local assets on that and it's pushing it and sinking it to S3 every minute.
So if somebody goes into this easy to instance and they do a new blog that will automatically be pushed
out to S3 within a minute.
Now this you probably wouldn't want to put behind a user you could put it behind a domain name but you
might want to put it behind right.
Dot Hello cloud gurus 2019 dot com.
You definitely don't want the general public trying to access this easy to instance you want to keep
this as your master writer node then what we did before with the first cron tab that we set up or cron
job that we set up we're actually getting our easy to instance to pull files down from S3 and then we
took an Ambi of that easy to instance.
So that's the EMI that we're now going to use to build out this part of our website.
We're going to use that EMI and put it into an auto scaling group and that auto scaling group gonna
sit behind our application load balancer and then when people go and visit our website route 53 is gonna
send them to our application load balancer and then it's gonna go on to our U.S. two instances that
are behind that.
And those easy two instances will be polling S3 every minute trying to download a local copy of their
file.
So let's go ahead and set that up now.
Okay so we're back in the AWOL console.
Let's go over to E2 and we're gonna go ahead and create a launch configuration group and then followed
by an auto scaling group singing go down here.
Let's go down to auto scaling groups.
If you do try and create an auto scaling group first it will prompt you to go and do a launch configuration.
So we go in here create and in here it says create an auto scaling group.
So we're gonna use a launch configuration and we're gonna use a new launch configuration.
I'm gonna go ahead and hit next.
We're gonna use our Miami Amy's so click over here and then you can see here my wordpress read node.
So let's go ahead and select that and then we're gonna just use the T2 micro in terms of our launch
configuration.
We're just going to call this my wordpress launch configuration.
I am RO you are going to need S3 access.
It's in critical because obviously it's gonna be downloading the code from S3 in our advance details
in here.
We could pass it a bootstrap script.
So this is gonna be our bootstrap script.
It's available in the resources section of the course you need to change this to be your bucket name
but essentially all it's doing is it's sinking and using the delete marker and it's going to sink S3
to your var dub dub dub.
Each team l.
So as soon as it as soon as your easy two instances are launched in an auto scaling group that's gonna
run a yum update and then it's gonna download the latest copy of your S3 bucket so pasted that into
the boot straps script IP address just say leave it as default we are doing this entire default PPC
go ahead and add your storage we just need an eight gig general purpose SSD in terms of the security
group choose your web DMZ security group hit review and now we're ready to create our launch configuration
so we're just going to be using a T2 micro we're using our EMI and it's going to be deployed into our
web DMZ so next let's go through and we're going to do as we're going to create our order scaling group
so auto scaling group let's call this my wordpress reader nodes so something like that keep it simple
we're going to start with two instances that's totally up to you as to how many that you want I'm gonna
do two in terms of our network we to use our default VPC subnets just select all the subnets in here
because you want it spread across as many availability zones as possible in here we're going to say
Rich receive traffic for one or more load balancers so you can either choose your classic load balancers
or your target group we're gonna use this one so my wordpress instances the health check are we gonna
do an LP health check or an easy to health check I'm going to choose an ESB health check so we'll be
we'll go through and I'll be able to monitor this your health check grace period it's totally up to
you what you're going to do for this I'm gonna choose sixty seconds so it updates quite a bit quicker
and then everything else I'm going to leave as default and I'm gonna go ahead and configure our scaling
policies so we can keep this group at its initial size we can use scaling policies to adjust the capacity
of this group we could do that and go in and start running commands to max out the CPA but I'm sure
you get the point you can now you know you can order scale based on CPE utilization et cetera.
So I'm just going to leave it at keep initial size I don't want to really add any notifications can
get quite annoying.
So the name we'll call it My Word Press and then reader notes then I'm gonna go ahead and hit review
and so we're going to keep the group at 2 minimum group size 2 maximum group size 2 we can change all
of this later.
So let's go ahead and create our auto scaling group and we're going to go ahead and hit close now what
we probably want to do is go over to our target groups and take our right node out of that target group.
The reason for that is we don't really want it to be getting a read traffic and we've you know we've
already connected up our Hello cloud gurus dot com address to route 53.
So let's go in and go to our targets and go edit and we're just going to remove this one from the group's
going to remove it from the register target and go ahead and hit save.
Now if we go over to easy to dashboard we should be able to see some instances.
Right now we've got one that's on line and we've got another one that's coming up online and you'll
see the two new ones because they're initializing they are in different availability zones but our writer
node annoyingly is in the same availability zone as one of our reader nodes.
You may want to put this in its own auto scaling group if you wanted to do something like that but I'm
going to keep it simple and in here we can see that names now so anything that says my wordpress Amen
Amen is our reader nodes and my golden image.
You might just want to change this to the my wordpress and then write a note.
Right.
Note There we go.
And so now it's very easy to see the difference between our reader nodes and our writer nodes.
So I'm just going to pause the video to wait for all of this to come back up and then we should be able
to go over and browse our Web site.
Okay so these are up and running now.
Let's just go over to our target groups and we'll have a look at our registered targets.
So we've got our two registered targets in here and their status is coming back as healthy.
So I guess the next thing to do is to go over to our domain case so I'm going to go to Hello cloud gurus
2019 dot com.
Gonna go ahead and hit enter and then we go we can see that it is loaded so it is going to those two
reader nodes.
Now what we can do is if we just go to forward slash and then WP hyphen admin we can actually go in
and log in that will allow us to then log in.
And if you just enter your password so mine was a cloud guru Kay have logged in now and I'm actually
logging in.
If you look at the Domain I'm logging into my right to node.
And so what I'm going to do now is I'm gonna go ahead and add a new post and we're gonna add new I'm
just gonna call it.
This is a test.
Cloud gurus.
And then in here we're going to write testing.
And then in here I might want to add a pitcher.
So I'm gonna upload a picture and I'm gonna choose this one.
So this is AWOL this week.
So this is me and Fe.
We have a weekly TV show called AWOL this week.
Now see straight away We've uploaded it and it looks like it's having an issue and what's happening
is a U.R.L. rewrite is writing to cloud front automatically but it's gonna take some time for this image
to propagate through cloud front might take up to 10 minutes.
So I'm gonna go ahead and just publish this post and go ahead and hit publish.
And then what I'm going to do I'm honestly going to go away and make myself a cup of coffee and I'm
going to wait exactly 10 minutes and come back and then do a refresh and you've got to be patient with
cloud front and DNS propagation.
It can just take time submitters just pause the video now.
Okay so I'm just going to refresh the page and there we go.
There's the image coming out of cloud front and you can go ahead and view the post.
You'll be able to see it there and then if we go back to Hello cloud gurus 2019 dot com we can see our
new post there if we grab this image address and paste it into a clipboard you'll see it is definitely
being U.R.L. rewritten to our cloud front distribution.
So we now have a very highly available and fault tolerant Web site.
Let's go ahead and start testing how highly available it is.
Some back in the AWOL management console.
Let's go over to E2 and the first thing we're going to simulate is the loss of an availability zone
and we'll do it of 1 c..
And we're gonna go over to my actions instant state and I'm going to go ahead and hit terminate and
hit terminate.
So you've just lost us West 1 C..
I'm gonna pause and wait for this to actually show as terminated as soon as it's terminated it's going
to start failing to health check.
So let's just pause a video here okay.
That has now terminated so we can see it's in a terminated state if we go down to our Elastic Load balancers
and go to our target groups will be able to see in our targets that we've only now got one registered
target.
If we click on our health checks you can see the reason why is because it's not able to reach that healthy
dot HMO.
And if we go back here and refresh our page we may get some latency but it was like half a second if
that.
So it is still serving our content even though we've lost one availability zone.
We go back to E.C..
It may take some time for auto scaling to figure this out.
Fact if you actually just go over to your auto scaling groups you should be able to look at the events
the activity history and in here we can see that it has detected that something has terminated and is
now bringing up another easy to instance we go over here and have a look.
We now have three running instances and we've got a new Reed node which is initializing and it is in
a completely new availability zone EU West One.
What I'm gonna do is I'm just going to pause the video and wait for this easy to instance to come into
service and the way we can test that is just by going over to our target groups and seeing that this
has been added to our new target in fact that's already been added.
Let's just go over and refresh the page and make sure we're getting the latest version and we definitely
are getting the latest version because we created this post after we took our EMI.
So EMI has already been deployed and it's gone to S3 3 and it's downloaded this asset.
So we definitely have a now a self healing WordPress site.
Okay.
So we're almost at the end of 20 minutes I appreciate you're probably tired to go have a break in the
next lecture what will which tests are D.S. failing over from one availability zone to another.
And then what we'll do is we'll go in and delete the rest of our environment so if you've got the time
please join me in the next lecture.
Thank you.