如何在 Kubernetes 中修补 ConfigMap [英] How to patch a ConfigMap in Kubernetes
问题描述
Kubernetes 附带一个名为 coredns
的 ConfigMap
,可让您指定 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屋!