使用kubectl补丁将DNS重写规则添加到CoreDNS Configmap [英] Use kubectl patch to add DNS Rewrite Rule to CoreDNS Configmap
问题描述
我想使用kubectl patch
命令将DNS重写规则添加到coredns配置图,如
I want to use the kubectl patch
command to add a DNS rewrite rule to the coredns configmap, as described at Custom DNS Entries For Kubernetes. The default config map looks like this:
apiVersion: v1
data:
Corefile: |
.:53 {
log
errors
health
kubernetes cluster.local in-addr.arpa ip6.arpa {
pods insecure
upstream
fallthrough in-addr.arpa ip6.arpa
ttl 30
}
prometheus :9153
forward . /etc/resolv.conf
cache 30
loop
reload
loadbalance
}
kind: ConfigMap
....
我要添加行
rewrite name old.name new.name
,但是如何指定在.:53"中添加一行元素使我感到困惑.
but how to specify adding a line within the ".:53" element is confounding me.
我知道使用kubectl get ... | sed ... | kubectl replace -f -
可以获得类似的结果,但这看起来很难看,而且我想使用JSON扩展对kubctl patch
的了解.谢谢!
I know that I can get a similar result using kubectl get ... | sed ... | kubectl replace -f -
but that would look kind of ugly, plus I want to expand my knowledge of kubctl patch
using JSON. Thanks!
推荐答案
您不能使用patch
修改ConfigMap.
You cannot modify ConfigMap using patch
in your case.
data.Corefile
是键,并且其值(Corefile内容)的类型为:string
.
data.Corefile
is a key and its value (Corefile content) is of type: string
.
api-server将其视为字节字符串.您无法使用kubectl补丁来修补字符串的一部分.
It is treated by api-server as a string of bytes. You cannot patch part of a string with kubectl patch.
第二:
我想使用JSON扩展我对kubctl补丁的了解
I want to expand my knowledge of kubctl patch using JSON
Corefile甚至不是有效的json文件.即使是,api-server也看不到json/yaml,对于api-server来说,它只是一串随机的字母数字字符.
Corefile is not even a valid json file. Even if it was, api-server doesn't see a json/yaml, for api-server its just a string of random alphanumeric characters.
那你该怎么办?
您剩下的是kubectl get ... | sed ... | kubectl replace -f -
,这是一个完全有效的解决方案.
You are left with kubectl get ... | sed ... | kubectl replace -f -
, and this is a totally valid solution.
这篇关于使用kubectl补丁将DNS重写规则添加到CoreDNS Configmap的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!