DEV Community

Cover image for Deployment using all three Kubernetes probes
Diya
Diya

Posted on

Deployment using all three Kubernetes probes

Full Example YAML

Here’s a deployment using all three Kubernetes probes:

containers:
  - name: api
    image: my-api:latest

    startupProbe:
      httpGet:
        path: /readyz
        port: 5000
      failureThreshold: 20
      periodSeconds: 15

    readinessProbe:
      httpGet:
        path: /readyz
        port: 5000
      initialDelaySeconds: 5
      periodSeconds: 10
      failureThreshold: 3

    livenessProbe:
      httpGet:
        path: /healthz
        port: 5000
      initialDelaySeconds: 30
      periodSeconds: 20
      failureThreshold: 3
Enter fullscreen mode Exit fullscreen mode

Now let’s break down what Kubernetes is actually doing here.


startupProbe

startupProbe:
  httpGet:
    path: /readyz
    port: 5000
  failureThreshold: 20
  periodSeconds: 15
Enter fullscreen mode Exit fullscreen mode

This tells Kubernetes:

Check /readyz every 15 seconds.
Allow 20 failures before killing the container.
Enter fullscreen mode Exit fullscreen mode

Calculation:

15 seconds × 20 failures = 300 seconds
Enter fullscreen mode Exit fullscreen mode

So Kubernetes gives the application:

5 minutes to fully start
Enter fullscreen mode Exit fullscreen mode

before deciding:

“The application failed to start.”

Default Values

If not specified, Kubernetes uses:

periodSeconds: 10
timeoutSeconds: 1
failureThreshold: 3
successThreshold: 1
Enter fullscreen mode Exit fullscreen mode

Which means by default:

10 seconds × 3 failures = 30 seconds
Enter fullscreen mode Exit fullscreen mode

Your application may only get:

~30 seconds
Enter fullscreen mode Exit fullscreen mode

before Kubernetes decides startup failed.

This is why slow-starting applications often need a custom startupProbe.

Common Real-World Use Cases

  • Java applications
  • ML workloads
  • applications loading huge caches
  • Python/Gunicorn services
  • applications waiting for database migrations

The important part:

A startup probe failure itself is NOT the issue.

The issue happens only when failures continue beyond the threshold.


readinessProbe

readinessProbe:
  httpGet:
    path: /readyz
    port: 5000
  initialDelaySeconds: 5
  periodSeconds: 10
  failureThreshold: 3
Enter fullscreen mode Exit fullscreen mode

This tells Kubernetes:

Wait 5 seconds after container start.
Then check /readyz every 10 seconds.
If it fails 3 consecutive times:
remove the pod from Service traffic.
Enter fullscreen mode Exit fullscreen mode

Calculation:

10 seconds × 3 failures = 30 seconds
Enter fullscreen mode Exit fullscreen mode

If the application cannot respond successfully for:

30 continuous seconds
Enter fullscreen mode Exit fullscreen mode

the pod becomes:

NotReady
Enter fullscreen mode Exit fullscreen mode

But importantly:

The container is NOT restarted.
Enter fullscreen mode Exit fullscreen mode

Traffic simply stops flowing to it temporarily.

Default Values

If not configured, Kubernetes defaults to:

initialDelaySeconds: 0
periodSeconds: 10
timeoutSeconds: 1
failureThreshold: 3
successThreshold: 1
Enter fullscreen mode Exit fullscreen mode

This means Kubernetes starts checking almost immediately.

That can become dangerous for applications that:

  • take time to boot
  • warm caches
  • establish DB connections
  • initialize workers

Important Concept

A readiness failure usually means:

"Do not send traffic right now."
Enter fullscreen mode Exit fullscreen mode

It does NOT mean:

"The application is dead."
Enter fullscreen mode Exit fullscreen mode

This distinction is extremely important in production.


livenessProbe

livenessProbe:
  httpGet:
    path: /healthz
    port: 5000
  initialDelaySeconds: 30
  periodSeconds: 20
  failureThreshold: 3
Enter fullscreen mode Exit fullscreen mode

This tells Kubernetes:

Wait 30 seconds before starting checks.
Then check /healthz every 20 seconds.
If it fails 3 consecutive times:
restart the container.
Enter fullscreen mode Exit fullscreen mode

Calculation:

20 seconds × 3 failures = 60 seconds
Enter fullscreen mode Exit fullscreen mode

If health checks fail continuously for:

60 seconds
Enter fullscreen mode Exit fullscreen mode

Kubernetes assumes:

“The application is unhealthy or stuck.”

and restarts the container automatically.

Default Values

Kubernetes defaults:

initialDelaySeconds: 0
periodSeconds: 10
timeoutSeconds: 1
failureThreshold: 3
successThreshold: 1
Enter fullscreen mode Exit fullscreen mode

Which effectively means:

10 seconds × 3 failures = 30 seconds
Enter fullscreen mode Exit fullscreen mode

before restart behavior begins.

Common Mistake

Many teams configure aggressive liveness probes like:

timeoutSeconds: 1
Enter fullscreen mode Exit fullscreen mode

During:

  • CPU spikes
  • GC pauses
  • dependency slowness
  • temporary latency

the application may briefly respond slowly.

This can accidentally trigger unnecessary restarts.


The Most Important Thing to Understand

Many engineers panic immediately when they see:

Readiness probe failed
Enter fullscreen mode Exit fullscreen mode

or:

Liveness probe failed
Enter fullscreen mode Exit fullscreen mode

But probes are designed to fail occasionally.

The real question is:

Did the failures exceed the threshold?
Enter fullscreen mode Exit fullscreen mode

Because Kubernetes only takes action after repeated failures over time.

That’s why these settings matter so much:

failureThreshold
periodSeconds
timeoutSeconds
initialDelaySeconds
Enter fullscreen mode Exit fullscreen mode

Together, they control:

  • how patient Kubernetes should be
  • when traffic should stop
  • when restarts should happen
  • how tolerant the system should be during spikes

Probe What Happens on Failure?
startupProbe Container may be killed if startup takes too long
readinessProbe Pod stops receiving traffic
livenessProbe Container gets restarted

Kubernetes probes are not meant to punish applications.

They are safety mechanisms.

The goal is to:

  • avoid sending traffic to unhealthy pods
  • restart stuck applications
  • allow slow startups safely

Once you understand probe thresholds, Kubernetes behavior suddenly becomes much easier to debug.

Top comments (0)