首页 > 其他 > 详细

add dns items for coredns

时间:2021-06-12 11:10:51      阅读:13      评论:0      收藏:0      [点我收藏+]

 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 hosts
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"

append fallthrough

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

function add_coredns_host(){
CM=${CM:-coredns}

item=fallthrough

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

NATPATH="/data/Corefile"
kubectl patch cm $CM -n kube-system --type=json -p [
{"op":"replace","path":""$NATPATH"","value": "$str"},
]
  str=$(kubectl get cm $CM -n kube-system -o json | jq .data.Corefile |
           sed -e s/\(hosts {\)/\1\\n       ‘"$1"‘/)


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"

 

restart pod

kubectl scale deployment coredns -n kube-system --replicas=0
watch -n 1 "kubectl -n kube-system get pod |grep core"


kubectl scale deployment coredns -n kube-system --replicas=2  
watch -n 1 "kubectl -n kube-system get pod |grep core"

 

add dns items for coredns

原文:https://www.cnblogs.com/shaohef/p/14877150.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!