Kubernetes PropertySource implementations

在 Kubernetes 环境中,启用此覆盖需要将 spring.config.import 属性设置为 "kubernetes:"。Spring Cloud Kubernetes 会加载名称与应用程序名称匹配的 ConfigMap 和机密。如果没有设置应用程序名称,则会加载名称为 application 的 ConfigMap 和机密。

还可以通过添加 spring-cloud-starter-bootstrap 到类路径或设置 spring.cloud.bootstrap.enabled=true 来在引导阶段加载 Kubernetes PropertySource。

配置 Spring Boot 应用程序最常见的方法是创建一个 application.propertiesapplication.yamlapplication-profile.propertiesapplication-profile.yaml 文件,其中包含为你的应用程序或 Spring Boot 初学者提供自定义值的键值对。你可以通过指定系统属性或环境变量来覆盖这些属性。

要启用此功能,你需要将 spring.config.import 应用程序配置属性设为 kubernetes:(在使用 yaml 时用引号转义,例如 "kubernetes:")。当前你无法使用 spring.config.import 指定要加载的 ConfigMap 或机密,默认情况下,Spring Cloud Kubernetes 将根据 spring.application.name 属性加载 ConfigMap 和/或机密。如果未设置 spring.application.name,它将加载名称为 application 的 ConfigMap 和/或机密。

如果你想将 Kubernetes PropertySource`s during the bootstrap phase like it worked prior to the 3.0.x release you can either add `spring-cloud-starter-bootstrap 加载到应用程序的类路径或将 spring.cloud.bootstrap.enabled=true 设置为环境变量。