AWS CodeDeploy Blue / Green Deployment to Amazon ECS

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi guys this lesson should be a lot of fun we're going to do a lab on AWS code deploy and we're going to deploy to Amazon ECS so this is going to be the configuration we're going to have an application load balancer we'll have e CS with a Fargate cluster and a service and in that service will be one task it shows two here but we'll just do one and the alb will be directing traffic to that task in a target group called tg1 so that will be our first target group then we'll upload an app spec Tom will file to Amazon s3 and I'll show you what that is shortly and then code deploy will actually obtain that file and with the instructions it will coordinate the deployment with ECS and the alb it will then launch a task in the second target group and then it will start shifting traffic across and removing the connection to target group 1 and then finally will actually take down those tasks as well so that's the way it looks should be good to build this out let's go over to the console and get started first thing i need to do on in iam is creative role and this is going to be a role for code deploy so we create role we choose code deploy here choose code deploy - ECS because what we were going to do is give code deploy the rights to talk to s free lambda s and s and ECS and also application load balancing now we won't be using a lambda function or s and s but we do need the others so we choose that click on next it should find the policy for you and if we have a look into the JSON we can see we're getting rights here for ECS elastic load balancing and s free those are the key ones that we need so let's choose next choose review and we'll call this e CS code deploy roll and click on create roll the next thing we need to do is copy up our app spec yeah Mille to s free so let's have a look at what app Spector Emal's on now we're gonna use this simple one here but first I want to show you some examples for ECS see 2 and lambda so this one here describes some resources with a task definition and a container and then there's some optional properties and then the key thing I want you to understand is the hooks so this is describing the actions that take place at certain intervals or at certain stages of the deployment so in this case for ECS its before install after install after allow test traffic before allow traffic and then after allow traffic now these are different for the different delivery types so here we have the hooks for ec2 and you've got before install after install application start and validate service and then for lambda we've got before allow traffic and after an hour traffic now you do need to know these for the exam because they do come up in questions so I'm gonna consolidate the information that you need to know on the training notes on our website and so have a look there and just get a good understanding of what's actually taking place at these different stages so for now we just need this simple app spec yeah Mille all it does is describe the resources which are going to be an e CS service a task definition so you need to modify this you need to put your AR n for your task definition in here you can easily get that by going to ECS go to task definitions find my sample app that we created earlier click on the app go to JSON and you can find the AR in here so just copy that paste it into your task definition AR in here make sure your container name is correct in this case it's my - sample - app and the port is 80 so you'll find this app spectrum or encode code deploy app spec yeah more so that's in the course download let's go back to s free and we're going to upload our file I'm going to choose app spec ml these are the examples I just showed you so you can have a look at those just upload we've got a success so that's great I'm now gonna go and create my load balancer so in ec2 I'm on load balancers I'm going to create an application load balancer just gonna call it my a lb listener is going to be port 80 I'm gonna put it in the default subnet make sure excuse me the default VPC and make sure you're careful which VPC you put it in because you've got to make sure your service is going to be in the same V PC I'm just going to attach it to all a Z's in public subnets I'm going to choose web access I just need to pour Daisy for this one and a full target group I'm going to create at one called TG one change here to IP everything else can stay the same I'm going to just go through next and create that's our target group created we can now go to ECS clusters and I've got a Fargate cluster if you don't just choose networking the only power by AWS Fargate next give it a name and choose create so in my Fargate cluster I'm going to create a service I'm going to choose faregates choose my sample app call this blue green we'll just have one task and now I want to choose a Bluegreen deployment and you'll see it finds the service role for code deploy choose next disabled service discovery integration you don't need to know that for this exam cluster VPC is going to be the same as the load balancer so default I'm going to change my security group it's a web access again port 80 oh yeah I need to connect my subnets I'm going to put this in all the public subnets that's all good and auto assign public IP is enabled and now we're going to choose our load balancer so choose application load balancer it's found the load balancer name and we now need to add the container to the load balancer so it's found my sample app let's choose add for production listener port choose 80 curl on HTTP it should be there for you I'm going to disable test listener I'm going to choose target group one TG one and for target group two I'm just going to backspace that name out and call it TG two everything else looks correct we've got HTTP health checks just a slash let's choose next we don't need to auto scaling and that's everything let's choose create servus so it's creating the target group has created the service and it's also created our code deploy application so let's go to code deploy refresh applications and it's created an application for us so in developer tools code deploy applications if you want to you can create your own application here you just have to choose the compute platform because then the options for the deployments are different in this case it would be ECS but we have one that's already created so let's use that we go into the application and then we have a deployment group so we'll go in there in a second I want to show you how to create one manually as well so here you would give it a name you would choose your role your ECS cluster the load balancer and then you would choose the target group one and target group two and then you have the options for how to reroute traffic so remember we've got linear and Canary so and then all at once so linear is where you have a increment in this case ten percent and then an interval in this case one minute and so every one minute it will shift ten percent of traffic where as canary will be 10 percent five minute interval and then the rest of the traffic so make sure you remember that for the exam we're just going to cancel out because we have a deployment group already so in our deployment group everything looks like it's set up correctly for us we now do create deployment and we're going to choose the location of our s free app spec Tamil file so I'm going to go to s free app spec tamil copy path come back paste that in change to dot Yama and then you could then override the deployment configuration here for traffic shifting we're going to leave it as it is you can also change what happens when rollbacks occur we're just going to choose create deployment now I just want to set a couple of things up before I do that to show you what's going on so at the moment we have target group one we have a healthy instance so if we go to ECS tasks we have this time running if I get the public IP we should find that we can connect to that and we should also be able to connect it out from the load balancer so let's click to the DNS name here and we can connect to our application that way as well so let's just keep on this screen here target groups now you can see that traffic is only going to tg1 because it's the only one that's attached to the load balancer and it's the only one that has any targets in it there are no targets in cg2 so let's go back to code deploy click on create deployment you'll now see a deployment status screen that shows you that the deployment is in progress and you can see on the right here that you've got the traffic shifting as well so at the moment 100% of the traffic is in the original task set so back on the diagram this is the stage we're at we still have all our traffic onto target group one code deploys picked up the app spec yeah Mille and it's now coordinating the deployment so it's going to launch these instances then it's going to start directing traffic and then it will stop traffic going to the other target group and then finally remove those tasks so let's go back and see what's going on let's go to ECS we now have two tasks running so the second task has been spun up we go to target groups here we'll see we still have all traffic down to target group one but we now have an unused target in target group two so that would just take a few more minutes so that didn't take too long we can now see that we have completed the deployment and the rerouting so let's go back over to our target group click on refresh and sure enough we see that that jumped over so now all traffic's going to target group two and we have our tasks there which is in an initial status and that should very quickly become healthy and back in ECS if we click on refresh here we still have both tasks running because remember we're now at this point where we have the old tasks still running but traffic has been directed to our new tasks now back in code deploy you can see that it's in a waiting state so it's going to wait one hour before terminating the original tasks set but we can expedite that by terminating the original tasks set by clicking this button here and that will then immediately remove the tasks from the original tasks set so let's go back over to ECS and click on refresh and it's still running but very quickly we should find that it gets terminated and there we go the original task is now gone and we have the new task which is running in our second target group so that's it for this lab guys I hope you enjoyed that now what we could do is obviously build this in to a pipeline so we could put this in a pipeline with code commit code build and then through the deployment we're not going to do that in this lab but in the next lab we're going to use AWS code star which will be a more enter end solution now in terms of cleaning up you can go up to your application level here go into your application and then just choose delete application and delete we can then go to our load balancer and delete our load balancer and then go to ECS and we can go into our cluster and just delete our service and that's all the resources that are going to cost anything you might also want to go and clean up your target groups so you can just go in and select each one and delete and that's everything gone see you in the next lab guys
Info
Channel: Digital Cloud Training
Views: 13,456
Rating: undefined out of 5
Keywords: AWS, AWS Certification, Amazon Web Services, AWS Amazon, AWS Certified, AWS Training, AWS tutorial for beginners, AWS tutorial, AWS tutorials, AWS cloud tutorial, Amazon AWS, Amazon tutorial series, Amazon AWS tutorials, AWS Certified Cloud, New AWS Content, how to get certified, free aws, free aws videos, free aws tutorials, AWS Cloud, AWS Exam, Amazon Application Load Balancer, ALB, Amazon Elastic Container Service, ECS, AWS CodeDeploy, AWS Developer, Certified Developer
Id: ekh2uW1VU6U
Channel Id: undefined
Length: 12min 30sec (750 seconds)
Published: Wed Mar 11 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.