Nodelocaldns 导致 Coredns hosts 失效

Coredns Host Invalid

Posted by BlueFat on Wednesday, November 17, 2021

问题:coredns configmap 添加hosts不起作用

coredns: 10.233.0.3
nodelocaldns: 169.254.25.10

kubectl edit configmap coredns -n kube-system

apiVersion: v1
data:
  Corefile: |
    .:53 {
        errors
        health {
            lameduck 5s
        }
        log
        ready
        kubernetes cluster.local in-addr.arpa ip6.arpa {
          pods insecure
          fallthrough in-addr.arpa ip6.arpa
        }
        ## 添加部分
        hosts {
            192.168.10.220 rancher.sundayhk.com
            192.168.10.220 ha.sundayhk.com
            fallthrough
        }
        prometheus :9153

在busybox容器中测试

nslookup ha.sundayhk.com 169.254.25.10 # 不通
nslookup ha.sundayhk.com 10.233.0.3 # 通

参考:https://github.com/coredns/coredns/issues/3298

将 nodelocaldns 的 forward 参数

kubectl edit configmap nodelocaldns -n kube-system

# 修改前
.:53 {
        errors
        cache 30
        reload 
        loop
        bind 169.254.25.10
        forward . /etc/resolv.conf
        prometheus :9253
    }
# 修改成
.:53 {
        errors
        cache 30
        reload 
        loop
        bind 169.254.25.10
        forward . 10.233.0.3 {
            force_tcp
        }
        prometheus :9253
    }

删除nodelocaldns pod刷新配置

kubectl delete pod -n kube-system $(kubectl get pod -n kube-system | grep nodelocaldns| awk '{print $1}') 

https://blog.csdn.net/zhouzixin053/article/details/105416203