add dns items for coredns

Posted lvmxh

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了add dns items for coredns相关的知识,希望对你有一定的参考价值。

 add a dns item as follow:

# $(kubectl get cm coredns -n kube-system  -o json | jq .data.Corefile |grep -o host)

function add_coredns_host(){
CM=${CM:-coredns}
 
kubectl get cm $CM -n kube-system  -o json | jq .data.Corefile |grep -o host
ret=$?

if [[ $ret != 0 ]]; then
  # str=`kubectl get cm $CM -n kube-system -o json | jq .data.Corefile | \\
  #      sed -e \'0,/prometheus/s/prometheus/host {\\\\\\n \'"$item"\'\\\\\\n }\\\\\\n /\'`
  str=$(kubectl get cm $CM -n kube-system -o json | jq .data.Corefile |
           sed -e \'0,/prometheus/s/prometheus/host {\\\\n       \'"$1"\'\\\\n    }\\\\n    prometheus/\')
else
  str=$(kubectl get cm $CM -n kube-system -o json | jq .data.Corefile |
           sed -e \'s/\\(host {\\)/\\1\\\\n       \'"$1"\'/\')
fi

NATPATH="/data/Corefile"
kubectl patch cm $CM -n kube-system --type=\'json\' -p \'[
{"op":"replace","path":"\'"$NATPATH"\'","value": \'"$str"\'},
]\'
}


item="172.16.30.4 gateway.sdwam.opennes"
add_coredns_host  "$item"

 

以上是关于add dns items for coredns的主要内容,如果未能解决你的问题,请参考以下文章

CoreDNS -- DNS服务与服务发现

k8s coredns 配置上游dns

k8s与dns--coredns的一些实战经验

centos7.5下coredns+etcd搭建DNS服务器

转: centos7.5 下 coredns+etcd搭建DNS服务器

处理coredns Pending故障