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?
Practice
Solution
Step 1: Understand TCP probe function
A TCP probe tests if a container is accepting TCP connections on a specific port.Step 2: Compare with other options
CPU, memory, and file system checks are not done by TCP probes but by other mechanisms.Final Answer:
To check if a container accepts TCP connections on a specified port -> Option DQuick Check:
TCP probe = connection check [OK]
- Confusing TCP probe with CPU or memory monitoring
- Thinking TCP probe checks file system health
- Assuming TCP probe checks HTTP endpoints
Solution
Step 1: Identify TCP probe syntax
TCP probes usetcpSocketwith aportfield, no path.Step 2: Check options for correctness
livenessProbe: tcpSocket: port: 8080 initialDelaySeconds: 5 periodSeconds: 10 usestcpSocketwith port 8080 and timing fields correctly. Others use HTTP or exec or invalid fields.Final Answer:
livenessProbe with tcpSocket and port field -> Option CQuick Check:
TCP probe syntax = tcpSocket + port [OK]
- Using httpGet or exec instead of tcpSocket for TCP probes
- Adding a path field to tcpSocket (invalid)
- Omitting port number in tcpSocket
livenessProbe:
tcpSocket:
port: 3306
initialDelaySeconds: 10
periodSeconds: 5Solution
Step 1: Understand liveness probe behavior
Liveness probes check if a container is alive; failure triggers a restart.Step 2: Apply to TCP probe failure
If TCP connection on port 3306 fails, Kubernetes restarts the container to fix it.Final Answer:
Kubernetes will restart the container after the probe fails -> Option BQuick Check:
Liveness probe failure = container restart [OK]
- Confusing liveness with readiness probe effects
- Thinking pod is deleted permanently on failure
- Assuming failure is ignored
Solution
Step 1: Analyze probe timing parameters
Without initialDelaySeconds, probe starts immediately, possibly before container is ready.Step 2: Evaluate other options
Port 0 is invalid but would cause different errors; periodSeconds affects frequency, not immediate failure; tcpSocket is valid for readiness probes.Final Answer:
initialDelaySeconds is missing or too low, so probe runs before container is ready -> Option AQuick Check:
Missing initialDelaySeconds = early probe failure [OK]
- Assuming tcpSocket is invalid for readiness probes
- Ignoring initialDelaySeconds importance
- Confusing periodSeconds with initialDelaySeconds
Solution
Step 1: Match initialDelaySeconds to container startup time
Container needs ~20 seconds to accept connections, so initialDelaySeconds should be at least 20 to avoid early failures.Step 2: Use periodSeconds and failureThreshold to allow retries
Period of 10 seconds and failureThreshold of 3 means Kubernetes retries for up to 30 seconds before marking not ready, avoiding false negatives.Final Answer:
readinessProbe with initialDelaySeconds 25, periodSeconds 10, failureThreshold 3 -> Option AQuick Check:
Delay + retries prevent false failures [OK]
- Setting initialDelaySeconds too low causing false failures
- Using failureThreshold of 1 with short delays
- Ignoring container startup time in probe config
Ready to prove it?
Pass the test and this pattern moves unknown
