Spring 云 Kubernetes 重新加载时间问题

Spring cloud Kubernetes reload timing issue

我在尝试为部署到 K8S 的应用程序实现 ConfigMap 属性 源实时重新加载时偶然发现了一个非常微妙的问题。

以下是我当前项目的一些配置片段:

application.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

PropertiesConfig.java

@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

来解决这个问题