1
votes

I try to restart the pod when an endpoint returns an HTTP 500 on the /health endpoint. The service, probe-pod, should never send traffic to the pod while it is failing.

  • The application needs to has an endpoint /start, which will indicate if it can accept traffic by returning an HTTP 200. If the endpoint returns an HTTP 500, the application has not finished initialization
  • The application needs to have another endpoint /health that will indicate if the application is still working as expected by returning an HTTP 200. If the endpoint returns an HTTP 500 the application is no longer responsive.
  • The probes should use port 8080

I know how the readiness and liveness probe works but how to connect their response base of output? I can't solve the first and second items. How could I test the solution? Could anyone help me?

2

2 Answers

1
votes

The following way you can choose I guess, also refer to this link for clarity

 livenessProbe:
      httpGet:
        path: /health
        port: 8080
      initialDelaySeconds: as-required-by-you
    
 readinessProbe:
      httpGet:
        path: /start
        port: 8080
2
votes

I try to restart the pod when an endpoint returns an HTTP 500 on the /health endpoint. The service, probe-pod, should never send traffic to the pod while it is failing.

This is the default behavior in Kubernetes with readiness probes. If the probe is failing then the pod is not 'ready' and no service forwards traffic to that pod. You can control the responsiveness of this (with some performance penalties implications) with the periodSeconds option. For example, you can set it to 1 second to make sure that as soon as the probe fails it's taken out of the traffic pool.

In terms of Readiness, Liveness, and Startup probes they have an httpGet mechanism. They consider everything status codes 200-399 as passing and everything else as failing but they don't allow you to control which status codes are 'Success' and which ones are 'Failure'.

If you'd like more control over the status code you can use the ExecAction mechanism and just use a script like this:

CODE=`curl -s -o /dev/null -w '%{http_code}' http://www.example.org/`; if [ "$CODE" -ge 200 ] && [ "$CODE" -le 399 ]; then exit 0; else exit 1; fi

In the above case, you have to make sure that curl is installed in you container.