gerasalus
gerasalus

Reputation: 7697

Kubernetes livenessProbe http result?

We have an HTTP livenessProbe setup which returns a 500 if service is unhealthy, and prints out what the problem is.
Is there any way to view the output that was returned by livenessProbe?

I could log it in the application, but maybe it's possible to view from Kubernetes?

Currently, the only thing that I see doing pod describe:

Killing container with id docker://12568746c312e6646fd6ecdb2123db448be0bc6808629b1a63ced8b7298be444:pod "test-3893895584-7f4cr_test(524091bd-49d8-11e7-bd00-42010a840224)" container "test" is unhealthy, it will be killed and re-created.

Running on GKE

Upvotes: 3

Views: 1451

Answers (1)

helmbert
helmbert

Reputation: 37994

Unfortunately, there does not seem to be a way to access the HTTP response body of a failed HTTP probe.

To confirm this suspicion, let's have a look at the HTTP Prober's source code, which is run within the Kubelet daemon:

func DoHTTPProbe(url *url.URL, headers http.Header, client HTTPGetInterface) (probe.Result, string, error) {
    // ...
    body := string(b)
    if res.StatusCode >= http.StatusOK && res.StatusCode < http.StatusBadRequest {
        glog.V(4).Infof("Probe succeeded for %s, Response: %v", url.String(), *res)
        return probe.Success, body, nil
    }
    glog.V(4).Infof("Probe failed for %s with request headers %v, response body: %v", url.String(), headers, body)
    return probe.Failure, fmt.Sprintf("HTTP probe failed with statuscode: %d", res.StatusCode), nil
}

As you can see, the Kubelet daemon will log the HTTP response body of a failed probe in its own log, but even then only if verbosity was set to 4 or higher. Beyond logging the response in its own log, it is not passed back from the DoHTTPProbe method and will not be processed any further by the Kubelet.

As already noted by yourself, I'd think your safest bet would be to log the data you need from within your application itself.

Upvotes: 6

Related Questions