I am working with logs in my system.
I want to use a log sidecar to collect business container’s log.
And my business container’s log will write to its STDOUT.
So I want to redirect this STDOUT to pod’s volume file, because in a pod all containers share the same volume, so my sidecar can collect log from volume.
How should I configuer this?
I mean maybe I should write some configuration in my k8s yaml so k8s will automaticlly redirect the container’s STDOUT to pod’s volume?
2
Answers
Adding this
2>&1 > /<your_path_to_volume_inside_pod>/file.log
to yourcommand
would redirectSTDOUT
andSTDERR
to a fileYou could use a sidecar container with a logging agent
In your case, it depends on how your application pod can be configured (for intance, with the journald service active, in order to record logs)
And the backend would be your common volume file.