Monitoring Health

In this lesson, we will find out why to monitor the health of services and how to achieve this using Kubernetes Probes.

Why to Monitor Health?

The go-demo-2 Docker image is designed to fail on the first sign of trouble. In cases like that, there is no need for any health checks. When things go wrong:

  • The main process stops.
  • The container hosting the main process stops as well.
  • Kubernetes restarts the failed container.

However, not all services are designed to fail fast. Even those that are might still benefit from additional health checks. For example, a back-end API can be up and running but, due to a memory leak, serves requests much slower than expected. Such a situation might benefit from a health check that would verify whether the service responds within, for example, two seconds.

Kubernetes Probes

We can exploit Kubernetes liveness and readiness probes for that.

Liveness Probe

livenessProbe can be used to confirm whether a container should be running. If the probe fails, Kubernetes will kill the container and apply restart policy which defaults to Always.

Readiness Probe

We’ll leave readinessProbe for later since it is directly tied to Services.

Instead, we’ll explore livenessProbe. Both are defined in the same way so the experience with one of them can be easily applied to the other.

Understanding the Updated Pod Definition

Let’s take a look at an updated definition of the Pod we used thus far.

Get hands-on with 1200+ tech skills courses.