When working with K8s containers, few application container doesn't log to standard output but to specific file. The only issue with that is unable to see the logs when you run kubectl logs <pod>. In this scenario, we have to exec into pod to access the log file.
To resolve this issue, We need to modify the "Dockerfile" of that container image as below -
Assuming, The log is being written into "/var/log/app.log" and error into "/var/log/err.log" files.
# Option 1
# forward request and error logs to docker log collector RUN ln -sf /dev/stdout /var/log/app.log \
&& ln -sf /dev/stderr /var/log/err.log
# Option 2
# Redirect request and error logs output to docker log collector RUN ln -sf /proc/1/fd/1 /var/log/app.log \
&& ln -sf /proc/1/fd/2 /var/log/err.log
No comments:
Post a Comment