Creating your first Elastic Load Balancer on EC2 in AWS

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys in this video we are going to be walking through creating your first load balancer in amazon web services under the ec2 dashboard and so we've already got one instance running and it's a simple little web server and its job is to say hello my name is blah it's host name when we refer to its ipv4 address it's public ip4 v4 address and we configured our security group such that it allows traffic on http that's for port 80 and so that's what we currently have and so our goal with a load balancer is to if we have a bunch of traffic we want to make sure that we have other ec2 instances present that can also serve requests that are going to our application and so that's where we're going to be making use of uh this thing called an application load balancer within aws so i'm going to keep this tab open just we can see that guy i'm going to go back to our instances dashboard right here and what i'm going to do is i'm going to make some more instances and i'll have three instances in total i'm going to keep these all in the free tier and so the way i'm going to do that is i'm going to go to launch instances and we're going to keep everything exactly the same so we're going to have the amazon linux 2 ami and i'm going to go with the free tier of the t2 family so not changing this we're going to configure our instance details so i want to have two more instances so i'm going to do two right there and i'm going to not change anything on our vpc so these are all going to live within the same vpc that's how our load balancer is going to be able to uh communicate with all three of these guys that we'll eventually have not going to change any of these settings but what i will do is under advanced details of configure instance details i'm going to have a script right here that will do what we did manually through ssh the first time around and i don't want to do this every single time so we're going to see how cool aws is at running this user data parameter so you can just punch in a bash script right here so assuming i don't make any typos we're going to do that i'm going to do so when you run this it's running as the root user so you don't need to worry about sudo su any of that stuff so just literally typing in a bash script yum update dash y to make sure you've got the latest versions of our packages yum install y httpd that's to install our actual apache web service onto the machine system ctl start httpd.service and we need to also enable that and then finally we're going to have it create a file index.html saying my name is and then run a shell command host name f so we can differentiate between our instances that live within our load balancer and this is going to live under var www html index dot html on the local machine so this is going to run once and only once at the first startup of our ac2 instance so it's going to make sure that it's an apache web server that is running and enabled and it has a file where uh it returns the host name when we call it so that's what these steps are doing now we're going to add storage we're going to stick with the 8 gigs of ebs storage that's the network drive that's attached somewhere else so we're not going to really do anything on that add tags um so right now we're going to be creating individual ec2 instances i'll add the tags after those instances get created i'll name them and then we're going to configure our security group and what i've done in the past when we spun up our first web server right here is i created that security group so the cool thing here is that i can take advantage of the fact that i've already created this and i'm just going to click on this guy and we're going to see right here that it's allowing the http and ssh traffic on the correct ports from anywhere which is what we want and now we're going to go to review and launch and uh got that all set up the way we want it and i'm just going to hit launch and uh we're also going to say that this key pair this vs key pair 1 uh is something that i have possession of and that's so that if i ever wanted to manually ssh into these instances once they spin up i can do that uh but right now i'm just going to uh let the aws user data bootstrap script do everything for me which is going to involve installing that apache web service and actually creating this index.html file so now that we've got that running what we can do is we can view instances and we can see that we've got these new guys coming up online and so this first guy right here was uh that 217 ip and we've also got these other two guys so if we click on these instance ids we'll be able to figure out what their ip address is so this guys is that i'm just going to see if we can call it and yeah so that's this is our second instance that's running you can see that they have different uh host names internally inside of our vpc and then we're just gonna check on our third guy so i'm going to name these it makes it a lot easier if you just give them a name call that instance two and then we'll call this guy instance three and uh that just helps us be a little bit more organized and so um i'm also gonna look up the ip on this guy okay there we go so we've got our three instances online we've got our three ipv4 addresses so we basically have three boxes running our web server right now obviously it's a very simple one but we've got our three web servers online and so now what i want to do is i want to actually make it so that we're going to have a load balancer so that our clients are not going to need to know the specific ip address to connect to they just want like a host name like you know google.com or whatever to access our service so now we've got three instances running i'm going to on the ec2 dashboard i'm going to scroll down here and we're going to start out by creating a target group and the target group is basically us specifying exactly which ec2 instances we want to have associated with our load balancer and so in this case i'm going to create one and we're going to target this based on instances and we are going to say vs target group web app just going to name it and we're going to allow health checks so basically what a health check does is it pings this route of our web server which is equivalent to what we did right here which is basically just making sure that we're getting a response from each one of our web servers so your load balancer will be responsible for checking the health of all the uh boxes running in the back end and if it doesn't get a response that means it's unhealthy and it won't send traffic there which is great because we want our service to be as available as it can be and so i'm just going to hit next right here and now we're going to actually spec which instances and we are just going to check all the instances that we've created here and it's going to do that and then we'll click on include as pending and so now what's happening is in aws we've created our target group uh of our ec2 instances got to click on create target group and so now we've got a target group but we don't have our load balancer yet so that's going to be what we do next so that guy's up and running which is great so now we're going to go to load balancers and give it a sec to load here create a load balancer and we're going to go with application load balancer which is probably just for starters the the best one to go with it operates it as they say here it's going to be http and https which is layer 7 and so it can have rules that we'll look at in a little bit but right now what i'm going to do is i'm going to name this so vs alb which stands for apple balancer and this is for web app that we're creating it'll be internet facing which means that we're going to allow anyone to access it uh and then we're going to be using an ipv4 address and not going to be changing any of these guys and um in terms of that we can just select these mappings so we're basically telling it what subnets it's allowed to operate in so i'm just going to go with all them for us east region and then security groups so i want to create a security group specific for our load balancer so i'm going to click on create a new security group and i'm going to call this vs sg or i'll call it alb psg that's the application load balancer security group so uh sec group for app load balancer and what we want to do is we want to make sure that we have configured inbound rules for this so what i want to make sure is that any http traffic on port 80 is allowed to come from anywhere so any ip address is allowed to hit my uh load balancer which is what we want and then we're going to have outbound rules right here and we're literally saying that it's allowed to send traffic anywhere you don't typically really need to modify outbound rules it's mostly the inbound so this is what's going to allow people to talk to our application load bouncer which will sit between our app uh our our clients and our back end three ec2 instances that we have running here so we've got that and now i'm just going to create this security group so we've got our security group created for our application load balancer and now what i'm going to do is i'm going to go back to that other tab we had and i'm going to refresh this and then i should see my application load balancer for that security group so i'm going to attach that policy to it now what i'm going to do is i'm going to say it's allowing traffic on uh port 80 so it's oh sorry so we have to expect which target group our application load balancer will be looking at so we've created that target group which was those three instances and now we're going to create that load balancer and we're going to view our load balancer all right so i know it still says provisioning and i'm very impatient but what we can see here is if we now look at our application load balancer we're going to have its dns name right here which we can copy and if i go here and i paste that in and hit enter it's going to send me to one of the three ec2 instances that it's load balancing for so basically if you were a customer of my web server you would just go to this dns name right here and as we refresh this page we're gonna see how these all have different internal hostnames because we are getting routed to the different web servers that exist right here so we can just keep on refreshing this how much we want but that is how we create our application load balancer in ec2 and we've also made use of bootstrap scripts to make that process a little bit easier and thank you all for watching so hope this helps and i'll talk to you guys next time
Info
Channel: Vincent Stevenson
Views: 5,497
Rating: undefined out of 5
Keywords:
Id: bpfb3bVr8GI
Channel Id: undefined
Length: 12min 54sec (774 seconds)
Published: Sun Apr 03 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.