busybox測試dns問題


獲取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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM