• 微信公众号:美女很有趣。 工作之余,放松一下,关注即送10G+美女照片!

add dns items for coredns

开发技术 开发技术 3小时前 2次浏览

 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/hosts {\n '"$item"'\n }\n /'`
  str=$(kubectl get cm $CM -n kube-system -o json | jq .data.Corefile |
           sed -e '0,/prometheus/s/prometheus/hosts {\n       '"$1"'\n    }\n    prometheus/')
else
  str=$(kubectl get cm $CM -n kube-system -o json | jq .data.Corefile |
           sed -e 's/(hosts {)/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
喜欢 (0)