Now, let's get started step by step.
And let's first of all, create a deployment
and a service for this demo application
so that we can at least reach it.
For that I'll run kubectrl get deployments first
to verify that I have no ongoing deployments.
And then I wanna use the declarative approach
of creating a new deployment and service.
So for that, I'll add a deployment.yaml file
and a service.yaml file.
And we could merge both into one file
if we wanted to of course, as you saw,
but I will split it up
so that it is easier to find the different configurations.
Now you'll learn to syntax,
in the deployment .yeml file.
We first of all, add the apiVersion
and for the deployment, this should be apps/v1.
Now we need to let Kubernetes know which kind
of resource we wanna create.
And we do this with the kind key
and set this to deployment here.
And then we add some metadata
where we give this deployment a name.
This name is up to you and I'll name it, "story-deployment."
But again, this name is totally up to you.
Next we need to add the spec key
to provide the specification of this deployment.
So the configuration of it.
Here we can then for example
specify the number of replicas we want
and I'll start with one.
And then we need to specify the template,
the port template for the ports
that are created by this deployment.
So for the one kind of port that is attached
to the supplement and which can then be replicated
by changing the replica's number.
Now in this template here, we also need a spec.
Now this will set up the specification
40 individual ports, as you learn.
And there, I wanna make it clear which containers
will be part of this port.
And here we have just one container.
So we need one bullet point,
so to say one dash here,
and the name of this container could be, "story"
it's up to you of course,
the image which I wanna use here of course
is the image we'll create with help of that docker file.
And you know that we need to push this to docker hub
in order for it, for it to be available in here
so I will already use my to be created
docker hop repository name
and I will name it 'kub-data-demo."
But of course, this is up to you
and it's depends on how you are going to name
your docker hub repository later.
And with that, we configured this container already.
Now, we're not entirely done
for our port template here, besides the specification.
We also need metadata where we add labels
by which the port can then be selected.
And here you learn,
you can have any key value pairs of your choice.
I will add an app key here and give it a value of "story".
So to same as I used here
as a container name, but you can use a different name.
Now, this matters because on the spec of our deployment
here we also need to add a selector as you learn
and here we can add match labels
and then select by the app key
and look for pods with the value of story for the app label.
And their for of course, the pod from this template
will be selected.
And that's all just something you learned about
in the last course section.
So this shouldn't be anything new.
And if it is definitely make sure you go through
this last course section first.
Now that's the deployment, let's now add a service.
For this here in the serviceyaml file,
we also set up an apiVersion.
However, here it's just v1
And of course we add a kind which should be service.
We should give this service a name
by adding metadata and I'll name it "story-service."
And then we add specification.
So the options for this service
and here, we now define which ports we want to select.
And of course I want to select the ports
created by this deployment.
These ports have an app label with the value of story.
So for a serviceyaml
under a selector we can add this app key here
and then look for a story as a value.
And again, that is something we already covered
in the previous course section.
Now, once that is done, we can define the ports
which should be mapped and exposed.
And here I'll set the protocol to "TCP."
You can also wrap this between quotes
if you want to both works
and then set the port on what you wanna expose it
to, for example, 80 and the targetport
ends up the container to three thousand
because that is the port my container exposes.
So now we've got the service and deployment configurations
created before we apply them,
We need to make sure that this image exists
on Docker hub though.
So, for that on Docker hub,
make sure you create a new repository
and then give it the name you chose here.
So in my case kup-data-demo
and then of course create this repository
with it created, we now need to build and our image.
So for that, we can use a docker build
and use the current folder as a context
because that is where my docker file
and the application source code sits.
And then simply give it a tag of academind/
and then kup-data-demo.
So that name you chose built this image
and there after push it.
So push academind/kub-data-demo.
So now this is pushed to Docker hub
and they for should be found here.
You could of course also give it a tag, a version number
to ensure that always this specific version is fetched
but these are all things I already talked about
in the last course section.
So I won't dive into that again here.
Instead now this was pushed and therefore of course
we can apply our service and our deployment.
So for that of course your Minikube virtual machine
needs to be up and running.
You can check this with minikube status,
and if you don't have the bunch of running there,
you can restart it with minikube start.
And then by adding a driver as explained
in the last course section
and once it is up and running,
we can run cubectrl apply-f
and apply to service.yaml file.
And also the deployment.yaml file.
And this will create a service and the deployment.
And by doing that, if we then run, get deployments
we should see that we have one deployment up
and running and it should be ready.
Now we can try reaching that deployment
by running minikube service.
And then the name of the service we chose here
story-service, and this will expose that service.
However, of course it fails
because I forgot one important thing.
We need to use a type here.
Of course besides specifying the ports,
we should add a type to the service.yaml file
and set this to LoadBalancer.
My mistake of course, this needs to be added
otherwise it's by default just exposed internally
in the cluster and not reachable from outside,
which is what we need here though.
So make sure you add this type
then simply reapply it by running
kubectrl apply-F=serviceyaml we don't need
to reapply the deployment.
We just need to update the service.
And with that done run minikube service story-service again
and now this gives you a URL
which you can use to reach your application.
And now we can use that here in Postman,
use this URL/story and send a get request
and you should get back a valid response.
Of course, without any data initially,
we can also use it to send a post request like this
with some dummy data added and that should work.
And if we then get this again,
we of course see our data here.
And that means that of course, it's working
now, let's dig into the problems
and then the solution, which of course are volumes.