使用k8s创建dns服务时出现如下报错

[root@localhost dashboard]# kubectl get pods -n kube-system -w
NAME                                    READY   STATUS             RESTARTS   AGE
coredns-56684f94d6-w2qg7                0/1     CrashLoopBackOff   5          26m

查看pod的日志报错如下

[root@localhost dashboard]# kubectl logs coredns-56684f94d6-w2qg7 -n kube-system
.:53
2020/05/23 08:36:17 [INFO] CoreDNS-1.2.2
2020/05/23 08:36:17 [INFO] linux/amd64, go1.11, eb51e8b
CoreDNS-1.2.2
linux/amd64, go1.11, eb51e8b
2020/05/23 08:36:17 [INFO] plugin/reload: Running configuration MD5 = 18863a4483c30117a60ae2332bab9448
2020/05/23 08:36:23 [FATAL] plugin/loop: Seen "HINFO IN 5825761439314689131.3408131627399086434." more than twice, loop detected

原因是CoreDNS启动后会通过宿主机的resolv.conf文件去获取上游DNS的信息,如果这个时候获取的DNS的服务器是本地地址的话,就会出现环路,从而被环路识别器识别出来
解决方法

[root@localhost demo]# vim coredns.yaml 
  Corefile: |
    .:53 {
        errors
        health
        kubernetes cluster.local in-addr.arpa ip6.arpa {
            pods insecure
            upstream
            fallthrough in-addr.arpa ip6.arpa
        }
        prometheus :9153
        proxy . 192.168.7.102      //将此处原来的/etc/resolv.conf更改为dns服务器所在所在的本地地址
        cache 30
        loop
        reload
        loadbalance
    }

更改后重新创建即可完成创建dns的pod资源

[root@localhost demo]# kubectl get pods -n kube-system
NAME                                    READY   STATUS    RESTARTS   AGE
coredns-56684f94d6-v852p                1/1     Running   0          6m23s