我正在通过使用Spring Cloud Kubernetes的功能来动态加载秘密来探索其功能。但是,我仍然无法正常工作。
我有一个简单的Spring Boot应用程序,它只打印出安装在pod中的密钥的内容。这是 bootstrap.properties
中的配置spring.cloud.kubernetes.reload.enabled=true
spring.cloud.kubernetes.reload.monitoring-secrets=true
spring.cloud.kubernetes.secrets.enabled=true
spring.cloud.kubernetes.secrets.paths=/etc/secret-volume
management.endpoint.info.enabled=true
management.endpoint.health.enabled=true
management.endpoint.restart.enabled=true
在 application.properties 中,我定义了属性以获取密钥的值:
mysecret.password=${MY-PWD}
在Spring Boot应用程序中,我定义了一个将存储密钥值的bean:
@Configuration
@ConfigurationProperties(prefix = "mysecret")
public class MySecret {
private String password;
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
当我在minikube上运行应用程序时,我在日志中看到Spring检测到声明的机密并激活了配置文件:
16:54:30.887 [main]信息 o.s.c.b.c.PropertySourceBootstrapConfiguration-位于属性 来源:[BootstrapPropertySource @ 1132379993 {name ='bootstrapProperties-my-pwd',properties = {MY-PWD = qwerty}}]] 16:54:30.899 [main] INFO c.c.r.ReloadSecretsApplication- 以下配置文件处于活动状态:kubernetes
过一会儿,我得到以下日志,该日志表明它已被添加为秘密监视者:
16:54:35.460 [OkHttp https://10.96.0.1 / ...]调试 i.f.k.c.d.i.WatchConnectionmanager-WebSocket已成功打开 16:54:35.460 [main] INFO o.s.c.k.c.r.EventBasedConfigurationChangeDetector-添加了新的 Kubernetes手表:秘密手表16:54:35.460 [main]信息 o.s.c.k.c.r.EventBasedConfigurationChangeDetector-Kubernetes 基于事件的配置更改检测器已激活
然后,当我更改机密时,我得到以下内容:不会触发重新加载:
11:20:15.963 [OkHttp https://10.96.0.1 / ...]警告 o.s.c.k.c.r.EventBasedConfigurationChangeDetector-当前数字 的Confimap PropertySources与从 Kubernetes-不会重新加载
有关此主题的文档非常少。 我这里有缺少的配置吗?
链接到Spring Boot应用程序:https://github.com/Azlop/spring-cloud-kubernetes-reload-secrets