coreDNS域名無法解析問題
阿新 • • 發佈:2018-11-25
問題: 在pod內無法解析域名 解決: busybox的映象有bug,導致ping可以解析,但是nslookup無法解析 kubectl run -it --rm --image=infoblox/dnstools dns-client 換成上面的就可以,實在解決不了再看下面的 dnstools# nslookup kubernetes 方式一: 建立coredns.yaml 要用hostwork模式,hostwork就是用的宿主機的 伺服器IP埠 cluster-dns 指定成宿主機的 然後重啟kubelet 然後重新建立pod 修改/etc/resolv.conf [[email protected] kubernetes]# kubectl get po -o wide -n kube-system NAME READY STATUS RESTARTS AGE IP NODE coredns-6d9f9c4fc9-2h652 1/1 Running 0 1h 10.1.1.111 10.1.1.111 coredns-6d9f9c4fc9-6prhs 1/1 Running 0 1h 10.1.1.68 10.1.1.68 修改三臺的 宿主機的 resolv.conf 都改成 10.1.1.111 [[email protected] kubernetes]# cat /etc/resolv.conf # Generated by NetworkManager search openstacklocal nameserver 10.1.1.111 修改三臺的,改成各自對應的宿主機的ip地址 [[email protected] kubernetes]# cat kubelet KUBELET_HOSTNAME="--hostname-override=10.1.1.68" KUBELET_POD_INFRA_CONTAINER="--pod-infra-container-image=registry.cn-hangzhou.aliyuncs.com/google_containers/pause-amd64:3.1" KUBELET_CONFIG="--config=/etc/kubernetes/kubelet-config.yml" KUBELET_ARGS="--bootstrap-kubeconfig=/etc/kubernetes/kubelet-bootstrap.conf --kubeconfig=/etc/kubernetes/kubelet.conf --cert-dir=/etc/kubernetes/pki --network-plugin=cni --cni-bin-dir=/opt/cni/bin --cni-conf-dir=/etc/cni/net.d --cluster-dns=10.1.1.68 --cluster-domain=cluster.local " 在cul容器內部訪問 [ [email protected]-87b54756-tsnwd:/ ]$ curl example-service.default.svc.cluster.local <!DOCTYPE html> <html> <head> <title>Welcome to nginx!</title> <style> body { width: 35em; margin: 0 auto; font-family: Tahoma, Verdana, Arial, sans-serif; } </style> </head> <body> <h1>Welcome to nginx!</h1> <p>If you see this page, the nginx web server is successfully installed and working. Further configuration is required.</p> <p>For online documentation and support please refer to <a href="http://nginx.org/">nginx.org</a>.<br/> Commercial support is available at <a href="http://nginx.com/">nginx.com</a>.</p> <p><em>Thank you for using nginx.</em></p> </body> </html> 在外部主機訪問 [[email protected] kubernetes]# curl example-service.default.svc.cluster.local <!DOCTYPE html> <html> <head> <title>Welcome to nginx!</title> <style> body { width: 35em; margin: 0 auto; font-family: Tahoma, Verdana, Arial, sans-serif; } </style> </head> <body> <h1>Welcome to nginx!</h1> <p>If you see this page, the nginx web server is successfully installed and working. Further configuration is required.</p> <p>For online documentation and support please refer to <a href="http://nginx.org/">nginx.org</a>.<br/> Commercial support is available at <a href="http://nginx.com/">nginx.com</a>.</p> <p><em>Thank you for using nginx.</em></p> </body> </html> 但是訪問下面短的 還是不行 [[email protected] kubernetes]# curl example-service curl: (6) Could not resolve host: example-service; Unknown error 解決辦法,指點:搜尋域有問題, 他的是搜尋域的問題 在busybox裡面可以訪問短的域名 [[email protected] kubernetes]# kubectl run -it --rm --image=infoblox/dnstools dns-client If you don't see a command prompt, try pressing enter. dnstools# dnstools# dnstools# curl example-service <!DOCTYPE html> <html> <head> <title>Welcome to nginx!</title> <style> body { width: 35em; margin: 0 auto; font-family: Tahoma, Verdana, Arial, sans-serif; } </style> </head> <body> <h1>Welcome to nginx!</h1> <p>If you see this page, the nginx web server is successfully installed and working. Further configuration is required.</p> <p>For online documentation and support please refer to <a href="http://nginx.org/">nginx.org</a>.<br/> Commercial support is available at <a href="http://nginx.com/">nginx.com</a>.</p> <p><em>Thank you for using nginx.</em></p> </body> </html> 方式二: 新版本自然解決: 流程: 1、刪除原先coredns的配置 2、部署coredns 3. 刪除原先的pod、service、重新建立, #!/bin/bash wget https://raw.githubusercontent.com/coredns/deployment/master/kubernetes/coredns.yaml.sed wget https://raw.githubusercontent.com/coredns/deployment/master/kubernetes/deploy.sh chmod +x deploy.sh ./deploy.sh -i 10.96.0.10 -d cluster.local. > dns.yaml kubectl apply -f dns.yaml; --cluster-dns=10.1.1.8 --cluster-domain=cluster.local" 在外邊訪問service ,那是另外一個問題了啊!但是首先你cluster 中 DNS的IP 不應拿hostip 來頂住哦 可以把內部的cluster ip 再用其他的代理 代理出來,裡邊的還是用 一個clusterip #!/bin/bash export http_proxy= export https_proxy= wget https://raw.githubusercontent.com/coredns/deployment/master/kubernetes/coredns.yaml.sed wget https://raw.githubusercontent.com/coredns/deployment/master/kubernetes/deploy.sh chmod +x deploy.sh ./deploy.sh -i 10.254.0.2 -d cluster.local. > dns.yaml kubectl apply -f dns.yaml; 16:30:50 [[email protected] kubernetes]# netstat -anp |grep 53 tcp 0 0 10.1.1.111:10250 10.1.1.8:53506 ESTABLISHED 32337/kubelet tcp6 0 0 :::53 :::* LISTEN 25791/coredns tcp6 0 0 :::9153 :::* LISTEN 25791/coredns udp6 0 0 :::53 :::* 25791/coredns unix 2 [ ACC ] STREAM LISTENING 15097 653/NetworkManager /var/run/NetworkManager/private-dhcp unix 3 [ ] STREAM CONNECTED 20544 653/NetworkManager unix 2 [ ] DGRAM 15853 508/systemd-udevd unix 2 [ ] DGRAM 20239 653/NetworkManager unix 3 [ ] STREAM CONNECTED 20979 653/NetworkManager unix 3 [ ] STREAM CONNECTED 20983 653/NetworkManager [ [email protected]-87b54756-782kr:/ ]$ nslookup example-service Server: 10.96.0.10 Address 1: 10.96.0.10 kube-dns.kube-system.svc.cluster.local Name: example-service Address 1: 10.104.125.95 example-service.default.svc.cluster.local [ [email protected]-87b54756-782kr:/ ]$ curl example-service <!DOCTYPE html> <html> <head> <title>Welcome to nginx!</title> <style> body { width: 35em; margin: 0 auto; font-family: Tahoma, Verdana, Arial, sans-serif; } </style> </head> <body> <h1>Welcome to nginx!</h1> <p>If you see this page, the nginx web server is successfully installed and working. Further configuration is required.</p> <p>For online documentation and support please refer to <a href="http://nginx.org/">nginx.org</a>.<br/> Commercial support is available at <a href="http://nginx.com/">nginx.com</a>.</p> <p><em>Thank you for using nginx.</em></p> </body> </html>