如何在Kubernetes中修补ConfigMap [英] How to patch a ConfigMap in Kubernetes

查看:942
本文介绍了如何在Kubernetes中修补ConfigMap的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Kubernetes附带一个名为corednsConfigMap,可用于指定DNS设置.我想通过添加以下内容来修改或修补此配置的一小部分:

Kubernetes ships with a ConfigMap called coredns that lets you specify DNS settings. I want to modify or patch a small piece of this configuration by adding:

apiVersion: v1
kind: ConfigMap
data:
  upstreamNameservers: |
    ["1.1.1.1", "1.0.0.1"]

我知道我可以使用kubectrl edit来编辑coredns ConfigMap,是否可以通过某种方式获取仅包含我要插入或更新的设置的上述文件,并将其合并到或打上补丁现有的ConfigMap?

I know I can use kubectrl edit to edit the coredns ConfigMap is there some way I can take the above file containing only the settings I want to insert or update and have it merged on top of or patched over the existing ConfigMap?

这样做的原因是我希望使用CI/CD可重复进行部署.因此,即使我在全新的Kubernetes群集上运行Helm图表,也将应用上面的设置.

The reason for this is that I want my deployment to be repeatable using CI/CD. So, even if I ran my Helm chart on a brand new Kubernetes cluster, the settings above would be applied.

推荐答案

这会将相同的补丁应用到单个字段:

This will apply the same patch to that single field:

kubectl patch configmap/coredns \
  -n kube-system \
  --type merge \
  -p '{"data":{"upstreamNameservers":"[\"1.1.1.1\", \"1.0.0.1\"]"}}'

这篇关于如何在Kubernetes中修补ConfigMap的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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