305-998-7702 | 415-800-2922 info@rx-m.com

Liveness Probes and Readiness Probes

Learn how to put the latest open source technology into practice with hands-on training, delivered by industry experts, aligned to your desired business outcomes

A liveness probe is a health check that tells a kubelet when to restart a container. Liveness probes help catch locks where an application seems to be running but can not proceed. Implementing a liveness probe in a deployment is a start to making a self-healing application.

An application may not immediately be ready to accept traffic when its container first starts; a readiness probe informs Kubernetes when it is okay to start sending traffic to a container after it boots. For example, a container of a java application might take minutes to load and may not be ready to accept traffic until it’s fully running. In this scenario, the readiness probe mitigates long loading times.

There are three options for liveness and readiness probes:

  • exec – takes a command, an exit code of 0 is success
  • httpGet – performs an http get, a 200-399 status is good
  • tcpSocket – a successful connection to a specified port is success

Liveness and readiness probes are similarly configured for each container in a pod. For example the following pod manifest has an nginx. container with a liveness probe that runs an http get to the root path to port 80. If the nginx web server replies with a 200 – 399 code then the pod is alive. The liveness probe waits 10 seconds before the first check and periodically checks every 20 seconds.

apiVersion: v1
kind: Pod
metadata:
  name: ready-pod
  labels:
    app: ready-pod
spec:
  containers:
  - name: nginx
    image: nginx:latest
    livenessProbe:
      httpGet:
        path: /
        port: 80
      initialDelaySeconds: 10
      periodSeconds: 20

Learn more about Liveness and Readiness Probes.