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.
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?
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.
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