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