问题
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
....
and I want to add the line
rewrite name old.name new.name
but how to specify adding a line within the ".:53" element is confounding me.
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!
回答1:
You cannot modify ConfigMap using patch
in your case.
data.Corefile
is a key and its value (Corefile content) is of type: string
.
It is treated by api-server as a string of bytes. You cannot patch part of a string with kubectl patch.
And second of all:
I want to expand my knowledge of kubctl patch using JSON
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.
So what can you do?
You are left with kubectl get ... | sed ... | kubectl replace -f -
, and this is a totally valid solution.
来源:https://stackoverflow.com/questions/63895949/use-kubectl-patch-to-add-dns-rewrite-rule-to-coredns-configmap