Skip to content

Kubernetes Lab 4 - Probes

Problem Statement I - Container Health Issues

The first issue is caused by application instances entering an unhealthy state and responding to user requests with error messages. Unfortunately, this state does not cause the container to stop, so the Kubernetes cluster is not able to detect this state and restart the container. Luckily, the application has an internal endpoint that can be used to detect whether or not it is healthy. This endpoint is /healthz on port 8080.

Solution

  • Your first task will be to create a probe to check this endpoint periodically.

  • If the endpoint returns an error or fails to respond, the probe will detect this and the cluster will restart the container.

Problem Statement II - Container Startup Issues

Another issue is caused by new pods when they are starting up. The application takes a few seconds after startup before it is ready to service requests. As a result, some users are getting error message during this brief time.

Solution

  • To fix this, you will need to create another probe. To detect whether the application is ready, the probe should simply make a request to the root endpoint, /ready, on port 8080. If this request succeeds, then the application is ready.

  • Also set a initial delay of 5 seconds for the probes.

Here is the Pod yaml file, add the probes, then create the pod in the cluster to test it.

  • Create the service container pod.

shell script oc apply -f energy-shield-service.yaml -n {DEV_NAMESPACE}

apiVersion: v1
kind: Pod
metadata:
  name: energy-shield-service
spec:
  containers:
  - name: energy-shield
    image: ibmcase/energy-shield:1
    livenessProbe:
      httpGet:
        path: /healthz
        port: 8080
    readinessProbe:
      httpGet:
        path: /ready
        port: 8080
      initialDelaySeconds: 5