Pedro Henrique
Pedro Henrique

Reputation: 191

Configure Kubernetes logs in different path with Spring Logback

I've a application Java/Spring boot that is running in a Kubernetes pod, the logs is configure to stdout, fluentd get logs from default path:

<source>
 @type tail
 path /var/log/containers/*.log
 pos_file /pos/containers.pos
 time_key time
 time_format %Y-%m-%dT%H:%M:%S.%NZ
 tag kubernetes.*
 format json
 read_from_head true
</source>

In my logback xml configs i've a appender json file:

<appender name="jsonAppender" class="ch.qos.logback.core.rolling.RollingFileAppender">
    <file>${LOG_PATH}/spring-boot-logger.log</file>
    <encoder class="net.logstash.logback.encoder.LogstashEncoder"/>
    <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
        <maxIndex>1</maxIndex>
        <fileNamePattern>${LOG_PATH}.%i</fileNamePattern>
    </rollingPolicy>
    <KeyValuePair key="service" value="java-app" />
    <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
        <MaxFileSize>1MB</MaxFileSize>
    </triggeringPolicy>
</appender>

How do I integrate this separate log file other than stdout in my Kubernete settings along with Fluentd, to send my json logs in a different path

Upvotes: 2

Views: 3215

Answers (2)

Arghya Sadhu
Arghya Sadhu

Reputation: 44579

  1. In the dockerfile for the spring boot app create a directory where logs will be written
  2. In the logback xml file have a FileAppender which will write logs in that directory path
  3. Have the logback xml file as part of the jar file in resources folder.
  4. Add Fluentd sidecar into the pod spec of the spring boot app
  5. Configure Fluentd sidecar to tail logs from the log file written in that directory path.

Upvotes: 1

coderanger
coderanger

Reputation: 54211

You need to:

  1. move that file onto an emptyDir volume (or hostPath I guess but use emptyDir) and then
  2. run fluentd/bit as a sidecar which reads from that volume and
  3. forwards to the rest of your fluentd setup.

Upvotes: 1

Related Questions