更新 k8s ConfigMap 或 Secret 而不删除现有的 [英] Update k8s ConfigMap or Secret without deleting the existing one

查看:20
本文介绍了更新 k8s ConfigMap 或 Secret 而不删除现有的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用 K8S ConfigMap 和 Secret 来管理我们的属性.我的设计非常简单,将属性文件保存在 git 存储库中,并使用诸如 Thoughtworks GO 之类的构建服务器自动将它们部署为 ConfigMaps 或 Secrets(根据选择条件)到我的 k8s 集群.

I've been using K8S ConfigMap and Secret to manage our properties. My design is pretty simple, that keeps properties files in a git repo and use build server such as Thoughtworks GO to automatically deploy them to be ConfigMaps or Secrets (on choice condition) to my k8s cluster.

目前,我发现我必须始终删除现有的 ConfigMap 和 Secret 并创建新的进行更新,效率并不高,如下所示:

Currently, I found it's not really efficient that I have to always delete the existing ConfigMap and Secret and create the new one to update as below:

  1. kubectl delete configmap foo

kubectl create configmap foo --from-file foo.properties

有没有比删除当前更有效的简单方法来完成以上步骤?可能我现在正在做的事情可能会危及使用这些 configmap 的容器,如果它在旧的 configmap 被删除并且新的尚未创建的情况下尝试挂载.

Is there a nice and simple way to make above one step and more efficient than deleting current? potentially what I'm doing now may compromise the container that uses these configmaps if it tries to mount while the old configmap is deleted and the new one hasn't been created.

推荐答案

您可以从 kubectl create configmap 命令中获取 YAML 并将其通过管道传输到 kubectl replace,就像这样:

You can get YAML from the kubectl create configmap command and pipe it to kubectl replace, like this:

kubectl create configmap foo --from-file foo.properties -o yaml --dry-run | kubectl replace -f -

这篇关于更新 k8s ConfigMap 或 Secret 而不删除现有的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆