Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Boot: override application.yml properties from Kubernetes ConfigMap

I need to oveeride some of properties defined in a application.yml of Spring Boot application running in k8s. How can I do this? The only way I found is to mount whole application.yml but I only need to override one property.

like image 650
kilonet Avatar asked Feb 03 '26 06:02

kilonet


1 Answers

Could be doable in another way, that's why i'm answering again. Do it in an easy way.

Create your application.yml in a configmap and mount it as a sub directory called config into the same directory where the spring boot jar ins located.

The documentation of spring boot (external application properties) says:

Spring Boot will automatically find and load application.properties and application.yaml files from the following locations when your application starts:

The classpath root

The classpath /config package

The current directory

The /config subdirectory in the current directory

Immediate child directories of the /config subdirectory

Which means we don't have to take care of setting anything. It should find the config inside the subdirectory config.

apiVersion: v1
kind: ConfigMap
metadata:
name: spring-application-config
data:
  application.yml: |
    spring:
      application:
        name: This is just an example, add as many values as you want.

pod.yaml:

...
    volumeMounts:
    - name: spring-application-config
      mountPath: /app/config
  - name: spring-application-config
    configMap:
      name: spring-application-config
...

Assuming that your spring boot jar file is located in the path /app

like image 134
Manuel Avatar answered Feb 05 '26 23:02

Manuel