We've now got a little bit of starter code for all service rather than developing the auto service out.
Let's immediately start to set up some different Cuban NATO's infrastructure stuff so we can start to
run the service in incumbent parties immediately which is going to make our lives a bit easier than
if we were going to develop the whole service and then come back later and start to set up the community
stuff.
So anytime that we start to set up Cuban cities we need a couple of different things.
We first need to make sure that we can build an image out of our service in order to build an image.
Remember we have to write out a docker file so inside my off directory I'm going to make a new file
called Docker file then inside this file we're gonna write out a couple of different steps very similar
to the ones that we wrote out a little bit ago on our last project.
So at the very top I'll do from node Alpine.
We will set up a working directory of slash app.
We will copy over just our package dot Jason File.
We will then install all of our dependencies with run npm install will then copy over everything else
from our project directory into that app folder and then finally we can set up our command to run with
the image or the container first starts up.
We'll do a command of NPM start like so I'm going to save that file and close it.
Now remember we don't really want to load up node modules into our container as it's being built so
I'm going to create another file inside this auth directory called Dot Docker.
Ignore an inside of Docker ignore.
I will list out node modules and then save the file.
So we've now got some config put together for off.
I'm gonna go back over to my terminal and just try to build this image very quickly.
Just make sure that yeah we can run it and everything looks reasonable so back at my terminal I'm going
to stop the server that we're currently running.
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
a period at the very end.
All right.
So looks like I've copy over the package not just on file.
I'm doing a little bit of installation and so after a brief second or so I should see the thing kick
back out.
Yep looks like it's all installed and I've successfully built the image.
Well that's a good start.
Now we're going to start to put together a little bit more configuration to get that image loaded up
into our communities cluster to get that image running.
We're going to create.
Remember it is called a deployment a deployment is going to create a set of pods for us automatically
and we can make sure that those pods are running our off service so to write out a Cuban 80s config
file.
I'm going to take the same strategy that we used in the last project.
I'm going to create a new folder inside this directory called infra short for infrastructure.
I'll make a new folder inside there called K and then inside that folder I'll make a new file called
off dash devil dot yellow so inside this file we're going to create our off deployment.
That's why we have the depot on there.
It is just short for deployment then inside of here.
We're going to write out a bunch of configuration that looks identical to what we just did a little
bit ago on our last project so at the very top we'll do API version of apps flash V1.
We're gonna set a kind of deployment all set metadata with a name of off dash devil
Well then start to write out a spec inside of here we're going to first designate the number of pods
that we want to run or the off service I want replicas of one.
I just want to run one copy of that image right now.
Well then set up a selector with match labels and app of off.
Remember this is step one in a little two step process.
This the purpose of this selector right here is going to be to tell the deployment how to find all the
pods that it's going to create after setting up that selector will then set up the template.
And so this template right here is how to create each individual pod that this deployment is going to
create first set up our metadata in here with labels of app colon off.
So again this selector right here is kind of matching up with a label that we set right there.
Then on the same indentation level as metadata we'll set up our actual spec.
So this is going to tell the pod how to behave we're gonna first designate all the containers that are
going to be running inside the spot.
We're gonna have one entry inside this array so I'll put in a little dash right there to indicate an
array entry.
I'm gonna give the container a name of off.
And remember this name right here is only important for logging purposes.
We're going to set the image to use which will be your Docker I.D. flash off the name of the image that
we just put together two seconds ago and that should be enough to get us started so there's our deployment.
Now remember anytime we create deployment we usually are going to want end up creating a service to
go along with it.
This is a Cuban any service.
Something to give us access or allow us to get access to a pod.
We could create a separate file inside of our case directory to house the service but all of the time
we're going to end up with a 1 to 1 ratio between our deployments and the services.
So I personally like to just to find a service inside the same file this deployment so that all this
stuff is put together in one single location so let's define a service at the very bottom the file at
the very bottom done here I'll put in that dash dash dash and we'll write out our config for our service
we'll put an API version of the one in this case a kind of service or metadata.
I'll set up a name of off dash Savi
then our spec to tell the service how to behave so we will put on that selector which is going to tell
this service how to find the set of pods that is supposed to govern access to we want to find all the
pods with the label of app colon off does the selector.
I will put an app colon off like so will then list out all the different ports that we want to expose
on that pod.
We only have one port that we really care about right now.
It's going to put in name of off a protocol of DCP and then we can set up our ports.
Should not be a colon at the end there.
A port of three thousand and a target port of three thousand as well.
So we're using three thousand.
In this case because remember our off implementation.
We put together in the last video we had it listening on port three thousand okay.
So it looks good.
You'll notice that in the spec section I did not find a type for the service.
We are relying upon the defaults.
The default service whenever recreate or one is a cluster IP service.
You might recall that a cluster IP service is going to allow communication to the service from anything
else running only inside of our cluster but this looks like a good place to get started.
We'll save this right here.
This video is running a little bit long so we'll take a quick pause but when we come back the next video
we're going to start to write out a scaffold config file.
Remember the goal of scaffold is to find all the different things that we want to throw into our cluster
build them up and then throw them in and also handle some live code reload for any changes that we make
to our off project as well so quick pause and we'll start to set up scaffold in just a moment.