0

I'm writing a K8s configmap for my Spring Boot application. This is my application.yaml file:

app:
config:
    paths:
        - id: a
          uri: http://localhost:8080
          args:
            - x=1
            - y=2

        - id: b
          uri: http://localhost:8081
          args:
            - x=3
            - y=4

I tried to convert it into Kubernetes configmap as below (I followed this document https://github.com/spring-projects/spring-boot/wiki/Relaxed-Binding-2.0):

apiVersion: v1
kind: ConfigMap
metadata:
    name: my-configmap
data:
    app.config.paths_0_id: a
    app.config.paths_0_uri: "http://a-service"
    app.config.paths_0_args_0_: "x=1"
    app.config.paths_0_args_1_: "y=2"

    app.config.paths_1_id: b
    app.config.paths_1_uri: "http://b-service"
    app.config.paths_1_args_0_: "x=3"
    app.config.paths_1_args_1_: "y=4"

And in the deployment file I defined configmap:

       ...
       envFrom:
          - configMapRef:
              my-configmap
       ...

But when I deployed my application, it was not working, the configmap did not override the application.yaml, for example: the first uri of app.config.paths still is http://localhost:8080 not http://a-service.

So anyone has experience with that, please help me! How can I define an array in K8S configmap?

Thanks

  • In config-maps you cannot use collections, only key/values. Try to change the collections `foo.bar['baz']: value1` to ` foo: value or foo: "value"` – lordisp Sep 18 '21 at 05:58
  • Try to follow the whole "environment variable thing". For example, try with `APP_CONFIG_PATHS_0_ID` as I don't think you can mix dots with underscores in this particular situation. With this said, I think the best option when you have a list in the configuration, is to inject the ConfigMap as a file – AndD Sep 18 '21 at 17:25
  • I have tried `APP_CONFIG_PATHS_0_ID` and it worked well, thank you! – Harry Tran Sep 20 '21 at 09:16

0 Answers0