Pod receives traffic even Kubernetes readiness probe fails
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
In Kubernetes, the management of how services interact with pods and how traffic is routed to these pods is crucial for maintaining the robustness and reliability of applications. A particular aspect of this system involves readiness probes, which are designed to determine whether a pod is ready to receive traffic. However, there are scenarios where a pod might still receive traffic even if its readiness probe fails. Understanding these scenarios requires a deeper look into Kubernetes probes and service behavior.
Understanding Kubernetes Probes
Kubernetes uses different types of probes to manage the lifecycle of pods within a cluster:
- Liveness probes: Determine if a pod is alive. If these probes fail, the kubelet kills the pod, and the pod's restart policy will be applied.
- Readiness probes: Determine if a pod is ready to accept traffic. If a readiness probe fails, the pod should theoretically not receive any traffic through Kubernetes Services.
- Startup probes: Ensure that the pod has started. These are useful for slower starting applications, to prevent them being killed before they are up and running.
These probes can be configured to perform HTTP GET requests, execute a command inside the container, or check a TCP socket, depending on the requirements of the application being deployed.
Scenario Where Pod Receives Traffic Despite Failing Readiness Probe
While the designed behavior of Kubernetes services is to distribute traffic only to pods that have their readiness probes pass, there are specific conditions under which a pod could still receive traffic even if its readiness probe fails:
Race Condition in Status Updates
The readiness status needs to propagate through the Kubernetes system. During this propagation, there's a short window where an outdated status might still be present in some parts of the system. Thus, a service could send traffic to a pod that has just failed its readiness check.
Misconfigurations in Probe and Service Definitions
If the readiness probe is misconfigured, it may not correctly reflect the pod’s state. For instance, a readiness probe could be set with inappropriate thresholds, timings, or commands. Such configurations might lead to unexpected behavior, including the handling of traffic by ‘unready’ pods.
Overlapping Liveness and Readiness Probes
If liveness and readiness probes are too closely configured, a pod may restart due to a failed liveness probe before the readiness state is updated. This situation can confuse the routing mechanism temporarily, allowing traffic to an unready pod.
Technical Example
Consider a Kubernetes Deployment with a flawed readiness probe:
If the endpoint /status is not correctly configured to return the right status codes under different circumstances, the probe might fail to accurately reflect the container's state, leading pods to incorrectly receive traffic.
Summary Table
| Factor | Description | Impact on Traffic |
| Readiness Probe Configuration | Misconfigurations can lead to inaccurate status signaling. | May cause unready pods to receive traffic. |
| Kubernetes System Latency | Delays in status propagation might result in temporary misrouting of traffic. | Short-term traffic misdirection to failing pods. |
| Overlapping Probes | Close configuration of liveness and readiness probes might cause unexpected restarts. | Potential traffic during pod restart. |
Conclusion
Kubernetes is a complex system and its behavior may sometimes deviate from expected patterns, due to configuration nuances or inherent system characteristics such as latency or race conditions. To minimize the chances of traffic being directed to unready pods, it is essential to ensure accurate readiness probe configurations, understand the nuances of probe timings, and be aware of potential system delays in status propagation.
Related reading
- Pod Security Policy not working as intended
- pod shows existing but get pod not found error when running port-forward
- Pod status as CreateContainerConfigError in Minikube cluster
- Pod template for specifying tolerations when running Spark on Kubernetes
- Pods stuck in PodInitializing state indefinitely
- Pods stuck in Terminating status
- Pods-resources.sh Permission denied in iOS Project
- PostgreSQL bitnami Helm Chart does not update the user password

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.