首页 > 解决方案 > Kubernetes Configmap 数据格式

问题描述

我正在为我的 Spring Boot 应用程序编写一个 K8s 配置映射。这是我的 application.yaml 文件:

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

我尝试将其转换为 Kubernetes configmap,如下所示(我遵循此文档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"

在部署文件中我定义了 configmap:

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

但是当我部署我的应用程序时,它不起作用,configmap没有覆盖application.yaml,例如:app.config.paths的第一个uri仍然是http ://localhost:8080而不是http://a-服务

所以有人有这方面的经验,请帮助我!如何在 K8S configmap 中定义数组?

谢谢

标签: spring-bootkubernetesyamlconfigmapspring-properties

解决方案


推荐阅读