The container probes are among the basic best practices advised for k8s cluster before going to production. It helps for deploying self probing and resilient services(restart) on Kubernetes.

The different categories under which we can put k8s container probes can be broadly as follows:

  • readiness-probe
  • liveness-probe

1. Readiness Probe

The readiness probe determines when a container can receive traffic.

The kubelet executes the checks and decides if the app is ready to receive traffic or not. Hence the name readiness.

Note: Containers are always ready which is not always desirable.

There’s no default value for readiness and liveness.

If you don’t set the readiness probe, the kubelet assumes that the app is ready to receive traffic as soon as the container starts.

If the container takes 2 minutes to start, all the requests to it will fail for those 2 minutes.

Lets have a quick look at how we applied our config

readinessProbe:
  failureThreshold: 3
  initialDelaySeconds: 5
  periodSeconds: 5
  successThreshold: 1
  tcpSocket:
    port: 80
  timeoutSeconds: 1

Generally we can translate the yaml configuration as the readiness probe waits for 5 seconds on container initializaton and then onwards the probes checks the health of tcp/port 80 of the container on an interval of 5 sec.

Note: Readiness probes runs on the container during its whole lifecycle.

If the probe sends OK response then it is considered healthy. If it ends up in 3 consecutive failure, the container will be considered unhealthy and all traffic to the container will be stopped.

2.The liveness probes

Containers crash when there’s a fatal error

Lets look at a typical liveness probe config yaml:

livenessProbe:
  failureThreshold: 3
  initialDelaySeconds: 15
  periodSeconds: 10
  successThreshold: 1
  tcpSocket:
    port: 80
  timeoutSeconds: 1

If the application reaches an unrecoverable error, you should let it crash

Examples of such unrecoverable errors are:

  • an uncaught exception
  • a typo in the code (for dynamic languages)
  • unable to load a header or dependency

Please note that you should not signal a failing Liveness probe.

Instead, you should immediately exit the process and let the kubelet restart the container.

The liveness probe determines when a container should be restarted.

The kubelet executes the check and decides if the container should be restarted.

For further reads on different types of checks configurable and a deep dive please visit the kubernets official documentation pages.

Resources:

Check out the Jekyll docs for more info on how to get the most out of Jekyll. File all bugs/feature requests at Jekyll’s GitHub repo. If you have questions, you can ask them on Jekyll Talk.