0
0
Kubernetesdevops~5 mins

Probe failure and container restart behavior in Kubernetes - Time & Space Complexity

Choose your learning style9 modes available
Time Complexity: Probe failure and container restart behavior
O(n)
Understanding Time Complexity

We want to understand how the system reacts over time when a probe fails in Kubernetes.

Specifically, how often the container restarts grow as probe failures increase.

Scenario Under Consideration

Analyze the time complexity of the following Kubernetes liveness probe configuration.


apiVersion: v1
kind: Pod
metadata:
  name: example-pod
spec:
  containers:
  - name: example-container
    image: example-image
    livenessProbe:
      httpGet:
        path: /healthz
        port: 8080
      initialDelaySeconds: 5
      periodSeconds: 10
      failureThreshold: 3

This config checks the container health every 10 seconds and restarts it after 3 failures.

Identify Repeating Operations

Identify the loops, recursion, array traversals that repeat.

  • Primary operation: The liveness probe runs repeatedly every 10 seconds.
  • How many times: It runs continuously until the container is restarted or stopped.
How Execution Grows With Input

As the number of probe failures increases, the container restart attempts grow linearly.

Input Size (failures)Approx. Restarts
31 restart after 3 failures
62 restarts after 6 failures
3010 restarts after 30 failures

Pattern observation: Restarts increase directly with the number of failures.

Final Time Complexity

Time Complexity: O(n)

This means the number of container restarts grows linearly as probe failures increase.

Common Mistake

[X] Wrong: "The container restarts immediately after one probe failure."

[OK] Correct: Kubernetes waits for the failureThreshold count before restarting, so restarts depend on multiple failures, not just one.

Interview Connect

Understanding how Kubernetes handles probe failures and restarts helps you explain system reliability and fault tolerance clearly.

Self-Check

What if we changed failureThreshold from 3 to 1? How would the time complexity of restarts change?