Monitoring Container Health in Kubernetes

Gaurav Kaushik
4 min readMay 16, 2021

Kubernetes provides a number of features that allow users to build robust solutions, such as the ability to automatically restart unhealthy containers. To make the most of these features, K8s needs to be able to accurately determine the status of user applications.
This means actively monitoring Container Health.

Health Checks are a good way to let the K8s system know if an instance of the application is working or not. The other containers or services should not send requests or try to access a container which is in a bad state. The system should also be able to bring the app back to healthy state.

By default, K8s restarts a container as it crashes. Also, it starts sending traffic to a pod when it is notified that all the containers inside the pod are started.
User can make their deployments more robust by creating custom health checks. Kubernetes allows creation of certain probes to keep the system in a healthy state.
Lets discuss these probes in detail here:

  1. Liveness Probes: Liveness Probes allows the user to automatically determine whether or not a container application is in its healthy state.
    By default, Kubernetes will only consider to be ‘down’ if the container process stops.

    Liveness Probes allow the user to customize this detection mechanism & make it more sophisticated.
  2. Startup Probes: Startup Probes are very similar to the Liveness Probes. However, while Liveness probes run constantly on a schedule, startup probes run at container startup & stop running once they succeed.

    They are used to estimate when the application has actually successfully started up. Startup Probes are useful for legacy applications that usually have longer startup times.
  3. Readiness Probes: Readiness Probes checks whether a container is ready to accept requests. When the user have a service backed by several container endpoints, user traffic will not be sent to a particular pod until all the containers have passed the readiness checks defined by their Readiness probes.
    Readiness Probes are used to prevent user traffic from being sent to pods that are still in the process of starting up.

Lets get into hands on details while exploring the probes:

  1. Login to the Control Plane node and create an ‘exec’ type pod that will execute a simple command. If the command executes successfully, then this means that the pod is in a healthy state otherwise not:
Pod in a healthy state after 5 seconds

2. Lets create another pod with ‘http’ type Liveness probe which will respond to https requests:

Pod is ready

3. Lets create a pod with Startup Probe now:

failureThershold value waits for the application to startup. This is kept greater so as to make sure that slow applications are started up properly.

4. Last, lets create a pod with Readiness probe:

This probe determines when your application is actually ready to serve user traffic.
STATUS shows that the Pod is in ‘Running’ state, but it is READY which determines when the pod is ready to respond to user traffic.

This was pretty much how Kubernetes takes care of Container Health in any compute infrastructure.

The above three probes are actually an important factor while considering deploying an application at scale. How efficiently the containers will serve the response to user requests in real time is of high importance & business critical.
Having proper value(s) in the probes makes the application agile & faster to respond to errors.

In the next post we will learn about how the pods heal themselves in an error condition.

Thank You!

--

--