We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

Liveness Probes

Because Kubernetes is all about building self-healing systems, it automatically restarts a container when it crashes.

But what if the app doesn't actually crash? A program can get stuck in a deadlock or an infinite loop, or just stop responding. Sure, technically the process is still running, so Kubernetes won't restart it, but the app is effectively dead.

A liveness probe fixes that. The kubelet periodically checks on the container, and if the check fails too many times in a row, it restarts the container.

The most common probe is a simple HTTP request. Most web servers have an endpoint just for this, conventionally at /healthz, that returns a 200 OK status code if the server has started up successfully and is listening for traffic. SynergyChat's API has one:

containers:
  - name: synergychat-api
    image: bootdotdev/synergychat-api:latest
    livenessProbe:
      httpGet:
        path: /healthz
        port: 8080
      periodSeconds: 5
      failureThreshold: 3
  • httpGet: Send a GET request to this path and port. Any status code from 200 to 399 is a success.

  • periodSeconds: How often to check, in seconds (default 10)

  • failureThreshold: How many failures in a row before Kubernetes restarts the container (default 3)

Assignment

Add a liveness probe to the API, then break it on purpose.

Submit the shell checks.