AWS EC2 Auto Scaling : Step By Step Tutorial ( Part - 10)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
in this session we are going to take a look onto the ec2 auto scaling groups as the name suggests autoscaling which means it is going to Auto scale or autocreate the ec2 instances into our AWS environment let's try to compare the two approaches so here onto the screen you can see one is traditional setup without Auto scaling and here on the right hand side you can see the ec2 auto scaling setup so let's first take a look onto the traditional uh setup where we don't have a auto scaling so here on the top you will see a load balancer and that load balancer will route the request to our VPC and then it will go into the subnet and where we are provisioning our ec2 instances so in the uh traditional way when we don't have Auto scaling so request will come to the load balancer and that request will be routed to the VPC and then it will eventually end up onto our subnet where our ec2 instances are running so in traditional setup what we do we just predefine the number of ec2 instances so here you can see there are three instances which is is running so let's consider a case where you are having only few number of requests coming to your uh application so it doesn't make a sense to run three CPU onto the cloud environment because there is only three requests few requests coming to your uh uh ec2 instances so you just need to run only one uh ec2 instance which is sufficient enough to catter those requests but instead you are running the three instances so what will happen is it you will pay a cost for running two extra instances into your AWS environment and that's not an ideal scenario but when you compare with the autoscaling group so here what it does it just let you it just gives you the flexibility to create in more instances and reduce the instances based on the traffic or CPU uses or memory uses so what you do uh you just create a Autos scaling group where you define the mean Max and desired number and these are configurable numbers so you can put like like 10 also 20 also it's up to you and how heavy your application is so you just create autoscaling group and in that autoscaling group you just configure these values and so that uh it knows like how many CPU it needs to or how many e to instance it needs to provision uh to C those requests so that's the difference between the traditional and the ec2 auto scaling group and the benefit we get out of this Autos scaling group is that you reduce quite a lot of cost because generally what happens is like uh let's take a normal scenario where uh requests are coming in a daytime but during the night there are very few requests because everyone is sleeping so in that scenario you can reduce the count of a CPU running onto your AWS environment and that's where the autoscaling group can help you all right so let's start implementing this Auto scaling group uh onto our AWS console so this is our Target architecture but let's break it down and start with our first block so first of all we need to create the VPC so let's go back to our AWS console over here and here just type in the VPC click on the VPC click on create VPC select VPC only here just type the name test VPC here you need to enter the range of your IP addresses so I'm just going to put this one and rest of the details I'm just going to keep default and I'm just going to click on create VPC and if you go back over here then here you can see the test VPC has been created after we create the VPC the next thing which we need to create is the internet gateway so again go back to your AWS console and here on the left hand side you will find the option for internet gateway so click on internet gateway uh create internet gateway and here you can enter the name so I'm just going to copy the name from my notepad and paste it over here so click on create internet gateway so name is internet gateway test so all the resources which I'm just going to create I'm just going to add a name test so that we can can identify these resources I'm just going to click on create internet gateway and also we need to attach this internet gateway with our VPC so here in the action section you can find the attached to VPC and here select and here you can choose the test VPC so select test VPC and attach to internet gway so now we have created the VPC we have created the internet gway and we have also attached the internet gateway to our VPC all right so let's take a look onto the diagram once again so now we have a VPC we have internet gateway the next thing which we need to create is the subnet so again go back to your console and here uh on the left hand side into the VPC dashboard you will find an option for a subnet so click on subnets over here and here you need to click on create subnet and first of all since we are doing everything inside our VPC so this subnet is also going to be created inside the VPC so first of all let's from the drop- down select the test VPC which we have just created and here we need to enter the name so in the diagram allthough so I have created only single subnet because uh I I didn't find much place to explain this concept but in actual we we are going to create a two subnet and those are going to be the public subnet present inside the VPC okay so let's get back to our uh browser or the console and here I'm just going to paste the name of my Subnet so I'm just going to paste the name which is test public subnet 1 a and the availability zone I'm just going to choose Europe Central 1A that's why I have suffixed it with the 1 a then we need to define the IP ranges so I'm just going to put the IP ranges here so 12.0.1 do0 /24 so we'll have a 256 IPS available inside the subnet and again I'm just going to add a one more subnet so that we have a maximum availability that's why I'm just creating multiple subnet and that's really important for you also so I'm just going to copy the name once again and I'm just going to paste it over here and I'm just going to change it to 1B uh select the availability Zone to Central 1B and here we need to assign the IP range so I'm just going to Define over here so again here we have a 256 but the IP range is 12.03 and previously in the previous subnet we have a 12.0.1 do0 so that's the basic difference between these two subnet and after that you can just click on create subnet all right so now uh we have created the VP see internet gateway and then subnet the next thing which we need to create is the route tables so here on the left hand side you will find the option for Route tables click on create route tables and here I'm just going to put the name uh route table test public so I'm just going to create a a public route table for it and again everything we are doing into the VPC so I'm just from the drop down I'm just going to select test VPC and uh I think that's it and click on create route table over here and the route table has been created but this route table is not associated with the subnet yet so what you need to do you need to go on to subnet Association over here click on edit subnets and here you can attach the subnets which we have just created in the previous step so select both the public subnet over here save the association all right now uh our route table has been associated with our subnet but this route table is also responsible for providing the internet access and that we for that we need to create a route so here uh in the route section uh there is edit routes so click on edit routes and here click add routes so here we need to enter the IP so this IP 0.0.0 which means uh we can uh this particular route table or this or any resource associated with route table can be accessed via internet so all the public subnet resources will have access to Internet okay that's been done so here click on on from the drop down internet gateway because internet gateway is responsible for providing the internet access so here we need to choose the internet gway which we have created previously so that is internet gateway test I'm just going to select that one and after that we are just going to click save changes all right so now we have created the route tables also all right let's take a look onto the diagram once again so we have created these many resources so far so the next resource which we need to create is the target group so remember in the subnet we will be creating the ec2 instances and those ec2 instances will be a part of a Target group so that when we will create a load balancer so load balancer will point to the Target group and this target group will point to the ec2 instances so this is how it's going to work so now we will create a Target group but this target group will be empty as of now because we are not going to create any ec2 instances yet that will be created using the Autos scale policy see but let's focus on this target group first so let's go back to our AWS console and go to home and here uh type ec2 over here click on ec2 and on the left navigation uh in the load balancing section click on the target groups over here and here you can see there is no target group so what we need to do is we need to create a Target group all right so the target group is uh so Target group is responsible for pointing the ec2 instances so I'm just going to choose the instances over here and here we need to put the name so I'm just going to put Target ec2 Apache uh because we are going to install Apache server inside our ec2 instance that's why I'm just going to put the Apache 2 and after that I'm just going to keep the things protocol as Port 80 that should be fine uh VPC we need to change we need to switch it to the test VPC because we are working inside the test VPC protocol http1 that's fine health checks I'm just going to keep everything as a default and then click next and here you can see available instances so there are no instances which has been created yet those instances will be created by Autos scale policy and then we are going to come back and take a look over here but as of now there is no instances running so we are just creating a blank Target group over here all right so now just click on create Target group over here okay so now we have created the target group and the load balancer you can see none Associated so there is no load balancer associated with this target group yet so we are just going to create that load balancer also all right so let's revisit the diagram once again and see what the next resource we need to create so the next resource we need to create is the we need to create a load balancer so again go back to your uh console over here so here we have created the target group and this target group you can already see it is not associated with the load balancer so now uh we need to create a load balancer so from the left hand navigation menu click on the load balancers uh click on create load balancer and here we need to choose the load balancer since we are working with the E2 instance instances so I'm just going to choose application load balancer so click on create name so I'm just going to put ALB ec2 uh instances then with uh autoscaling group okay so this is the name which I'm putting internet facing yes I want internet facing VPC we need to select the VPC so I'm just going to choose the test VPC select both the subnets over here further Security Group so this is important so whenever we create a application load balancer then we need to have an access from internet so for that we need to enable the HTTP Port 80 for that particular load balancer and here you can see this Security Group is only default one so we need to create a one more security group so that this application load balancer can be accessed from internet so I'm just going to click on create new Security Group over here and uh ALB uh Security Group uh for HTTP as well as I'm just going to enable the SS not s such but I'm just going to stick with HTTP requests and I'm just going to type allow uh HTTP request over here and again here we need to choose the VPC because we are working in a test VPC so I'm just going to select test VPC over here add a rule over here choose uh HTTP over here Port is 8 that's fine Source I should put 0000 0 so that it is accessible from everywhere okay and after that I'm just going to click create Security Group okay so this Security Group has been created I'm just going to copy this name I'm just going to close this window and here I'm just going to refresh this one and here here you can see ALB Security Group for HTTP request so I just need to add that one also over here okay so now in the uh application load balancer we have put the name we have selected the test VPC we have selected the subnets we have selected the security groups in The Listener and routing so as you can see in the diagram uh we have already created this Target group and now we are creating the application load balancer but this load balancer needs to point to the Target group so this is where I'm doing it so in the listener and routing select the target group and here you will find the target Group which we have created previously so I just select that one go further on and just check the summary over here so this is the summary for our application load balancer which is internet facing ip4 here these are the security group default and the one which I have created for to allow HTTP request VPC we are into the test VPC and these are the subnet and this is our Target group so which is pretty much uh this setup we are just trying to verify over here this is load balancer Target group subnet VPC so these everything are in place right now so okay I'll go back to console and after that I'm just going to click create load balancer okay so it has created the load balancer so if you go to the load balancer dashboard so it is provisioning so state is provisioning right now so whenever you create a load balancer so it might take a couple of minute to provision the whole load balancer so just wait for a while so I'll be back when this provisioning uh of this load balancer has been completed all right so after a couple of minute my load balancer is now into our active state so let's let's get back to our Target diagram and see what next resource which we need to create so after creating the application load balancer the next thing which we need to create is the auto scaling group so this autoscaling group will also contain the template which I'm just going to show to you but let's get back to our console first of all so in the left navigation menu just below the load balancing you will find a section for auto scaling so click on autoscaling group over here create autoscaling group and here we need to enter the name of our autoscaling but before that let's take a look onto the diagram once again so once we create a autoscaling group then it is going to ask you like what kind of a easy to inst you need to create so for that we need to use the launch template so the launch template is basically a primary configuration where you specify that what kind of ec2 instance you want to provision or you want to set up so this will contain primary like a t2. micro uh what the CPU type uh your uh Ami whether you are going to use Ubuntu Santo red red hat your security groups also and also you can specify uh the uh public public IP address do you want to assign the public IP address or not so these are some few details uh which you can specify into the launch template and then this autoscaling group is going to use the launch template to create the ec2 instances but this mean Max and desired numbers are not part of a launch template but this is a part of autoscaling group so what happens is autoscaling group reads the launch template it knows like what kind of ec2 instance it needs to create and how many ec2 instance it needs to create for that purpose it will read these parameter that is mean Max and desire all right so let's get back to our AWS console and let's continue with our Autos scaling group all right so here is the autoscaling group so first of all let's assign the name for auto scaling group so Auto scaling group ec2 instances uh test demo and here you will find option for a launch template so I have already created one launch template but for this demo let's create a fresh one so click on this link below so this is the link which I have clicked to create a new launch template so here uh I'll just put the name LT and then ec2 instances Apache 2 all right so after that uh assigning the name to the template let's go ahead choose the Ami uh I'm just going to choose uban 2 because I want to have uban 2 inside my ec2 machine so select that one that's been done uh instance type I'm just going to select t2. micro after that key pair just select the key pair if you have already created otherwise you can create a new one from here in the network setting we need to select the subnet so I'm just going to select the test public subnet over here security groups so this is important because we are creating ec2 instances and for those ec2 instances to serve the request we need to enable the port at T so that we can serve the HTTP request and for that we need to create create that security group and also we need for SSH purpose we need to enable the port 2020 22 also so that we can SSH into those ec2 instances all right so what I'll do I just need to create the uh Service Group for that so let's go to the VPC section go to uh security groups over here click security groups uh create create Security Group so here I'm just going to put uh like a launch template security group ec2 instances Apache 2 all right and allow SSH and HTTP requests so this is just a description I'm just going to put over here in the VPC we need to enter the VPC where we are working so we are working into the test VPC so select that one add rule so here I'm just going to choose first of all HTTP port and allow everyone so I'm just going to choose this IP add one more Rule and add SSH over here allow everyone and after that click on create Security Group okay so now we have created the security group just copy this name go to this launch template once again and here we need to assign that Security Group over here okay so that we have assigned okay so here uh I have assigned the security group and subnet it is complaining for so I'm just going to select some other subnet which is available okay so I'm just going to select this one uh remove subnet for ec2 autoscaling template so we don't need to select any subnet so I'm just going to not going to include anything over here that's okay uh let's go ahead Auto assign public IV so the we need to enable this one also so let's check once again so we don't need to include subnet uh we just need to include the security group to allow HTTP request over here and SSH that's also mandatory after that I'm just going to stick with the storage volume so 8 gigs that's fine resource tank I'm just going to skip it it's just optional thing so in the advanced detail we need to install the Apache and we need to have some custom HTML page so that it can show the host IP okay so for that purpose I'm just going to use this script which I have already copied into my notepad so this is the script which is going to update the package then it is going to install the Apache and here it is going to update the content of a HTML 5 which is going to print the host name and if you don't know what is user data then I have already uploaded the session for this user data section so just go and check into the playlist so that will help you to understand like how you can write the script which can be useful when you're bootstrapping or when you're starting your ec2 instance so that whenever you start an ec2 instance so these packages will always be installed okay so that's been done uh so I'm just going to click on create launch template over here and go to launch template and here you can see uh our launch template has been created okay all right so let's get back to our uh autoscaling group so we have assigned only the name now we need to uh select the launch template which we have just created so just refresh this one and here you will see the launch template so LT ec2 instances apach to that's thech template which we have created and here is the version since uh this is the fresh template that's why the version is one only if you have modified that template then you might get a different version so just select the proper version or the latest version in case you are modifying the existing one so that's a just a quick note for you all right so rest of the details are quite okay I'm just click on next and here the launch template is this here the VPC we need to change and we need to change it to the test VPC because we are working inside the test VPC the availability zone I'm just going to select both of it over here click next now here it will ask like the load balancing so if you go back to our Target diagram once again so here we already created this load balancer and this load balancer is already targeting attached to this target group so we need to select the load balancer for this autoscaling group so here go back to this attached existing load balancer choose from uh your load balancer Target groups so we already created this target group if you remember this blue uh boundary so this is our Target group so that we have already created so we just need to select that one so here you can see this is the target Group which we have created after that uh VPC latice integration just keep the things default we don't need to change it turn elastic load balancing health check so we just need to enable that one so that it can do the health checks for our ec2 instances health check grace period 300 seconds since we are doing it for demo purpose so I'm just going to keep it to 20 second but just change it if you want to have some other uh health check grace period for your ec2 instance okay so click on next so here these are the uh things which where we specify like what's the capacity mean Max and the desired so if you see over here so mean Max and desired so I'm just going to desired into two uh minimum one and maximum I'm just going to create three scaling uh so I'm just going to keep it none but in case if you're interested into further more then you can just uh Define some policies so what it will do so based on the CPU uses so if CPU usage is more than 70% 80% then also you can increase the uh uh ec2 provisioning so that will create more ec2 instances for you but just for this demo I'm just going to keep it none and after that click next uh do you want to add any notification no I don't want to add any notification click next attacks are also optional so click next and after that you just need to click on create autoscaling group and here you can see uh our autoscaling group has been created now the key thing is uh it is updating the capacity so as as you create autoscaling group it will automatically start creating those ec2 instances based on the uh desired capacity so here the desired capacity which we have specified is two so it will automatically provision the two ec2 instances for us so let's verify whether it has provision it has provisioned or it is provisioning the ec2 instances or not so click on the new tab and go to ec2 over here and click on instances running so here you can see two and here you can can see uh the two instances has been started both are in running State and status check is initializing so as you can see uh like when we created this autoscaling policy if you take a DI uh take a look onto the diagram so when we created this autoscaling group then it started provisioning those ec2 instances into our subnet and these ec2 instances are created based on this numbers like what numbers we have configured so we have configured two as a desired numbers that that's why we are seeing these two ec2 instances has been created over here so I'm just going to refresh it so it will take like a couple of minute more to properly initialize everything and then we are just going to verify from our load balancer okay so here you can see our E2 instances has been initialized properly and this uh status check is passed so let's go back to our load balancer so from the loow left navigation menu click on the load balancers and click on this load balancer and here just copy this DNS and go to new tab and enter the so here you can see we are able to access it I'm just going to zoom in so that you can see the details so here you can see the server detail and the IP address is 12 03127 and if I refreshes then it is going to change to 1247 and if you go to our ec2 instances then you we can verify the IP address which is the P private so here you can see 3.17 it is ending with I'm just going to refresh it once so one request is going to 3. 127 and the other other instances this one so which is uh 1. 245 so I'm just going to refresh it once again so here you can see 1 1245 so as you can see our load balancer is now routing the request to the ec2 instances properly so let's check few more things like how the auto scaling works so here in the auto scaling Target group here you can see uh the instance management here you can see both are into healthy state right now and uh we are able to access that also so now what we are going to do we are just going to manually forcefully terminate one of the instance then how the auto scalings behave it is going to provision another instance also for us so that we get the maximum availability okay so let's go to Let's close everything first of all and I'm just going to close this one also let's go back to ec2 so I'm just going to open two tabs so this is our ec2 dashboard here two instances are running and I'm also going to open the target group Target group go to Target group and uh yeah so health check yeah this is going good Target so yeah here you can see the both status are healthy so now what we are going to do I'm just going to terminate one of the instance over here so terminate instance terminate so as soon as you start terminating the instance I'm just going to remove the running filter over here also so soon it is going to start provisioning uh one more ec2 instance because uh in this target Group Policy if you'll see uh sorry in the auto scaling group we have set the desired capacity to be two so if one instance is down then it is going to provision in another instance so here you can see uh into the target group I'm sorry it's a launch template I just don't want to go into the launch template but I'm just going to go into the autoscaling group click on the autoscaling group and instance management so here you can see just refresh this one it will take some some time to uh see the changes I'll be back in a minute I think it will take a one or 2 minute to uh update the status over here so I'll be back and I'll show you those new instances all right so after a minute as you can see the one instance has been terminated and new instance is into pending state so it's already started provisioning uh one more instance for us so in the health section also if I refresh this one so here you can see one is unhealthy because we have terminated manually and now it has started provisioning in another instance so this is how the autoscaling works so whenever you define an autoscaling group for your ec2 instances so it will just act based on the counts which you have set up into the desired mean and Max so if you terminate if any of the application is unhealth then it is going to provision a new instance for us and then this is how we are just going to scale the requests which are coming to our ec2 instances from a load balancer so with that we conclude our Autos scaling session and if you like this content then I have also uh created a channel membership program for you guys so if you're interested into the more indepth level concept on AWS or any other devops topic then I have some other session which are specifically created for channel members so you can just uh be a member of this channel so you can check those uh like a behind the scene or more in-depth lab session and if you're interested into the similar content for future then consider subscribing to this channel because I have planned many of the similar session in the upcoming week and you will see similar topics onto my channel and also just check the description section where I have posted various course links like terraform Docker kubernetes Helm chart and previous uh there are many more lab session I have created for Jen kins also so so just go and check those courses also which will really help you to uh gain more insights into the devops so see you into the next session of a devops till then take care and bye-bye
Info
Channel: Rahul Wagh
Views: 13,406
Rating: undefined out of 5
Keywords: aws, ec2, ec2 auto scaling, auto scaling, devops, cloud
Id: fwfkSxb1T-s
Channel Id: undefined
Length: 30min 50sec (1850 seconds)
Published: Thu Oct 19 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.