问题描述
我正在尝试寻找最佳方式来批量编辑许多Kubernetes资源上的注释。看来Kustomize可能是最好的选择:
- 资源已经是kustomization.yaml的一部分
- 然后我可以使用新的或修订的注释编辑kustomization.yaml
-
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-