Currently, I have the following architecuture in kubernetes:
- In a pod, a service and a sidecar container (called
logger
) is running. - The services writes to a file, the sidecar container reads that file and writes it to stdout.
- A fluentd daemonset is configured to read the output (which is collected in a file in
/var/log/containers/*_logger-*.log
, which is a link to another file (the latest file since the last file rotation, to the older files, no link points). - Always 3 log messages belong together (some same fields)
This configration works as expected for thousands of messages.
However, here is the problem:
I noticed that fluentd sometimes only forwards logmessage 1 or 2 of the 3 messages that belong together, although all 3 messages are written by the service and the sidecar container.
For the explaination, assume 1 is forwarded, 2 and 3 not. After some research, I found out, that in such cases, message 1 is the last message before the log rotates, message 2 and 3 are in another file (where the symbolic link points to since the rotation, and therefore should be read).
Therefore, it looks like fluentd skips some lines before continue reading at the new file after the kubernetes log rotation.
- Is this a known problem?
- Why are fluentd and kubernetes behaving like this?
- And the main question: What can I do to prevent this behavior, in order to receive all log messages?
I am using the docker-image fluent/fluentd-kubernetes-daemonset:v0.12.33-elasticsearch
If more information is required, please let me know.