Now besides making changes easily,
you can also merge multiple files into one easily.
For example here, you could of course
argue that this service
is closely related with this deployment
and having multiple files could be what you want.
It can have advantages.
For example, it's clear where the service is defined.
But you could also argue that you wanna have one file
with all the related things in it.
So we could add a new file, maybe master-deployment.yaml.
The filename is up to you of course.
And then you could grab the content
from the deployment.yaml file and move it in here.
And you can move another resource definition
into the same file.
You can have as many resource definitions
in one of the same file as you want.
So in this case the service.yaml configuration,
I copy that and go to master-deployment
and I add it above my deployment config here
and the only thing you need as a separator
is these three dashes.
And it must be three dashes.
Not two, not four. It must be three
because this is a YAML-specific syntax
which basically means a brand new object starts thereafter.
So you have these three dashes
between all your resource definitions
and you can then have as many resource definitions
in this file as you want.
As a little side note,
if you combine a service and a deployment
in one of the same file,
it is a good practice to put the service first
so that this resource is created first
because resources are created from top to bottom
because since it has the selector,
it will then dynamically add any parts
which are created thereafter.
It would also work in the other order,
but that is considered to be a better practice.
And as a side note, it is really important
to keep in mind that these objects
are living organisms in the cluster.
When a service is created,
it's not created and analyzed once,
but it continuously monitors all the parts
which are created and removed in your application
and if a new part is created
which matches this label selector,
it will be added to this service.
That's why creating it first is no problem here,
but is instead recommended.
Well and with that let's actually
delete our deployed resources
and then apply this merged file.
Now to delete something we can simply run delete -f
and point at the files we wanna delete
so here deployment.yaml and then another -f command
to also delete what was created
because of the service.yaml file like this.
And now you see the respective deployment
and service was deleted.
And then we can simply apply this one single file
with this command here
so Q+Control apply -f equals master-deployment.yaml
and now both the service and the deployment
is created simultaneously.
Now I just wanna expose the service again
by running minikube service backend.
Something we need to do
in this local development environment
and then again it's this URL
which you can use to view your running application.
And that's how you can merge multiple files together
into one file.