I have an NGINX installation (used as a web proxy) inside a built Docker image in Kubernetes that will eventually have to be upgraded to run multiple pods to handle the traffic volume.
The log output from access.log
and error.log
needs to not only go into files (for our log collector service) but also appear in the Kubernetes logs, i.e. appear in /dev/stdout
and /dev/stderr
. My current solution is to run tail -F access.log >> /dev/stdout &
and similarly for the error log.
I would like to have these files in a shared PVC storage (so the logs remain after the pod crashes or restarts), and this should work fine as long as I only have one pod.
Once I have multiple pods, I have the problem that all pods will want to write into the same files - access.log
and error.log
.
I have tried a few things, but it doesn't look like NGINX supports using a variable in the log paths, so I am stuck in writing to static paths.
My best theoretical solution so far is to update the error and access log formats to include the pod name, but that would again involve adding a variable into NGINX, and I'm not sure it would allow that.
I also tried symlinks (ln -sf access-${PODNAME}.log access.log
and similar), but this can't work in a multi-pod situation, either, since all pods share the same configuration.
I'm sure I'm not the only one with this situation.
Any ideas I can try?
Thanks!