Monitoring Health

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 following things happen:

  • 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 services that are designed to fail might still benefit from additional health checks. For example, a back-end API can be up and running but, serves requests much slower than expected due to a memory leak. Such a situation might benefit from a health check that would verify whether the service responds within, for example, two seconds.

Kubernetes probes

To monitor health, we can exploit Kubernetes liveness and readiness probes.

Liveness probe

livenessProbe can be used to confirm whether a container should be running. If the probe fails, Kubernetes will terminate the container and apply a 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 look at an updated definition of the Pod we have used thus so far:

Get hands-on with 1200+ tech skills courses.