Kubernetes startupProbe: testing containers for application startup

2 min read | by Jordi Prats

Starting from Kubernetes v1.20 we can configure a startup Probe: It will check for containers to be come into service, disabling liveness and readiness checks until it succeeds.

These startup probes are useful for Pods that have containers that take a long time to be ready. Most people was setting really long liveness intervals to allow the container to start. Using a startup Probe we can set the liveness interval to something that doesn't need to take into account the service startup time.

We can configure the startupProbe for each container on a Pod like so:

startupProbe:
  httpGet:
    path: /health
    port: liveness-port
  failureThreshold: 30
  periodSeconds: 10

Once the startupProbe succeeds, it it right after disabled and the liveness and readiness probes starts doing it's job

Here you can find a full example of a Pod with a startupProbe:

apiVersion: v1
kind: Pod
metadata:
  name: demo-startup-probe
spec:
  containers:
  - image: startupdemo:3.0
    name: startupdemo
    startupProbe:
      failureThreshold: 30
      httpGet:
        path: /api/system/status
        port: http
        scheme: HTTP
      periodSeconds: 10
      successThreshold: 1
      timeoutSeconds: 1

It's important to correctly sed the failureThreshold so that it waits enough time for the container to startup, otherwise we might end up with never-ending restart loop.


Posted on 05/08/2021