How to customize the log entries of the nginx-ingress-controller pod
This document (000021932) is provided subject to the disclaimer at the end of this document.
Environment
- Rancher v2.x
Situation
- We are trying to figure out an issue, and it requires us to know what HOST was used by a client to connect to our Kubernetes cluster.
- We want to have our custom log-format eg : "$status $request $remote_addr - $remote_user [$time_local]" for our rke2-ingress-nginx-controller pod.
Resolution
- The default log format for the "ingress-controller-log" is below. Refer to the official doc here for more details on the parameters.
log_format upstreaminfo
'$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" "$http_user_agent" '
'$request_length $request_time [$proxy_upstream_name] [$proxy_alternative_upstream_name] $upstream_addr '
'$upstream_response_length $upstream_response_time $upstream_status $req_id';
- If you want to modify the default log format, you can use any one of the methods below :
Method 1): Using Configmap (Quick method)
- Editing the configmap is the easiest and quickest option; however, it is not recommended to make lasting changes since the ConfigMap edits aren't persistent across upgrades.
- Follow the steps below to edit the "rke2-ingress-nginx-controller" configmap and modify the "log-format-upstream" as required.
- (Optional) The configuration should reload automatically. If auto-reload works, restart is optional; otherwise, perform a rollout restart of the "rke2-ingress-nginx-controller" daemonset.
a) Take backup:
#kubectl get cm -n kube-system rke2-ingress-nginx-controller -o yaml >> rke2-ingress-nginx-controller_backup.yaml
b) modify or add "log-format-upstream" :
#kubectl edit cm -n kube-system rke2-ingress-nginx-controller -o yaml
c) Verfiy changes :
#kubectl get cm -n kube-system rke2-ingress-nginx-controller -o yaml | grep -i data -A2
data:
allow-snippet-annotations: "false"
log-format-upstream: $status $request $remote_addr - $remote_user [$time_local]
d) (Optional) Rollout restart :
# kubectl rollout restart ds rke2-ingress-nginx-controller -n kube-system
Method B) : Using HelmChartConfig
- Making the changes using "HelmChartConfig" is recommended since the changes will be persisted during the upgrade.
A) Take the backup of "rke2-ingress-nginx" helmchartconfigs :
#kubectl get helmchartconfigs.helm.cattle.io rke2-ingress-nginx -n kube-system -o yaml > rke2-ingress-nginx_helmchartconfig_backup.yaml
B) Edit and add "log-format-upstream" to the rke2-ingress-nginx helmchartconfigs :
#kubectl edit helmchartconfigs.helm.cattle.io rke2-ingress-nginx -n kube-system -o yaml
spec:
valuesContent: |-
controller:
config:
log-level: info
error-log-level: info
log-format-upstream: $status $request $remote_addr - $remote_user [$time_local
Validate the changes on log:
- Access your application and monitor the logs of rke2-ingress-nginx-controller pods to validate the changes :
Eg : kubectl logs rke2-ingress-nginx-controller-vbrtk -n kube-system -f
200 GET /apple HTTP/1.1 3.0.101.163 - - [16/Aug/2025:15:21:21 +0000]
Disclaimer
This Support Knowledgebase provides a valuable tool for SUSE customers and parties interested in our products and solutions to acquire information, ideas and learn from one another. Materials are provided for informational, personal or non-commercial use within your organization and are presented "AS IS" WITHOUT WARRANTY OF ANY KIND.