Kubernetes
Readiness Probe
Network Traffic
Pod Management
Troubleshooting

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.

Practice system design

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:

  1. 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.
  2. 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.
  3. 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:

yaml
1apiVersion: apps/v1
2kind: Deployment
3metadata:
4  name: example-app
5spec:
6  replicas: 3
7  selector:
8    matchLabels:
9      app: example
10  template:
11    metadata:
12      labels:
13        app: example
14    spec:
15      containers:
16      - name: web-container
17        image: nginx:latest
18        ports:
19        - containerPort: 80
20        readinessProbe:
21          httpGet:
22            path: /status
23            port: 80
24          initialDelaySeconds: 5
25          periodSeconds: 5

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

FactorDescriptionImpact on Traffic
Readiness Probe ConfigurationMisconfigurations can lead to inaccurate status signaling.May cause unready pods to receive traffic.
Kubernetes System LatencyDelays in status propagation might result in temporary misrouting of traffic.Short-term traffic misdirection to failing pods.
Overlapping ProbesClose 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
Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
Track 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.

Practice system design

All Rights Reserved.