Search code examples
spring-bootkubernetesloggingkubernetes-helmlogback

Logback file with Kubernetes


I have a microservice application based on SpringBoot and deployed on Kubernetes with Helm Chart.

I'd like to continue to use the logback file we used previously to write the application logs in a formatted way.

This is my logback.xml file we used in:

<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="true" scanPeriod="10 seconds" debug="true">
    <include resource="org/springframework/boot/logging/logback/base.xml"/>
    <logger name="org.springframework.web" level="INFO"/>
    <logger name="com.netflix" level="WARN"/>
</configuration>

This is my configmap.xml:

apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ .Values.app.name }}-configmap
  namespace: {{ .Values.namespace }}
data:
  application.yml : |+
    server:
      ssl:
        enabled: false

I don't know how to add it.


Solution

  • You need to add the logback.xml file to the root folder of the Helm Chart template.

    This is the structure of the folder:

    ├── app-root
    │   ├── logback.xml
    │   ├── values
    │   ├── template
    │       ├── configmap.xml
    │       ├── deployment.xml
    │       ├── ...
    

    then, add in the configmap.yml file the import of that file:

    apiVersion: v1
    kind: ConfigMap
    metadata:
      name: {{ .Values.app.name }}-configmap
      namespace: {{ .Values.namespace }}
    data:
      application.yml : |+
        server:
          ssl:
            enabled: false
      logback.xml : |+
    {{ .Files.Get "base-logback.xml" | indent 4 }}