Reload namespace and label filtering

默认情况下,将使用 Namespace resolution 中概述的步骤选择的命名空间来监听 configmap 和 Secrets 中的更改。即:如果您不告诉 Reload 要监视哪些命名空间和 configmap/Secrets,它将监视使用上述算法计算出的命名空间中的所有 configmap/Secrets。

By default, a namespace chosen using the steps outlined in Namespace resolution will be used to listen to changes in configmaps and secrets. i.e.: if you do not tell reload what namespaces and configmaps/secrets to watch for, it will watch all configmaps/secrets from the namespace that will be computed using the above algorithm.

另一方面,您可以定义更细粒度的做法。例如,您可以指定将监视更改的命名空间:

On the other hand, you can define a more fine-grained approach. For example, you can specify the namespaces where changes will be monitored:

spring:
  application:
    name: event-reload
  cloud:
    kubernetes:
      reload:
        enabled: true
        strategy: shutdown
        mode: event
        namespaces:
          - my-namespace

此类配置将使应用程序仅在 my-namespace 命名空间中监视更改。请注意,这将监视 所有 ConfigMap/secret(具体取决于您启用的哪个)。如果您想要更细粒度的做法,您可以启用“标签筛选”。首先,我们需要通过 enable-reload-filtering: true 启用此类支持

Such a configuration will make the app watch changes only in the my-namespace namespace. Mind that this will watch all configmaps/secrets (depending on which one you enable). If you want an even more fine-grained approach, you can enable "label-filtering". First we need to enable such support via : enable-reload-filtering: true

spring:
  application:
    name: event-reload
  cloud:
    kubernetes:
      reload:
        enabled: true
        strategy: shutdown
        mode: event
        namespaces:
          - my-namespaces
        monitoring-config-maps: true
        enable-reload-filtering: true

这将监视仅具有 spring.cloud.kubernetes.config.informer.enabled: true 标签的 ConfigMap/secret。

What this will do, is watch configmaps/secrets that only have the spring.cloud.kubernetes.config.informer.enabled: true label.

Table 1. Properties:
Name Type Default Description

spring.cloud.kubernetes.reload.enabled

Boolean

false

Enables monitoring of property sources and configuration reload

spring.cloud.kubernetes.reload.monitoring-config-maps

Boolean

true

Allow monitoring changes in config maps

spring.cloud.kubernetes.reload.monitoring-secrets

Boolean

false

Allow monitoring changes in secrets

spring.cloud.kubernetes.reload.strategy

Enum

refresh

The strategy to use when firing a reload (refresh, restart_context, or shutdown)

spring.cloud.kubernetes.reload.mode

Enum

event

Specifies how to listen for changes in property sources (event or polling)

spring.cloud.kubernetes.reload.period

Duration

15s

The period for verifying changes when using the polling strategy

spring.cloud.kubernetes.reload.namespaces

String[]

namespaces where we should watch for changes

spring.cloud.kubernetes.reload.enable-reload-filtering

String

enabled labeled filtering for reload functionality

备注:

Notes:

  • You should not use properties under spring.cloud.kubernetes.reload in config maps or secrets. Changing such properties at runtime may lead to unexpected results.

  • Deleting a property or the whole config map does not restore the original state of the beans when you use the refresh level.