Kubernetes PropertySource 实现
配置 Spring Boot 应用程序最常用的方法是创建一个 application.properties、application.yaml、application-profile.properties 或 application-profile.yaml 文件,其中包含键值对,用于为您的应用程序或 Spring Boot Starters提供自定义值。您可以通过指定系统属性或环境变量来覆盖这些属性。
要启用此功能,您需要将应用程序配置属性 spring.config.import 设置为 kubernetes:(在使用 YAML 时,请用引号包裹,例如 "kubernetes:")。
目前,您无法通过 spring.config.import 指定要加载的 ConfigMap 或 Secret;默认情况下,Spring Cloud Kubernetes 将根据 spring.application.name 属性加载 ConfigMap 和/或 Secret。如果 spring.application.name 未设置,则它将加载名称为 application 的 ConfigMap 和/或 Secret。
如果您希望在引导阶段加载 Kubernetes PropertySource(即 Kubernetes 的 0 个实例),就像 3.0.x 版本之前的实现方式一样,您可以将 spring-cloud-starter-bootstrap 添加到应用程序的类路径中,或者将 spring.cloud.bootstrap.enabled=true 设置为环境变量。
在引导阶段(Bootstrap)期间不支持加载属性(使用 spring-cloud-starter-bootstrap 或 spring.cloud.bootstrap.enabled=true),也不支持通过 spring.config.import 加载属性。您必须选择其中一种方法,不能同时使用。 |