1 00:00:01,230 --> 00:00:03,630 We just spoke about the four different types of services. 2 00:00:03,690 --> 00:00:05,690 We're not going to try to create our own service. 3 00:00:05,700 --> 00:00:08,320 We're going to first focus on creating a node port. 4 00:00:08,340 --> 00:00:12,720 Remember in the last video I said that we're not going to use a node port very often unless we are doing 5 00:00:12,720 --> 00:00:14,520 it for just development purposes. 6 00:00:14,550 --> 00:00:18,540 So why are we making a node port first if it's not what we're going to use very often. 7 00:00:18,540 --> 00:00:23,090 Well it's really simple a cluster IP is used to network different pods together. 8 00:00:23,100 --> 00:00:25,410 Right now we have only one odd. 9 00:00:25,590 --> 00:00:27,450 So if we start to create a cluster IP service. 10 00:00:27,450 --> 00:00:32,530 Well it's not really gonna do anything because we're not really exposing our pod to any other pods. 11 00:00:32,560 --> 00:00:34,430 We don't have any other pods. 12 00:00:34,470 --> 00:00:38,700 Why are we not creating a load balancer a load balancer usually requires a decent amount of additional 13 00:00:38,700 --> 00:00:39,980 configuration. 14 00:00:40,110 --> 00:00:44,220 So right now the easiest service to create and the one that actually does something for right now we're 15 00:00:44,220 --> 00:00:46,950 actually has some effect on our cluster is a node port. 16 00:00:46,950 --> 00:00:49,120 That's why we're gonna create that first. 17 00:00:49,280 --> 00:00:52,290 Now all these different services are types of objects. 18 00:00:52,290 --> 00:00:55,210 Remember a deployment a pod a service. 19 00:00:55,230 --> 00:01:00,840 These are all referred to as objects and Cuban eddies all objects we creates are made by first creating 20 00:01:00,870 --> 00:01:04,280 a config file and then applying that config file to our cluster. 21 00:01:04,380 --> 00:01:09,390 So whenever we talk about creating a service or modifying a service we are always talking about creating 22 00:01:09,450 --> 00:01:10,600 a config file. 23 00:01:10,710 --> 00:01:14,130 So let's get to it back inside my editor. 24 00:01:14,130 --> 00:01:19,330 I'm going to find that key aides directory and inside there I'll make a new file I'll post dash s r 25 00:01:19,340 --> 00:01:26,490 v dot yellow SRB stands for service inside of here we're going to write out some config that looks very 26 00:01:26,490 --> 00:01:31,320 similar to the config we wrote inside that deployment file and the pod file previously. 27 00:01:31,320 --> 00:01:40,830 So we will first begin with an API version of the one a kind of service a metadata that has name of 28 00:01:40,830 --> 00:01:45,360 posts dash SRB the name right here is going to be the name of the service. 29 00:01:45,360 --> 00:01:49,670 So if we ever try to print out all the services that are running inside of our cluster we will see post 30 00:01:49,670 --> 00:01:58,130 dash as Harvey will then define our spec which is going to customize how this service actually behaves. 31 00:01:58,160 --> 00:02:04,070 The first thing we'll do is designate a type of node port as you guess that's going to be the type of 32 00:02:04,070 --> 00:02:05,270 service that we are trying to create. 33 00:02:05,300 --> 00:02:09,050 We are trying to make a node port service after that. 34 00:02:09,060 --> 00:02:14,510 We're going to put down a selector with an app of posts like so. 35 00:02:14,580 --> 00:02:16,980 So what is this selector thing all about. 36 00:02:16,980 --> 00:02:25,220 Well remember the entire goal of a node Port is to expose a set of pods to the outside world. 37 00:02:25,250 --> 00:02:30,890 This service right here this node port service needs to know about what pause it should actually expose. 38 00:02:31,100 --> 00:02:33,570 And that's the goal of that selector thing. 39 00:02:33,620 --> 00:02:35,980 Remember a selector right here of outposts. 40 00:02:35,990 --> 00:02:39,090 We did something very similar to this back inside of our deployment file. 41 00:02:39,410 --> 00:02:41,980 So let's go back over to deployment very quickly. 42 00:02:42,220 --> 00:02:46,730 So inside of here we have that template section and the template is describing how all these different 43 00:02:46,730 --> 00:02:50,480 pods should be created by the deployment inside the templates. 44 00:02:50,480 --> 00:02:54,110 We had a metadata with the labels of app posts. 45 00:02:54,470 --> 00:02:59,780 So this label right here is applying a label or some kind of designation of sorts an identifier of sorts 46 00:03:00,020 --> 00:03:02,420 to the pod that is going to be created. 47 00:03:02,450 --> 00:03:08,450 So by writing a selector of app post right here we are telling the service to try to find all the different 48 00:03:08,450 --> 00:03:16,460 pods with a label of app posts and expose traffic or expose those pods to the outside world this whole 49 00:03:16,520 --> 00:03:17,800 label system in general. 50 00:03:17,810 --> 00:03:23,480 You can really think of this as being very similar to class names that get applied to an HMO element 51 00:03:23,510 --> 00:03:24,590 in the browser. 52 00:03:24,590 --> 00:03:30,200 So if you're familiar with HDL Well we apply class names to elements so we can select a broad range 53 00:03:30,230 --> 00:03:32,480 or a set of elements very easily. 54 00:03:32,480 --> 00:03:39,550 You should really think of this entire label and selector system as being very similar in nature. 55 00:03:39,550 --> 00:03:41,940 Next up we're going to designate some ports. 56 00:03:42,730 --> 00:03:46,930 So this port section is going to list out all the different ports that we want to expose on the target 57 00:03:46,930 --> 00:03:48,010 pod. 58 00:03:48,010 --> 00:03:52,750 Well let me give you a quick reminder on the Postal Service really quickly or a postal application inside 59 00:03:52,750 --> 00:03:54,380 of our postal application directory. 60 00:03:54,420 --> 00:03:58,380 I can open up the index dot J.S. file at the very bottom. 61 00:03:58,390 --> 00:04:03,040 You'll recall that we had said app listen on port four thousand right there. 62 00:04:03,040 --> 00:04:08,590 So our application nation is listening for traffic on port four thousand inside of our service. 63 00:04:08,600 --> 00:04:14,080 We need to make sure that we specifically expose port 4000 on our part. 64 00:04:14,180 --> 00:04:16,370 So that's what this ports section is all about. 65 00:04:16,370 --> 00:04:22,390 We're going to list out all the different ports that we want to expose on the part now sports is going 66 00:04:22,390 --> 00:04:23,490 to be an array of entries. 67 00:04:23,500 --> 00:04:28,090 And remember we set up a rate entry in Yemen by putting in that little dash right there. 68 00:04:28,240 --> 00:04:42,040 We'll say dash then name of those a protocol of DCP a port of 4000 and a target port of 4000. 69 00:04:42,210 --> 00:04:43,560 I got some bad news. 70 00:04:43,680 --> 00:04:47,490 These port properties right here are pretty darn confusing. 71 00:04:47,520 --> 00:04:48,390 I'm not going to lie with you. 72 00:04:49,230 --> 00:04:50,610 So what are these all about. 73 00:04:50,610 --> 00:04:55,820 Well again if we think about our post application it is listening for traffic on port four thousand. 74 00:04:55,870 --> 00:05:01,680 So this 4000 right here is essentially saying we want to open up access on Port 4000. 75 00:05:01,770 --> 00:05:05,100 But real quick question why are we listening this out twice. 76 00:05:05,100 --> 00:05:07,640 What is the difference between Port and target ports. 77 00:05:07,650 --> 00:05:08,760 Let me show you a diagram. 78 00:05:08,780 --> 00:05:09,800 I'm going to tell you right away. 79 00:05:09,810 --> 00:05:14,730 This diagram is probably going to make things a little bit more confusing so bear with me for just a 80 00:05:14,730 --> 00:05:15,490 second. 81 00:05:17,280 --> 00:05:17,630 All right. 82 00:05:17,640 --> 00:05:21,280 Here's our diagram on the right hand side is our node. 83 00:05:21,280 --> 00:05:26,650 Remember the node is the actual kind of virtual machine that is running all of our Cuban eddies objects 84 00:05:27,270 --> 00:05:33,410 on the left hand side is our browser on the far right hand side is the actual pod that is running our 85 00:05:33,410 --> 00:05:34,970 post container. 86 00:05:34,970 --> 00:05:39,620 Now on that container we've got some application that is listening for traffic on port four thousand. 87 00:05:40,280 --> 00:05:43,520 We refer to that ports that is attach the container. 88 00:05:43,520 --> 00:05:49,180 So the ultimate port that we want to direct traffic to as the target port so target port. 89 00:05:49,250 --> 00:05:50,240 Back over here. 90 00:05:50,240 --> 00:05:53,620 This is the actual port that our application is listening for traffic on. 91 00:05:53,630 --> 00:05:57,780 That's where we ultimately want to send traffic to. 92 00:05:57,960 --> 00:06:03,300 We are creating a node port service the node port service is going to have a port of its own. 93 00:06:04,080 --> 00:06:06,390 So that is referred to as simply the port. 94 00:06:06,480 --> 00:06:13,510 And that is what this property is right here so we are sending traffic to port 4000 on a node port service 95 00:06:13,960 --> 00:06:19,900 and that service internally is going to redirect that traffic over to Port 4000 on the container itself 96 00:06:20,850 --> 00:06:23,600 the port and the target port do not have to be identical. 97 00:06:23,610 --> 00:06:25,230 So this could be 5000 right here. 98 00:06:25,290 --> 00:06:30,900 And if we make a request to work 5000 on the no port service the service will redirect that traffic 99 00:06:30,900 --> 00:06:31,880 to port 4000. 100 00:06:31,880 --> 00:06:33,020 On the container. 101 00:06:33,180 --> 00:06:37,360 Now are there scenarios in which we would want to have a different port in a different target port. 102 00:06:37,620 --> 00:06:40,900 Maybe I'm kind of hard pressed to think of one off the top of my head. 103 00:06:41,010 --> 00:06:47,380 So usually Bassim during the time you're going to have a port and a target port that are just identical. 104 00:06:47,420 --> 00:06:48,480 That's the long and short of it. 105 00:06:49,190 --> 00:06:54,350 So at the end the day this whole section right here you can pretty much copy paste between all your 106 00:06:54,350 --> 00:07:00,140 different services that you are creating and just change that actual number to be whatever your actual 107 00:07:00,140 --> 00:07:01,730 application is listening for traffic on. 108 00:07:01,730 --> 00:07:05,440 So for example if we were creating a service where our comments application. 109 00:07:05,440 --> 00:07:06,410 No comments right here. 110 00:07:07,220 --> 00:07:12,350 If we open up that index not just file that application is listening for traffic on four thousand one. 111 00:07:12,380 --> 00:07:17,210 So if we were creating a service for comments we would pretty much copy paste the same thing right here 112 00:07:17,600 --> 00:07:25,180 and just change that to four thousand one the name on here of posts is really just for logging purposes 113 00:07:25,270 --> 00:07:26,990 and having some name attached to it. 114 00:07:27,130 --> 00:07:28,570 The name can be anything you want it to be. 115 00:07:28,600 --> 00:07:31,460 So we could change that to whatever no big difference. 116 00:07:31,460 --> 00:07:33,520 Well usually just name it after the service. 117 00:07:33,520 --> 00:07:36,370 No big difference OK. 118 00:07:36,410 --> 00:07:39,630 So that is our service has been completed. 119 00:07:39,630 --> 00:07:43,290 Now you might notice back on Instagram over here I had this additional port right here. 120 00:07:43,320 --> 00:07:45,120 We'll talk about that in just a moment. 121 00:07:45,120 --> 00:07:46,460 This video is running a little bit long. 122 00:07:46,470 --> 00:07:50,520 So let's take a quick pause right here and we're going to apply this config file to our cluster in just 123 00:07:50,520 --> 00:07:52,110 a moment to actually create the service.