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"
原文:https://www.cnblogs.com/shaohef/p/14877150.html