We just spoke about the four different types of services.
We're not going to try to create our own service.
We're going to first focus on creating a node port.
Remember in the last video I said that we're not going to use a node port very often unless we are doing
it for just development purposes.
So why are we making a node port first if it's not what we're going to use very often.
Well it's really simple a cluster IP is used to network different pods together.
Right now we have only one odd.
So if we start to create a cluster IP service.
Well it's not really gonna do anything because we're not really exposing our pod to any other pods.
We don't have any other pods.
Why are we not creating a load balancer a load balancer usually requires a decent amount of additional
configuration.
So right now the easiest service to create and the one that actually does something for right now we're
actually has some effect on our cluster is a node port.
That's why we're gonna create that first.
Now all these different services are types of objects.
Remember a deployment a pod a service.
These are all referred to as objects and Cuban eddies all objects we creates are made by first creating
a config file and then applying that config file to our cluster.
So whenever we talk about creating a service or modifying a service we are always talking about creating
a config file.
So let's get to it back inside my editor.
I'm going to find that key aides directory and inside there I'll make a new file I'll post dash s r
v dot yellow SRB stands for service inside of here we're going to write out some config that looks very
similar to the config we wrote inside that deployment file and the pod file previously.
So we will first begin with an API version of the one a kind of service a metadata that has name of
posts dash SRB the name right here is going to be the name of the service.
So if we ever try to print out all the services that are running inside of our cluster we will see post
dash as Harvey will then define our spec which is going to customize how this service actually behaves.
The first thing we'll do is designate a type of node port as you guess that's going to be the type of
service that we are trying to create.
We are trying to make a node port service after that.
We're going to put down a selector with an app of posts like so.
So what is this selector thing all about.
Well remember the entire goal of a node Port is to expose a set of pods to the outside world.
This service right here this node port service needs to know about what pause it should actually expose.
And that's the goal of that selector thing.
Remember a selector right here of outposts.
We did something very similar to this back inside of our deployment file.
So let's go back over to deployment very quickly.
So inside of here we have that template section and the template is describing how all these different
pods should be created by the deployment inside the templates.
We had a metadata with the labels of app posts.
So this label right here is applying a label or some kind of designation of sorts an identifier of sorts
to the pod that is going to be created.
So by writing a selector of app post right here we are telling the service to try to find all the different
pods with a label of app posts and expose traffic or expose those pods to the outside world this whole
label system in general.
You can really think of this as being very similar to class names that get applied to an HMO element
in the browser.
So if you're familiar with HDL Well we apply class names to elements so we can select a broad range
or a set of elements very easily.
You should really think of this entire label and selector system as being very similar in nature.
Next up we're going to designate some ports.
So this port section is going to list out all the different ports that we want to expose on the target
pod.
Well let me give you a quick reminder on the Postal Service really quickly or a postal application inside
of our postal application directory.
I can open up the index dot J.S. file at the very bottom.
You'll recall that we had said app listen on port four thousand right there.
So our application nation is listening for traffic on port four thousand inside of our service.
We need to make sure that we specifically expose port 4000 on our part.
So that's what this ports section is all about.
We're going to list out all the different ports that we want to expose on the part now sports is going
to be an array of entries.
And remember we set up a rate entry in Yemen by putting in that little dash right there.
We'll say dash then name of those a protocol of DCP a port of 4000 and a target port of 4000.
I got some bad news.
These port properties right here are pretty darn confusing.
I'm not going to lie with you.
So what are these all about.
Well again if we think about our post application it is listening for traffic on port four thousand.
So this 4000 right here is essentially saying we want to open up access on Port 4000.
But real quick question why are we listening this out twice.
What is the difference between Port and target ports.
Let me show you a diagram.
I'm going to tell you right away.
This diagram is probably going to make things a little bit more confusing so bear with me for just a
second.
All right.
Here's our diagram on the right hand side is our node.
Remember the node is the actual kind of virtual machine that is running all of our Cuban eddies objects
on the left hand side is our browser on the far right hand side is the actual pod that is running our
post container.
Now on that container we've got some application that is listening for traffic on port four thousand.
We refer to that ports that is attach the container.
So the ultimate port that we want to direct traffic to as the target port so target port.
Back over here.
This is the actual port that our application is listening for traffic on.
That's where we ultimately want to send traffic to.
We are creating a node port service the node port service is going to have a port of its own.
So that is referred to as simply the port.
And that is what this property is right here so we are sending traffic to port 4000 on a node port service
and that service internally is going to redirect that traffic over to Port 4000 on the container itself
the port and the target port do not have to be identical.
So this could be 5000 right here.
And if we make a request to work 5000 on the no port service the service will redirect that traffic
to port 4000.
On the container.
Now are there scenarios in which we would want to have a different port in a different target port.
Maybe I'm kind of hard pressed to think of one off the top of my head.
So usually Bassim during the time you're going to have a port and a target port that are just identical.
That's the long and short of it.
So at the end the day this whole section right here you can pretty much copy paste between all your
different services that you are creating and just change that actual number to be whatever your actual
application is listening for traffic on.
So for example if we were creating a service where our comments application.
No comments right here.
If we open up that index not just file that application is listening for traffic on four thousand one.
So if we were creating a service for comments we would pretty much copy paste the same thing right here
and just change that to four thousand one the name on here of posts is really just for logging purposes
and having some name attached to it.
The name can be anything you want it to be.
So we could change that to whatever no big difference.
Well usually just name it after the service.
No big difference OK.
So that is our service has been completed.
Now you might notice back on Instagram over here I had this additional port right here.
We'll talk about that in just a moment.
This video is running a little bit long.
So let's take a quick pause right here and we're going to apply this config file to our cluster in just
a moment to actually create the service.