TCP probe configuration in Kubernetes - Time & Space 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?
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 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.
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 |
|---|---|
| 10 | 10 |
| 100 | 100 |
| 1000 | 1000 |
Pattern observation: The total number of TCP probes grows linearly with the number of pods.
Time Complexity: O(n)
This means the total time spent on TCP probes grows directly in proportion to the number of pods being checked.
[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.
Understanding how probe checks scale helps you design systems that stay responsive and efficient as they grow.
What if we changed periodSeconds to a smaller value? How would the time complexity change?