I have a spring boot application with the below docker file.
FROM docker.com/base/jdk1.8:latest
MAINTAINER Application Engineering [ https://docker.com/ ]
RUN mkdir -p /opt/docker/svc
COPY application/weather-service.war /opt/docker/svc/
CMD java -jar /opt/docker/svc/weather-service.war --spring.config.location=file:/conf/application.properties -Dlogging.config=/conf/logback.xml
I can use kubernetes configMap or secrets for application.properties and use the volume mount option as below.
"spec": {
"volumes": [
{
"name": "svc-prop",
"configMap": {
"name": "svc-app-config",
"items": [
{
"key": "application.properties",
"path": "application.properties"
}
]
}
}
],
"containers": [
"volumeMounts": [
{
"name": "svc-prop",
"mountPath": "/conf"
}
]
How can i achieve the samething for logback.xml. Do i need to use secrets as a file in this case?
I dont want to bundle logback.xml file with the image as we might be changing the log level at runtime.
Is there any other better approach for keeping logback.xml for spring boot app in Kubernetes?
You have already done... use ConfigMap and update ConfigMap by using "kubectl edit" when logback.xml needs to be updated.
When a ConfigMap or a Secret is updated, it gets eventually reflected inside the container, and if so configured such as via scan, then the application will pick up the change eventually. If not, the pod(s) need to be restarted to pick up the updated logback.xml.
Create a configmap for logback.
apiVersion: v1
kind: ConfigMap
metadata:
name: logback-configmap
data:
logback.xml: |+
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include resource="org/springframework/boot/logging/logback/base.xml"/>
<logger name="org.springframework.web" level="DEBUG"/>
</configuration>
Specify the configmap as a volume in your deployment.
volumes:
- configMap:
name: logback-configmap
name: logback
Mount the configmap volume in your container.
volumeMounts:
- mountPath: /path/to/logback.xml
name: logback