Kubernetes health probes¶
Kubernetes health probes are mechanisms used by the kubelet to actively monitor the status of containers running within a Pod^[400-devops-06-kubernetes-k8s-ithelp-day10-readme.md]. They allow the cluster to detect and self-heal applications that have failed or are not yet ready to serve traffic^[400-devops-06-kubernetes-k8s-ithelp-day10-readme.md].
Probe Handlers¶
To perform a check, the kubelet can interface with the container using one of four handlers^[400-devops-06-kubernetes-k8s-ithelp-day10-readme.md].
- ExecAction: Executes a specific command inside the container. The probe succeeds if the command exits with status code
0^[400-devops-06-kubernetes-k8s-ithelp-day10-readme.md]. - TCPSocketAction: Attempts to open a TCP connection to a specific port on the container's IP. It succeeds if the port is open^[400-devops-06-kubernetes-k8s-ithelp-day10-readme.md].
- HTTPGetAction: Sends an HTTP GET request to a specific IP, port, and path. It succeeds if the response status code is between 200 and 399^[400-devops-06-kubernetes-k8s-ithelp-day10-readme.md].
- gRPC: Performs a Health Check using gRPC (available from v1.24). This requires specifying the port^[400-devops-06-kubernetes-k8s-ithelp-day10-readme.md].
Types of Probes¶
Kubernetes supports three types of probes that serve distinct purposes within the Pod lifecycle^[400-devops-06-kubernetes-k8s-ithelp-day10-readme.md].
Liveness Probe¶
A liveness probe indicates whether the container is running normally.^[400-devops-06-kubernetes-k8s-ithelp-day10-readme.md]
- Action: If this probe fails, the
kubeletterminates the container, and the container is subjected to its restart policy.^[400-devops-06-kubernetes-k8s-ithelp-day10-readme.md] - Default: If no liveness probe is provided, the state defaults to
Success.^[400-devops-06-kubernetes-k8s-ithelp-day10-readme.md]
Readiness Probe¶
A readiness probe indicates whether the container is ready to service requests.^[400-devops-06-kubernetes-k8s-ithelp-day10-readme.md]
- Action: If this probe fails, the Endpoint Controller removes the Pod's IP from all matching Service Endpoint lists.^[400-devops-06-kubernetes-k8s-ithelp-day10-readme.md]
- Use Case: This is used to control traffic flow, ensuring requests are not sent to a Pod that is still starting up or is temporarily unable to handle load.
- Default: If no readiness probe is provided, the state defaults to
Success.^[400-devops-06-kubernetes-k8s-ithelp-day10-readme.md]
Startup Probe¶
A startup probe indicates whether the application within the container has started.^[400-devops-06-kubernetes-k8s-ithelp-day10-readme.md]
- Action: If this probe fails, the
kubeletterminates the container, triggering the restart policy.^[400-devops-06-kubernetes-k8s-ithelp-day10-readme.md] - Behavior: While the startup probe is running, all other probes (liveness and readiness) are disabled. They only take over after the startup probe succeeds once^[400-devops-06-kubernetes-k8s-ithelp-day10-readme.md].
- Default: If no startup probe is provided, the state defaults to
Success.^[400-devops-06-kubernetes-k8s-ithelp-day10-readme.md]
Configuration Parameters¶
When configuring a probe, several parameters control the timing and frequency of the checks^[400-devops-06-kubernetes-k8s-ithelp-day10-readme.md].
initialDelaySeconds: The number of seconds to wait after the container starts before the first probe is initiated^[400-devops-06-kubernetes-k8s-ithelp-day10-readme.md].periodSeconds: The frequency (in seconds) at which the probe is performed^[400-devops-06-kubernetes-k8s-ithelp-day10-readme.md].timeoutSeconds: The number of seconds to wait for a response before considering the probe to have failed^[400-devops-06-kubernetes-k8s-ithelp-day10-readme.md].failureThreshold: The number of consecutive failures required before the container is considered unhealthy (e.g., triggering a restart or marking unready)^[400-devops-06-kubernetes-k8s-ithelp-day10-readme.md].
Sources¶
400-devops-06-kubernetes-k8s-ithelp-day10-readme.md
Related¶
- Pod Lifecycle
- [[Restart Policy]]
- Init Container
- [[Lifecircle Hook]]