Home > Software design >  K8s ConfigMap Properties mounted and loaded from file system does not work when refresh is called
K8s ConfigMap Properties mounted and loaded from file system does not work when refresh is called

Time:05-23

I have a Spring Boot app deployed to K8s. I'm using ConfigMap instance to mount my application.properties into the Pod by running the Spring Cloud Kubernetes application and having Spring Cloud Kubernetes read them from the file system

application.properties:

spring.application.name=spring-cloud-k8s-minion
server.port=8080
spring.cloud.kubernetes.config.paths=/etc/app-config/application.properties

management.endpoint.refresh.enabled=true
management.endpoints.web.exposure.include=*

pom.xml:

    <spring-boot.version>2.6.7</spring-boot.version>
    <spring-cloud.version>2021.0.2</spring-cloud.version>
    <spring.cloud.k8s.version>2.1.2</spring.cloud.k8s.version>

    <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-starter-kubernetes-client</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-starter-kubernetes-client-config</artifactId>
    </dependency>

@Configuration()
@ConfigurationProperties(prefix = "minion")
public class MinionConfig {

    private String type = "generic-minion";

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }
}

I have a rest endpoint exposing the configs and can verify that the properties are loaded into my app when it loads.

If I update my config:

kubectl edit configmap -n development spring-cloud-k8s-minion -o yaml

and exec into my pod/container to see if the new config is reloaded I can see the new values. So far so good.

Now, if I call /actuator/refresh the new value is not loaded into my app. What I'm missing here?

CodePudding user response:

I found the fix. I have to move spring.cloud.kubernetes.config.paths to bootstrap.properties.

At least to me it was not clear where to put spring.cloud.kubernetes.config.paths. If you check the docs you cannot find anything regarding the location of it.

Overall, we have to guess between bootstrap.properties and application.proeprties!

  • Related