Dockerized Spring Boot app not using mounted Kubernetes ConfigMap (application.properties) Dockerized Spring Boot app not using mounted Kubernetes ConfigMap (application.properties) kubernetes kubernetes

Dockerized Spring Boot app not using mounted Kubernetes ConfigMap (application.properties)


The thing is that /src/main/resources/application.properties that your application uses is the one that is inside the jar file by default. If you open your jar, you should see it there.That being said, your expectations to mount a /src/main/resources directory where your jar is are not going to be fulfilled, unfortunately.These are the docs you should be looking at.

I won't go into much detail as it's explained pretty good in the docs but I will say that you are better off explicitly declaring your config location so that new people on the project know from where the config is coming from right off the bat.

You can do something like this:

---apiVersion: extensions/v1beta1kind: Deploymentmetadata:  name: my-project-api  labels:    app: my-project-apispec:  selector:    matchLabels:      app: my-project-api  template:    metadata:      labels:        app: my-project-api    spec:      containers:        - name: my-project-api          image: "my-project:latest"          imagePullPolicy: Always          env:            - name: JAVA_OPTS              value: "-Dspring.config.location=/opt/config"            .            .            .          volumeMounts:            - name: my-project-config              mountPath: /opt/config          ports:            - containerPort: 8080      volumes:        - name: my-project-config          configMap:            name: my-project-config

Hope that helps,

Cheers!


I did slightly differently. I made sure I have mounted application.properties at config/. i.e; below is my example mounted application.properties (below commands show the values in pod - i.e; after kubectl exec -it into the pod)

/ # pwd// # cat config/application.properties logback.access.enabled=falsemanagement.endpoints.web.exposure.include=health, loggers, beans, configprops, env

Basically, the trick is based on the link in the above answer. Below is an excerpt from the link in which it does say application.properties will be picked from config/. So, I made sure my environment (dev, test, prod) specific config map was mounted at config/. Do note there is precedence for the below list (per the link: locations higher in the list override lower items)

A /config subdir of the current directory.The current directoryA classpath /config packageThe classpath root

Below is the config map definition (just pasted data section)

data:  application.properties: |+    logback.access.enabled={{.Values.logacbkAccessEnabled}}    management.endpoints.web.exposure.include=health, loggers, beans, configprops, env

And you can also see from actuator/env endpoint SpringBootApp did pick those values.

{"name": "Config resource 'file [config/application.properties]' via location 'optional:file:./config/'","properties": {"logback.access.enabled": {"value": "false","origin": "URL [file:config/application.properties] - 1:24"},"management.endpoints.web.exposure.include": {"value": "health, loggers, beans, configprops, env","origin": "URL [file:config/application.properties] - 2:43"}}},