K8s: Log response body of the HTTP probe 'httpGet'

8/12/2021

The command kubectl describe pod returns information about a specific pod. There is a section called Events, which contains events related to a selected pod.

In case of readiness probe (httpGet) failure there will be written something like this:

Message
-------	
Readiness probe failed: HTTP probe failed with statuscode: 503

However, it's not clear what the reason is and I would like to see the response body of the readiness probe, because in the response I can specify a message that explains the reason.

Is it possible to add the response of the http probe straight to the output of kubectl describe pod so I don't have to curl this pod?

As I understand, I can set readiness probe as a exec, but I think there could be a simpler solution.

The example of the httpGet probe:

readinessProbe:
  httpGet:
    path: /healthz
    port: 8080
  initialDelaySeconds: 10
  periodSeconds: 5
-- Eldar Rakhimberdin
kubernetes

1 Answer

8/12/2021

To debug the response of HTTP GET of your program at healthz endpoint, you can port-forward your pod to the local machine, and check the response body by yourself.

  1. First of all, you need to increase the initial delay so that you have enough time to test:
readinessProbe:
  httpGet:
    path: /healthz
    port: 8080
  initialDelaySeconds: 1000 # something like this
  periodSeconds: 5
  1. Once your pod is running, use kubectl port-forward:
$ kubectl port-forward -n <namespace> <pod-name> 8080:8080
  1. Now use curl command to test response:
$ curl -XGET "localhost:8080/healthz"
-- Kamol Hasan
Source: StackOverflow