kubernetes-ingress-controller
kubernetes-ingress-controller copied to clipboard
Unable to inject log_format and access_log instructions
Is there an existing issue for this?
- [X] I have searched the existing issues
Current Behavior
Injecting individual Nginx directives
hi, My goal is to inject log_format
& access_log
instructions at the same time.
I inject it in the form of environment variables, and the injection is as follows:
(KONG_NGINX_HTTP_ACCESS_LOG=/dev/stdout main)
- env:
- name: KONG_NGINX_HTTP_LOG_FORMAT
value: 'main escape=json ''{ "remote_addr": "$remote_addr", "status": $status,
"dm":$request_body, "upstr_addr": "$upstream_addr"}'''
- name: KONG_NGINX_HTTP_ACCESS_LOG
value: /dev/stdout main
But the pod doesn't boot properly.The log output is as follows:
proxy Error: could not prepare Kong prefix at /kong_prefix: nginx configuration is invalid (exit code 1):
proxy nginx: [warn] the "user" directive makes sense only if the master process runs with super-user privileges, ignored in /kong_prefix/nginx.conf:6
proxy nginx: [emerg] unknown log format "main" in /kong_prefix/nginx-kong.conf:33
proxy nginx: configuration file /kong_prefix/nginx.conf test failed
proxy
proxy
proxy Run with --v (verbose) or --vv (debug) for more details
It can run when I remove main
, as follows:
(KONG_NGINX_HTTP_ACCESS_LOG=/dev/stdout ~~main~~)
- env:
- name: KONG_NGINX_HTTP_LOG_FORMAT
value: 'main escape=json ''{ "remote_addr": "$remote_addr", "status": $status,
"dm":$request_body, "upstr_addr": "$upstream_addr"}'''
- name: KONG_NGINX_HTTP_ACCESS_LOG
value: /dev/stdout
Next I went into the proxy
container and executed the cat kong_prefix/nginx-kong.conf
command and found that the log_format
& access_log
instruction had been injected as shown below:
# injected nginx_http_* directives
access_log /dev/stdout;
log_format main escape=json '{ "remote_addr": "$remote_addr", "status": $status, "dm":$request_body, "upstr_addr": "$upstream_addr"}';
From this, I speculate that there is a sequential relationship between the injected instructions, access_log /dev/stdout main
instructions precede the log_format ...
instructions. When nginx performs configuration loading, it finds that main
is not defined, and then reports an error.
Expected Behavior
nginx.conf
http {
log_format main escape=json '{ "dm":$request_body, "agent": "$http_user_agent" }';
access_log /dev/stdout main
}
...
Steps To Reproduce
No response
Kong Ingress Controller version
Chart version, kong:2.7.0
kong/kubernetes-ingress-controller:2.2
Kubernetes version
Server Version: version.Info{Major:"1", Minor:"21+", GitVersion:"v1.21.13-eks-84b4fe6", GitCommit:"e1318dce57b3e319a2e3fecf343677d1c4d4aa75", GitTreeState:"clean", BuildDate:"2022-06-09T18:22:07Z", GoVersion:"go1.16.15", Compiler:"gc", Platform:"linux/amd64"}
Anything else?
No response
Hi @pzhx521 👋
Do you mind adding info which KIC and chart versions you're using? Are you using the default version from 2.7 chart version which is 2.2 (https://github.com/Kong/charts/blob/kong-2.7.0/charts/kong/values.yaml#L410-L414) ?
Hi @pzhx521 👋
Do you mind adding info which KIC and chart versions you're using? Are you using the default version from 2.7 chart version which is 2.2 (https://github.com/Kong/charts/blob/kong-2.7.0/charts/kong/values.yaml#L410-L414) ?
Yes, I use the default version.
kong/kubernetes-ingress-controller:2.2