CoreDNS介紹


本文介紹 CoreDNS 相關配置以及驗證方法,實驗環境為 Kubernetes 1.11,搭建方法參考kubeadm安裝kubernetes V1.11.1 集群

busybox 的槽點

開始之前先吐槽一下busybox中的nslookup命令。這個命令應該是實現的不是很完全,導致我在測試DNS的成功,得到了錯誤的信息。先來看一下

[root@devops-101 ~]# kubectl run busybox1 --rm -it --image=docker.io/busybox /bin/sh
If you don't see a command prompt, try pressing enter.
/ # nslookup kubernetes.default
Server:		172.17.0.10
Address:	172.17.0.10:53

** server can't find kubernetes.default: NXDOMAIN

*** Can't find kubernetes.default: No answer

看起來像是DNS沒有響應,慢着,使用帶nslookup的alphine試一下。

[root@devops-101 ~]# kubectl run dig --rm -it --image=docker.io/azukiapp/dig /bin/sh
If you don't see a command prompt, try pressing enter.
/ # dig @172.17.0.10 kubernetes.default.svc.cluster.local +noall +answer

; <<>> DiG 9.10.3-P3 <<>> @172.17.0.10 kubernetes.default.svc.cluster.local +noall +answer
; (1 server found)
;; global options: +cmd
kubernetes.default.svc.cluster.local. 5	IN A	172.17.0.1
/ # nslookup kubernetes.default
Server:		172.17.0.10
Address:	172.17.0.10#53

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

/ # nslookup www.baidu.com
Server:		172.17.0.10
Address:	172.17.0.10#53

Non-authoritative answer:
www.baidu.com	canonical name = www.a.shifen.com.
Name:	www.a.shifen.com
Address: 220.181.112.244
Name:	www.a.shifen.com
Address: 220.181.111.188

/ # nslookup kubernetes.default
Server:		172.17.0.10
Address:	172.17.0.10#53

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

好好的啊!就是這個原因,busybox坑了我好幾天。

CoreDNS

CoreDNS在Kubernetes1.11版本已經做為GA功能釋放,成為Kubernetes默認的DNS服務替代了Ku be-DNS,目前是kubeadm、kube-up、minikube和kops安裝工具的默認選項。

Stubdomain and upstreamnameserver in kube-dns translates to the proxy in CoreDNS. The federation in kube-dns has an equivalent federation in CoreDNS.

配置文件

使用kubeadm安裝CoreDNS,會使用ConfigMap做為配置文件。這份配置文件,會默認使用宿主機的DNS服務器地址。

[root@devops-101 ~]# kubectl -n kube-system get configmap coredns -oyaml
apiVersion: v1
data:
  Corefile: |
    .:53 {
        errors
        health
        kubernetes cluster.local in-addr.arpa ip6.arpa {
           pods insecure
           upstream
           fallthrough in-addr.arpa ip6.arpa
        }
        prometheus :9153
        proxy . /etc/resolv.conf
        cache 30
        reload
    }
kind: ConfigMap
metadata:
  creationTimestamp: 2018-08-20T07:01:55Z
  name: coredns
  namespace: kube-system
  resourceVersion: "193"
  selfLink: /api/v1/namespaces/kube-system/configmaps/coredns
  uid: ec72baa4-a446-11e8-ac92-080027b7c4e9

配置文件各項目的含義

名稱 含義
errors 錯誤會被記錄到標准輸出
health 可以通過http://localhost:8080/health查看健康狀況
kubernetes 根據服務的IP響應DNS查詢請求,kubeadm的Cluster DomainService CIDR默認為cluster.local10.95.0.0/12,可以通過--service-dns-domain--service-cidr參數配置。
prometheus 可以通過http://localhost:9153/metrics獲取prometheus格式的監控數據
proxy 本地無法解析后,向上級地址進行查詢,默認使用宿主機的 /etc/resolv.conf 配置
cache 緩存時間

檢查COreDNS運行狀況

檢查Pod狀態

[root@devops-101 ~]# kubectl -n kube-system get pods -o wide
NAME                                 READY     STATUS    RESTARTS   AGE       IP              NODE
coredns-78fcdf6894-52gp9             1/1       Running   4          4h        172.16.0.11     devops-101
coredns-78fcdf6894-mkvqn             1/1       Running   4          4h        172.16.0.10     devops-101
etcd-devops-101                      1/1       Running   4          3h        192.168.0.101   devops-101

檢查部署

[root@devops-101 ~]# kubectl -n kube-system get deployments
NAME      DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
coredns   2         2         2            2           4h

驗證可以采用本文剛開始部分提到的方法。

參考資料

  1. nslookup not working with flannel as network: nameserver 10.96.0.10
  2. 使用 kubeadm 搭建 kubernetes1.10 集群
  3. CoreDNS for Kubernetes Service Discovery, Take 2
  4. Migration from kube-dns to CoreDNS
  5. Deploying Kubernetes with CoreDNS using kubeadm
  6. dns service discovery fails on 1.11 with coredns (new default)


免責聲明!

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



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