Kubernetes, often referred to as K8s, is a powerful open-source platform for automating deployment, scaling, and management of containerized applications. A critical aspect of ensuring the health and reliability of these applications is the use of probes. Probes in Kubernetes are used to know when to restart a Container, when to replace it, or when not to route traffic to it. This article delves into the Kubernetes probes documentation, providing a comprehensive guide to help you understand and implement probes effectively.
Understanding Kubernetes Probes
Probes in Kubernetes are HTTP requests or TCP connections that Kubernetes performs to determine the health and readiness of your application. They are essential for ensuring that your application is ready to receive traffic and that it's healthy enough to serve requests. Kubernetes offers three types of probes: livenessProbe, readinessProbe, and startupProbe.
LivenessProbe
The livenessProbe is used to know when to restart a Container. For example, liveness probes could catch a deadlock, where an application is running, but unable to make progress. If the probe fails, Kubernetes will restart the Container. Here's a simple example:

livenessProbe:
httpGet:
path: /healthz
port: 8080
initialDelaySeconds: 15
timeoutSeconds: 5
ReadinessProbe
The readinessProbe is used to determine when a Container is ready to start receiving traffic. This is often used in conjunction with a load balancer to ensure that traffic is routed to healthy instances of the application. Here's an example:
readinessProbe:
httpGet:
path: /ready
port: 8080
initialDelaySeconds: 5
periodSeconds: 5
StartupProbe
The startupProbe is used to determine when a Container application has started. If a Container does not pass its startup probe, Kubernetes will keep trying to restart it until it succeeds or reaches the number of restart attempts allowed. Here's an example:
startupProbe:
httpGet:
path: /startup
port: 8080
failureThreshold: 30
periodSeconds: 10
Probe Configuration Options
Kubernetes probes offer several configuration options to fine-tune their behavior. Here are some of the key options:

- httpGet: An HTTP GET request to the specified path and port.
- tcpSocket: A TCP socket test to the specified port.
- exec: An exec command in the Container.
- initialDelaySeconds: The number of seconds after the Container has started before liveness or readiness probes are initiated.
- timeoutSeconds: The number of seconds after which the probe will timeout.
- periodSeconds: How often (in seconds) to perform the probe.
- successThreshold and failureThreshold: The minimum consecutive successes or failures for the probe to be considered successful or failed.
Probe Failure and Recovery
When a probe fails, Kubernetes takes specific actions based on the type of probe. For livenessProbe, Kubernetes will restart the Container. For readinessProbe, Kubernetes will remove the Container from the service's load balancing pool. For startupProbe, Kubernetes will keep trying to restart the Container until it succeeds or reaches the number of restart attempts allowed.
Best Practices
Here are some best practices for using probes in Kubernetes:
- Use probes to monitor your application's health and readiness.
- Configure probes to match your application's behavior.
- Use different paths for liveness and readiness probes.
- Set appropriate thresholds and timeouts for your probes.
- Test your probes to ensure they work as expected.
By following these best practices, you can ensure that your Kubernetes applications are healthy, ready, and reliable.























