I need to implement logging for kubernetes ingress installation so all request will be logging with the following details:
I understand that I can edit log_format
of nginx using ConfigMap, however, for logging response body, I need to use lua (something like this).
In this case, I should have possibility to add this lua code in every server section of nginx config. What is the most easy way to do it?
Thank you!
To be able to configure the nginx Ingress controller using a ConfigMap, you need to create the ConfigMap that will hold those values.
The nginx ingress controller will use whatever value you specify in the LogFormat
key of the ConfigMap
. So you should be able to edit the configMap and change the LogFormat key to specify the format you want. I haven't actually tried this command, but it should be something like
kubectl patch configmap nginx-config -p '{"LogFormat":\'$remote_addr - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent" $request_time <"$request_body" >"$resp_body"\'}'
I think I found the solution. I need to use custom nginx template. In general, the steps should be as following:
nginx.tmpl
from the ingress-nginx controller that is located at /etc/nginx/template/nginx.tmpl
The detailed instruction is located here