The second option when it comes to collecting logs is to run a sidecar container for each application, as shown in the following diagram:
Figure 6: Running a log collector as a sidecar container
While this approach might feel a bit more cumbersome compared to using the infrastructure already built into Kubernetes, it can work quite nicely in cases where the following happens:
- The application writes to multiple log files. For example, a web server such as Apache or Nginx might be configured to write error logs to a different location than access logs. In such a case, you would add a sidecar container for each log file that you want to scrape.
- Applications use non-standard log formats that need to be transformed on a per-application basis.