[英]Spring cloud Kubernetes reload timing issue
我偶然发现了一个非常微妙的问题,试图为我部署到 K8S 的应用程序实现 ConfigMap 属性源实时重新加载。
以下是我当前项目中的一些配置片段:
应用程序.yaml
spring:
application:
name: myapp
cloud:
kubernetes:
config:
enabled: true
name: myapp
namespace: myapp
sources:
- namespace: myapp
name: myapp-configmap
reload:
enabled: true
mode: event
strategy: refresh
refresh:
refreshable:
- com.myapp.PropertiesConfig
extra-refreshable:
- javax.sql.DataSource
myapp-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
name: myapp
name: myapp
namespace: myapp
spec:
replicas: 1
selector:
matchLabels:
name: myapp-backend
strategy:
rollingUpdate:
maxUnavailable: 0
template:
metadata:
labels:
name: myapp-backend
spec:
serviceAccountName: myapp-config-reader
volumes:
- name: myapp-configmap
configMap:
name: myapp-configmap
containers:
- name: myapp
image: eu.gcr.io/myproject/myapp:latest
volumeMounts:
- name: myapp-configmap
mountPath: /config
ports:
- containerPort: 8080
envFrom:
- configMapRef:
name: myapp-configmap
env:
- name: DATASOURCE_PASSWORD
valueFrom:
secretKeyRef:
name: myapp-db-credentials
key: password
myapp-configmap.yml
apiVersion: v1
kind: ConfigMap
metadata:
name: myapp-configmap
namespace: myapp
data:
SPRING_PROFILES_ACTIVE: dtest
application.yml: |-
reload.message: 1
属性配置文件
@Data
@Configuration
@ConfigurationProperties(prefix = "reload")
public class PropertiesConfig {
private String message;
}
我在我的 Maven POM 中使用了以下依赖项:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.4.RELEASE</version>
</parent>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-kubernetes-config</artifactId>
<version>1.1.1.RELEASE</version>
</dependency>
我可以成功地将 myapp 部署到我的 K8S 集群。
我每 10 秒有一个计划任务打印propertiesConfig.getMessage()
。 因此,当 myapp 启动时,我在日志中看到一系列“1”。
紧接着,我将 reload.message ConfigMap 的属性更改为“2”。 发生什么了?
此外,我还尝试了其他组合:模式轮询、策略 restart_context 等。 但是......我绝对想要事件+刷新! 这是我们用例所需的解决方案。
我的问题:
项目中的 application.yml 文件与 configmap 中描述的文件冲突,不知何故。
我通过将项目中的一个重命名为bootstrap.yml 来解决这个问题
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.