使用Kustomize批量编辑Kubernetes批注,而无需重新启动Pod

问题描述

我正在尝试寻找最佳方式来批量编辑许多Kubernetes资源上的注释。看来Kustomize可能是最好的选择:

  1. 资源已经是kustomization.yaml的一部分
  2. 然后我可以使用新的或修订的注释编辑kustomization.yaml
  3. kubectl apply -k ./使用所需的新注释更新所有相关资源

不幸的是,这会使所有Pod终止并重新启动,有时这比我希望的要长。如果对YAML没有其他更改,则在不使用Kustomize的情况下应用注释时,不需要重新部署,我很想做类似的事情,但要大量进行。任何提示表示赞赏!

解决方法

看来,您的Pod是由某些副本集(部署,后台驻留程序,statefulset等)管理的,这是正确的。更新这些将导致更新pod规格并因此进行重新部署。

您可以查看kubectl annotate命令。

来自kubectl annotate --help

的一些示例
Examples:
  # Update pod 'foo' with the annotation 'description' and the value 'my frontend'.
  # If the same annotation is set multiple times,only the last value will be applied
  kubectl annotate pods foo description='my frontend'

  # Update a pod identified by type and name in "pod.json"
  kubectl annotate -f pod.json description='my frontend'

  # Update pod 'foo' with the annotation 'description' and the value 'my frontend running nginx',overwriting any
existing value.
  kubectl annotate --overwrite pods foo description='my frontend running nginx'

  # Update all pods in the namespace
  kubectl annotate pods --all description='my frontend running nginx'

  # Update pod 'foo' only if the resource is unchanged from version 1.
  kubectl annotate pods foo description='my frontend running nginx' --resource-version=1

  # Update pod 'foo' by removing an annotation named 'description' if it exists.
  # Does not require the --overwrite flag.
  kubectl annotate pods foo description-

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...