Health Checks

Kubernetes supports two types of health checks:

  • Readiness Probes: To determine if a pod is ready.
  • Liveness Probes: To determine if a pod is healthy or unhealthy after it has become ready.

Readiness Probes

Kubernetes uses readiness probes to decide if the container is available for accepting traffic. The readiness probe controls which pods to use as the backend for a service. A pod is considered ready when all of its containers are ready. If a pod is not ready, it is removed from service load balancers. For example, if a container loads a large cache at start-up and takes minutes to start, you should not send requests to this container until it is ready, or the requests will fail. Instead, route requests to other pods, which are capable of servicing requests.

Liveness Probes

Kubernetes uses liveness probes to know when to restart a container. If a container is unresponsive, the application could be deadlocked due to a multi-threading defect. Restarting the container can make the application more available.

These are the methods you can use to check container status:

  • HTTP request to the pod.
  • Command execution to the pod.
  • TCP request to the pod.

Probes are defined on a container in a deployment.

Here is an example of the deployment using HTTP method:

Parameter Description
periodSeconds
Specifies that the kubelet should perform a liveness probe every
3 seconds.
initialDelaySeconds
Specifies the kubelet that it should wait 3 seconds before
performing the first probe
timeOutSeconds
Specifies how long to wait for the probe to finish. If this time is
exceeded, OpenShift Container Platform considers the probe to have failed.

The kubelet uses a web hook to determine the healthiness of the container. The check is successful if the HTTP response code is between 200 and 399.

To perform a probe, the kubelet sends an HTTP GET request to the server that is running in the Container and listening on port 8080. The handler for the server’s /health path returns a success code. For example:

livenessProbe:
   failureThreshold: 3
   httpGet:
      path: /health
      port: 8080
      scheme: HTTP
   initialDelaySeconds: 15
   periodSeconds: 15
   successThreshold: 1
   timeoutSeconds: 15
readinessProbe:
   failureThreshold: 3
   httpGet:
      path: /health
      port: 8080
      scheme: HTTP
   initialDelaySeconds: 30
   periodSeconds: 30
   successThreshold: 1
   timeoutSeconds: 15

To view the liveness and readiness of the deployed pod, run the command: Kubectl describe pod <pod_name> -n kube-system

Here is the example output:

     resources: {}
     terminationMessagePath: /dev/termination-log
     terminationMessagePolicy: File
     - --log-level=debug
     terminationMessagePolicy: Fileermination-log
   --log-level=debug
   --namespace=default
   --route-label=systest
   --insecure=true
   --agent=cccl
Liveness:      http-get http://:8080/health delay=15s timeout=15s period=15s #success=1 #failure=3
Readiness:     http-get http://:8080/health delay=30s timeout=15s period=30s #success=1 #failure=3
Environment:   <none>
Mounts:        <none>
Volumes:          <none>
curl http://<self-ip>:<port no>/health shows a response of OK.

Note

To provide feedback on Container Ingress Services or this documentation, please file a GitHub Issue.