0
0
Kubernetesdevops~5 mins

TCP probe configuration in Kubernetes - Time & Space Complexity

Choose your learning style9 modes available
Time Complexity: TCP probe configuration
O(n)
Understanding Time Complexity

We want to understand how the time it takes to check a TCP connection changes as we check more endpoints.

How does the number of TCP probes affect the total checking time?

Scenario Under Consideration

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


readinessProbe:
  tcpSocket:
    port: 8080
  initialDelaySeconds: 5
  periodSeconds: 10
  timeoutSeconds: 2

This configuration checks if the container is ready by trying to open a TCP connection on port 8080 every 10 seconds after an initial delay.

Identify Repeating Operations

Identify the loops, recursion, array traversals that repeat.

  • Primary operation: TCP connection attempt to the specified port.
  • How many times: Repeats every periodSeconds (e.g., every 10 seconds) indefinitely while the pod runs.
How Execution Grows With Input

As the number of pods or containers increases, the total number of TCP probes grows proportionally.

Number of Pods (n)Approx. TCP Probes per Period
1010
100100
10001000

Pattern observation: The total number of TCP probes grows linearly with the number of pods.

Final Time Complexity

Time Complexity: O(n)

This means the total time spent on TCP probes grows directly in proportion to the number of pods being checked.

Common Mistake

[X] Wrong: "Adding more pods does not affect probe time because probes run independently."

[OK] Correct: Even if probes run independently, the total time and resources used increase with more pods, so the overall checking effort grows with pod count.

Interview Connect

Understanding how probe checks scale helps you design systems that stay responsive and efficient as they grow.

Self-Check

What if we changed periodSeconds to a smaller value? How would the time complexity change?