How to edit nginx ingress config in kubernetes?

12/22/2017

I need to implement logging for kubernetes ingress installation so all request will be logging with the following details:

  • Request headers
  • Request body
  • Response headers
  • Response body

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!

-- Eduard
kubernetes
logging
lua
nginx

2 Answers

12/22/2017

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"\'}'
-- Jose Armesto
Source: StackOverflow

1/14/2018

I think I found the solution. I need to use custom nginx template. In general, the steps should be as following:

  1. Obtain the nginx.tmpl from the ingress-nginx controller that is located at /etc/nginx/template/nginx.tmpl
  2. Edit it according to your needs
  3. Map it using volumes

The detailed instruction is located here

-- Eduard
Source: StackOverflow