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

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

问题描述

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

当前,我发现必须总是删除现有的ConfigMap和Secret并创建一个新的要进行更新的效率并不高:

  1. kubectl delete configmap foo

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

有没有一种简单而又好用的方法可以比删除当前文件更高效?如果现在尝试删除旧的configmap而未创建新的configmap时尝试装载,则我现在正在做的事情可能会损害使用这些configmap的容器.

谢谢.

解决方案

您可以从kubectl create configmap命令获取yaml,并将其通过管道传输到kubectl replace,如下所示:

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

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.

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

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

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.

Thanks in advance.

解决方案

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天全站免登陆