1 00:00:01,210 --> 00:00:06,220 We've now got a little bit of starter code for all service rather than developing the auto service out. 2 00:00:06,220 --> 00:00:10,690 Let's immediately start to set up some different Cuban NATO's infrastructure stuff so we can start to 3 00:00:10,690 --> 00:00:14,890 run the service in incumbent parties immediately which is going to make our lives a bit easier than 4 00:00:14,890 --> 00:00:19,600 if we were going to develop the whole service and then come back later and start to set up the community 5 00:00:19,600 --> 00:00:19,990 stuff. 6 00:00:20,710 --> 00:00:24,100 So anytime that we start to set up Cuban cities we need a couple of different things. 7 00:00:24,100 --> 00:00:29,290 We first need to make sure that we can build an image out of our service in order to build an image. 8 00:00:29,290 --> 00:00:34,930 Remember we have to write out a docker file so inside my off directory I'm going to make a new file 9 00:00:34,930 --> 00:00:41,630 called Docker file then inside this file we're gonna write out a couple of different steps very similar 10 00:00:41,630 --> 00:00:45,720 to the ones that we wrote out a little bit ago on our last project. 11 00:00:45,750 --> 00:00:50,800 So at the very top I'll do from node Alpine. 12 00:00:50,920 --> 00:00:54,650 We will set up a working directory of slash app. 13 00:00:54,770 --> 00:00:59,890 We will copy over just our package dot Jason File. 14 00:01:00,050 --> 00:01:07,700 We will then install all of our dependencies with run npm install will then copy over everything else 15 00:01:07,790 --> 00:01:14,450 from our project directory into that app folder and then finally we can set up our command to run with 16 00:01:14,470 --> 00:01:16,700 the image or the container first starts up. 17 00:01:16,750 --> 00:01:26,850 We'll do a command of NPM start like so I'm going to save that file and close it. 18 00:01:26,860 --> 00:01:33,530 Now remember we don't really want to load up node modules into our container as it's being built so 19 00:01:33,530 --> 00:01:38,420 I'm going to create another file inside this auth directory called Dot Docker. 20 00:01:38,420 --> 00:01:42,000 Ignore an inside of Docker ignore. 21 00:01:42,100 --> 00:01:50,300 I will list out node modules and then save the file. 22 00:01:50,370 --> 00:01:53,070 So we've now got some config put together for off. 23 00:01:53,070 --> 00:01:56,270 I'm gonna go back over to my terminal and just try to build this image very quickly. 24 00:01:56,280 --> 00:02:02,430 Just make sure that yeah we can run it and everything looks reasonable so back at my terminal I'm going 25 00:02:02,430 --> 00:02:05,810 to stop the server that we're currently running. 26 00:02:05,870 --> 00:02:15,850 Then do a docker build dash t my Docker I.D. slash I'm going to cut this thing off and then don't forget 27 00:02:15,850 --> 00:02:17,140 a period at the very end. 28 00:02:19,150 --> 00:02:19,470 All right. 29 00:02:19,480 --> 00:02:21,850 So looks like I've copy over the package not just on file. 30 00:02:21,850 --> 00:02:27,530 I'm doing a little bit of installation and so after a brief second or so I should see the thing kick 31 00:02:27,550 --> 00:02:28,790 back out. 32 00:02:28,850 --> 00:02:34,040 Yep looks like it's all installed and I've successfully built the image. 33 00:02:34,070 --> 00:02:35,560 Well that's a good start. 34 00:02:35,570 --> 00:02:40,460 Now we're going to start to put together a little bit more configuration to get that image loaded up 35 00:02:40,490 --> 00:02:44,070 into our communities cluster to get that image running. 36 00:02:44,070 --> 00:02:44,790 We're going to create. 37 00:02:44,790 --> 00:02:49,500 Remember it is called a deployment a deployment is going to create a set of pods for us automatically 38 00:02:49,830 --> 00:02:55,910 and we can make sure that those pods are running our off service so to write out a Cuban 80s config 39 00:02:55,910 --> 00:02:56,440 file. 40 00:02:56,480 --> 00:02:59,680 I'm going to take the same strategy that we used in the last project. 41 00:02:59,860 --> 00:03:06,450 I'm going to create a new folder inside this directory called infra short for infrastructure. 42 00:03:06,500 --> 00:03:12,200 I'll make a new folder inside there called K and then inside that folder I'll make a new file called 43 00:03:13,070 --> 00:03:19,970 off dash devil dot yellow so inside this file we're going to create our off deployment. 44 00:03:20,020 --> 00:03:21,510 That's why we have the depot on there. 45 00:03:21,510 --> 00:03:25,300 It is just short for deployment then inside of here. 46 00:03:25,310 --> 00:03:29,540 We're going to write out a bunch of configuration that looks identical to what we just did a little 47 00:03:29,540 --> 00:03:38,640 bit ago on our last project so at the very top we'll do API version of apps flash V1. 48 00:03:38,790 --> 00:03:46,730 We're gonna set a kind of deployment all set metadata with a name of off dash devil 49 00:03:50,270 --> 00:03:55,240 Well then start to write out a spec inside of here we're going to first designate the number of pods 50 00:03:55,240 --> 00:04:02,280 that we want to run or the off service I want replicas of one. 51 00:04:02,350 --> 00:04:06,740 I just want to run one copy of that image right now. 52 00:04:06,790 --> 00:04:13,880 Well then set up a selector with match labels and app of off. 53 00:04:13,900 --> 00:04:17,740 Remember this is step one in a little two step process. 54 00:04:17,740 --> 00:04:21,910 This the purpose of this selector right here is going to be to tell the deployment how to find all the 55 00:04:21,910 --> 00:04:28,210 pods that it's going to create after setting up that selector will then set up the template. 56 00:04:28,280 --> 00:04:32,930 And so this template right here is how to create each individual pod that this deployment is going to 57 00:04:32,930 --> 00:04:41,340 create first set up our metadata in here with labels of app colon off. 58 00:04:41,360 --> 00:04:46,100 So again this selector right here is kind of matching up with a label that we set right there. 59 00:04:48,660 --> 00:04:54,020 Then on the same indentation level as metadata we'll set up our actual spec. 60 00:04:54,090 --> 00:05:00,530 So this is going to tell the pod how to behave we're gonna first designate all the containers that are 61 00:05:00,530 --> 00:05:02,760 going to be running inside the spot. 62 00:05:02,900 --> 00:05:07,490 We're gonna have one entry inside this array so I'll put in a little dash right there to indicate an 63 00:05:07,490 --> 00:05:08,870 array entry. 64 00:05:09,060 --> 00:05:11,200 I'm gonna give the container a name of off. 65 00:05:11,250 --> 00:05:16,810 And remember this name right here is only important for logging purposes. 66 00:05:16,870 --> 00:05:24,810 We're going to set the image to use which will be your Docker I.D. flash off the name of the image that 67 00:05:24,810 --> 00:05:33,980 we just put together two seconds ago and that should be enough to get us started so there's our deployment. 68 00:05:34,020 --> 00:05:38,340 Now remember anytime we create deployment we usually are going to want end up creating a service to 69 00:05:38,340 --> 00:05:39,530 go along with it. 70 00:05:39,540 --> 00:05:41,310 This is a Cuban any service. 71 00:05:41,310 --> 00:05:45,490 Something to give us access or allow us to get access to a pod. 72 00:05:45,690 --> 00:05:50,640 We could create a separate file inside of our case directory to house the service but all of the time 73 00:05:50,670 --> 00:05:55,240 we're going to end up with a 1 to 1 ratio between our deployments and the services. 74 00:05:55,260 --> 00:06:00,150 So I personally like to just to find a service inside the same file this deployment so that all this 75 00:06:00,150 --> 00:06:08,640 stuff is put together in one single location so let's define a service at the very bottom the file at 76 00:06:08,640 --> 00:06:13,950 the very bottom done here I'll put in that dash dash dash and we'll write out our config for our service 77 00:06:15,160 --> 00:06:23,340 we'll put an API version of the one in this case a kind of service or metadata. 78 00:06:23,370 --> 00:06:26,010 I'll set up a name of off dash Savi 79 00:06:29,890 --> 00:06:35,780 then our spec to tell the service how to behave so we will put on that selector which is going to tell 80 00:06:35,840 --> 00:06:41,390 this service how to find the set of pods that is supposed to govern access to we want to find all the 81 00:06:41,390 --> 00:06:46,570 pods with the label of app colon off does the selector. 82 00:06:46,570 --> 00:06:53,650 I will put an app colon off like so will then list out all the different ports that we want to expose 83 00:06:53,650 --> 00:06:54,870 on that pod. 84 00:06:55,030 --> 00:06:57,990 We only have one port that we really care about right now. 85 00:06:58,170 --> 00:07:07,310 It's going to put in name of off a protocol of DCP and then we can set up our ports. 86 00:07:07,440 --> 00:07:09,480 Should not be a colon at the end there. 87 00:07:09,600 --> 00:07:13,830 A port of three thousand and a target port of three thousand as well. 88 00:07:14,490 --> 00:07:15,650 So we're using three thousand. 89 00:07:15,650 --> 00:07:19,610 In this case because remember our off implementation. 90 00:07:19,620 --> 00:07:25,670 We put together in the last video we had it listening on port three thousand okay. 91 00:07:25,710 --> 00:07:26,880 So it looks good. 92 00:07:26,880 --> 00:07:30,970 You'll notice that in the spec section I did not find a type for the service. 93 00:07:31,090 --> 00:07:32,960 We are relying upon the defaults. 94 00:07:33,000 --> 00:07:37,210 The default service whenever recreate or one is a cluster IP service. 95 00:07:37,290 --> 00:07:42,360 You might recall that a cluster IP service is going to allow communication to the service from anything 96 00:07:42,390 --> 00:07:48,870 else running only inside of our cluster but this looks like a good place to get started. 97 00:07:48,990 --> 00:07:50,370 We'll save this right here. 98 00:07:50,370 --> 00:07:55,020 This video is running a little bit long so we'll take a quick pause but when we come back the next video 99 00:07:55,290 --> 00:07:58,620 we're going to start to write out a scaffold config file. 100 00:07:58,620 --> 00:08:03,660 Remember the goal of scaffold is to find all the different things that we want to throw into our cluster 101 00:08:04,560 --> 00:08:09,600 build them up and then throw them in and also handle some live code reload for any changes that we make 102 00:08:09,600 --> 00:08:14,490 to our off project as well so quick pause and we'll start to set up scaffold in just a moment.