【问题标题】:How to set null value using config map in spring boot applicaton如何在 Spring Boot 应用程序中使用 configmap 设置空值
【发布时间】:2022-01-11 19:48:18
【问题描述】:

我按照thisthis 示例在kube 中运行spring boot 应用程序并重新加载配置映射。当我设置值时,一切正常。但是当我想从地图中设置 null 或删除值时,什么也没有发生

例如我的初始化配置映射是:

apiVersion: v1
kind: ConfigMap
metadata:
  name: my-app
data:
  application.yaml: |-
    config:
      testicek: stringvalue123
      inticek: 123

但是当我将其更改为 a 并应用配置映射时:

apiVersion: v1
kind: ConfigMap
metadata:
  name: my-app
data:
  application.yaml: |-
    config:
      testicek: null
      inticek: null

然后 testicek what is String 包含空字符串 not null 并且 inticek what is Integer 甚至没有刷新并且仍然包含旧值。任何提示如何解决这个问题?

更新

所以我找到了为什么 null 被解析为空字符串here。那么4年后仍然没有钩点如何改变这种行为?更糟糕的是,当我想将 Integer 更改为 null 时什么也没有发生,因为我猜 Integer 不能为空,所以在 configMap 更改后甚至不会调用我的属性的 setter

【问题讨论】:

  • 在您的问题中,您提到“testicek 什么是 String 包含空字符串而不是 null 并且 inticek 什么是 Integer 甚至没有刷新并且仍然包含旧值”。这与 configmap 或您的 Spring Boot 应用程序有关吗?由于应用更改的 configmap 后,testicekinticek 应该更改。您能否在应用更改后为kubectl describe configmap my-app 添加输出?
  • 是的,kubectl 中的配置映射的两个属性都为 null,但在我的 Spring Boot 应用程序中 inticek 仍然是旧值

标签: java spring-boot kubernetes


【解决方案1】:

幸运的是,您所遵循的示例使用的是Deployment,而不是普通的Pod。这意味着您可以按以下方式滚动更新新版本:

kubectl rollout restart deployment/minikube-sample

【讨论】:

  • 我无法重新启动应用程序。我需要在运行时更改配置
  • 我还添加了 spring 中的第二个示例
【解决方案2】:

您可以使用 Reloader 自动安排部署的重新加载

reloader 将监视 configmap 和 secret。

请结帐:https://github.com/stakater/Reloader

【讨论】:

  • 但它会重新启动我的应用程序?
  • 是的,它将重新启动有状态的部署。检查只是文件你会明白的。
  • ye 就像我说的那样,我无法重新启动应用程序
猜你喜欢
  • 2021-10-24
  • 2022-01-12
  • 2017-08-03
  • 1970-01-01
  • 2015-07-24
  • 2017-04-16
  • 2018-09-08
  • 1970-01-01
  • 2016-08-10
相关资源
最近更新 更多