How to see which node/pod served a Kubernetes Ingress request? How to see which node/pod served a Kubernetes Ingress request? kubernetes kubernetes

How to see which node/pod served a Kubernetes Ingress request?


AFAIK, there is no feature like that out of the box.

The easiest way I can think of, is adding these information as headers yourself from your API.

You technically have to Expose Pod Information to Containers Through Environment Variables and get it from code to add the headers to the response.

Would be something like this:

apiVersion: v1kind: Podmetadata:  name: dapi-envars-fieldrefspec:  containers:    - name: test-container      image: k8s.gcr.io/busybox      command: [ "sh", "-c"]      args:      - while true; do          echo -en '\n';          printenv MY_NODE_NAME MY_POD_NAME MY_POD_NAMESPACE;          printenv MY_POD_IP MY_POD_SERVICE_ACCOUNT;          sleep 10;        done;      env:        - name: MY_NODE_NAME          valueFrom:            fieldRef:              fieldPath: spec.nodeName        - name: MY_POD_NAME          valueFrom:            fieldRef:              fieldPath: metadata.name        - name: MY_POD_NAMESPACE          valueFrom:            fieldRef:              fieldPath: metadata.namespace        - name: MY_POD_IP          valueFrom:            fieldRef:              fieldPath: status.podIP        - name: MY_POD_SERVICE_ACCOUNT          valueFrom:            fieldRef:              fieldPath: spec.serviceAccountName  restartPolicy: Never

And from the API you get the information and insert into the header.