My scrapbook about almost anything I stumble upon in my tech world. If you find anything useful don't forget to give thumbs-up :)


Thursday, September 15, 2022

Add k8s Container Logs to Stdout

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

Like the below page to get the update  
Facebook Page      Facebook Group      Twitter Feed      Telegram Group

No comments:

Post a Comment


The postings on this site are my own and don't necessarily represent IBM's or other companies positions, strategies or opinions. All content provided on this blog is for informational purposes and knowledge sharing only.
The owner of this blog makes no representations as to the accuracy or completeness of any information on this site or found by following any link on this site. The owner will not be liable for any errors or omissions in this information nor for the availability of this information. The owner will not be liable for any losses, injuries, or damages from the display or use of his information.