Perform Health Checks in OpenShift
In software systems, containers can become unhealthy due to issues such as temporary connectivity loss, configuration errors, or problems with external dependencies. OpenShift applications provide the readinessProbe and livenessProbe options that enable you to detect and handle unhealthy containers.
gateway93
In software systems, containers can become unhealthy due to issues such as temporary connectivity loss, configuration errors, or problems with external dependencies. OpenShift applications provide the
readinessProbe
and livenessProbe
options that enable you to detect and handle unhealthy containers.The OpenShift deployment YML file contains the configurations for performing health checks on each container.
Contents:
The following code sample shows an example of the OpenShift deployment YML file, where:
- gateway-dcis the name of the Deployment Configuration in the OpenShift deployment YML file.
- readinessProbedetermines whether a container is ready to service requests. If the readiness probe fails a container, the endpoints controller ensures the container has its IP address removed from the endpoints of all services. A readiness probe can signal to the endpoints controller that even though a container is running, it should not receive any traffic from a proxy.
- livenessProbedetermines whether a container is running properly. If the liveness probe fails, the container is killed and is subject to its restart policy.
- /opt/docker/rc.d/diagnostic/health_check.shis the Container Gateway's health check script running inside the container.
apiVersion: v1 kind: DeploymentConfig metadata: name: gateway-dc spec: containers: - name: gateway image: apim-gateway/gateway:latest env: [...] ports: [...] ? readinessProbe: exec: command: [sh, /opt/docker/rc.d/diagnostic/health_check.sh] initialDelaySeconds: 120 timeoutSeconds: 5 periodSeconds: 5 successThreshold: 1 livenessProbe: exec: command: [sh, /opt/docker/rc.d/diagnostic/health_check.sh] initialDelaySeconds: 120 timeoutSeconds: 5 periodSeconds: 5 successThreshold: 1
To change the default behavior of a health check in OpenShift, you can customize the parameters in the
livenessProbe
and readinessProbe
sections in the YML file. View the Health Check Status of the OpenShift Pod
Use the
oc get pod
command to view the health of the OpenShift pod. The following is an example of how the command is used:$ oc get pod gateway-dc-1-deploy
The output displays in the
Status
column. A healthy pod indicates a "Running" status, as shown in the following example. If the container is unhealthy and fails the health check, OpenShift tries to redeploy the pod.NAME READY STATUS RESTARTS AGE gateway-dc-1-deploy 0/1 Running 0 35m
Customize Default Health Check Behavior
The Container Gateway's default health check behavior evaluates whether there is a problem starting the Gateway server process. To customize the default health check behavior in a derived image, see Customizing Default Health Check Behavior.