With that we're almost done
with these very basics about Kubernetes
and resources with Kubernetes.
There's one a little bit more advanced concept,
which I wanna touch on right now.
And that is related to how Kubernetes
checks whether your pods and containers,
and the pods are healthy or not,
because this can matter in certain applications.
Up to this point,
it always works the way it seems to do it by default
but you can of course configure how it should do that.
And for this deployment Yami file,
I will actually go to my container definition
to change how this container is checked by the pod
to see whether it's up and running.
And we can change this
by adding a so called liveness probe key.
And again, you find this
in your official documentation as well.
If you have a look at the deployment,
the deploymentSpec
they are at the template and the podSpec
there if you dive into the container array,
you find that for containers,
you can configure a lot of things.
For example, all the environment variables
which can become important later
also how the image should be pulled
and here you also find the liveness probe key.
So, how can we configure this?
Well, there you can add a httpGet key,
and of course there are more options,
which you can learn about if you dive
into that probe definition
or simply into the official docs.
If you search for kubernetes liveness probe,
here you find more information and documentation,
but here we can simply define
that a Gethttp request should be sent
by the pod to the running application so to say,
or by Kubernetes to the running application.
We wanna send it to a path of just slash,
but of course that could be another nested path
your application might have,
on port 8080 in our container,
since that's the port this container exposes
maybe with some extra Headers,
but we don't need some here so we can omit this.
And then, on the same level as httpGet
not nested inside of it,
you add the periodSeconds value
where you define how often that should be performed.
For example, all three seconds or 10 seconds,
whatever you want.
In addition, you can add to the initial DelaySeconds key,
where you can tell Kubernetes how long it should wait
until it checks the health for the first time,
for example, five seconds.
And now we've got our own liveness probe in action,
where we define how Kubernetes should verify
whether that container is up and running.
And if I now save this
I can of course again apply the deployment.yaml file
and service.yaml file.
And if you then run minikube service backend
we again get our URL to the deployed application.
Here it is.
But if I now visit slash error
it of course crashed, but it's opens immediately
up and running again because that crash was detected
and the container and the pod was restarted
as you can see if you get your pods.
you see it was restarted once here.
Now that is something which worked before as well.
I will say that,
but it still works with our own liveness probe
and defining such a liveness probe can be very useful
if you have an application
which doesn't react to the default,
or if you simply want to check the health
by sending a request to slash something
instead of just slash.
So knowing how that can be defined can be very helpful
to ensure that your applications work
no matter how they are structured or configured.