busybox测试dns问题

2019/08/25 19:34
阅读数 445

获取svc

[root@master01 ~]# kubectl get svc
NAME                 TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)       AGE
kubernetes        ClusterIP      10.68.0.1       <none>          443/TCP     5d6h
nginx-service    ClusterIP      10.68.36.30   <none>          5000/TCP   45h


启动busybox容器,解析kubernetes域名

[root@master01 ~]# kubectl run --rm -it  mybox-test --image=busybox

/ # nslookup kubernetes
Server:         10.68.0.2
Address:        10.68.0.2:53

** server can't find kubernetes.default.svc.cluster.local.: NXDOMAIN

*** Can't find kubernetes.svc.cluster.local.: No answer
*** Can't find kubernetes.cluster.local.: No answer
*** Can't find kubernetes.default.svc.cluster.local.: No answer
*** Can't find kubernetes.svc.cluster.local.: No answer
*** Can't find kubernetes.cluster.local.: No answer

问题分析:

初步看可能是域名不存在或者是dns连接不上


换成dig 镜像试试

[root@master01 ~]#  kubectl run dig --rm -it --image=docker.io/azukiapp/dig /bin/sh

/ # nslookup kubernetes
Server:         10.68.0.2
Address:        10.68.0.2#53

Name:   kubernetes.default.svc.cluster.local
Address: 10.68.0.1

问题解决居然是镜像的问题


CoreDNS

CoreDNS在Kubernetes1.11版本已经做为GA功能释放,成为Kubernetes默认的DNS服务替代了Ku be-DNS,目前是kubeadm、kube-up、minikube和kops安装 工具 的默认选项。


使用ConfigMap做为配置文件。这份配置文件,会默认使用宿主机的DNS服务器地址。

[root@master01 ~]# kubectl -n kube-system get configmap coredns -oyaml
apiVersion: v1
data:
   Corefile: |
     .:53 {
         errors
         health
         ready
         kubernetes cluster.local. in-addr.arpa ip6.arpa {
           pods insecure
           fallthrough in-addr.arpa ip6.arpa
         }
         prometheus :9153
         forward . /etc/resolv.conf
         cache 30
         reload
         loadbalance
     }
kind: ConfigMap
metadata:
   annotations:
     kubectl.kubernetes.io/last-applied-configuration: |
       {"apiVersion":"v1","data":{"Corefile":".:53 {\n    errors\n    health\n    ready\n    kubernetes cluster.local. in-addr.arpa ip6.arpa {\n      pods insecure\n      fallthrough in-addr.arpa ip6.arpa\n    }\n    prometheus :9153\n    forward . /etc/resolv.conf\n    cache 30\n    reload\n    loadbalance\n}\n"},"kind":"ConfigMap","metadata":{"annotations":{},"name":"coredns","namespace":"kube-system"}}
   creationTimestamp: "2019-08-23T08:39:06Z"
   name: coredns
   namespace: kube-system
   resourceVersion: "618253"
   selfLink: /api/v1/namespaces/kube-system/configmaps/coredns
   uid: 0510fab2-7327-4c1c-8b0e-87daaa3ee1ba


名称|含义

---|---

errors|错误会被记录到标准输出

health|可以通过http://localhost:8080/health查看健康状况

prometheus|可以通过http://localhost:9153/metrics获取prometheus格式的监控数据

proxy|本地无法解析后,向上级地址进行查询,默认使用宿主机的 /etc/resolv.conf 配置

cache|缓存时间


检查COreDNS运行状况

[root@master01 ~]# kubectl -n kube-system get pods -o wide|grep coredns
NAME                                          READY   STATUS    RESTARTS            AGE    IP                NODE        NOMINATED NODE   READINESS GATES
coredns-797455887b-4n8b7                      1/1     Running   0          2d2h   10.16.0.3   51.0.1.13   <none>           <none>
coredns-797455887b-qdgk6                      1/1     Running   0          2d2h   10.16.0.2   51.0.1.13   <none>           <none>

检查部署

[root@master01 ~]# kubectl -n kube-system get deployments
NAME                         READY   UP-TO-DATE   AVAILABLE   AGE
coredns                      2/2                  2                 2           2d2h

展开阅读全文
加载中
点击引领话题📣 发布并加入讨论🔥
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部