标签:ready using rom oct info cal page clu tools
问题: 在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 [root@lab3 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 [root@lab2 kubernetes]# cat /etc/resolv.conf # Generated by NetworkManager search openstacklocal nameserver 10.1.1.111 修改三台的,改成各自对应的宿主机的ip地址 [root@lab2 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容器内部访问 [ root@curl-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> 在外部主机访问 [root@lab2 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> 但是访问下面短的 还是不行 [root@lab3 kubernetes]# curl example-service curl: (6) Could not resolve host: example-service; Unknown error 解决办法,指点:搜索域有问题, 他的是搜索域的问题 在busybox里面可以访问短的域名 [root@lab2 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 [root@lab3 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 [ root@curl-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 [ root@curl-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>
标签:ready using rom oct info cal page clu tools
原文地址:https://www.cnblogs.com/effortsing/p/10014608.html