kubernetes.default: Name does not resolve

2019-03-05 06:52发布

问题:

Im running OpenShift.

  • OpenShift Master: v3.3.1.7
  • Kubernetes Master: v1.3.0+52492b4

But am having problems trying to run a build in Jenkins (running in a pod). This is not a problem with the java code that I'm trying to build, but is a problem in the Kubernetes/Openshift setup.

The builds fail with:

Caused by: java.net.UnknownHostException: kubernetes.default: Name does not resolve
    at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
    at java.net.InetAddress$2.lookupAllHostAddr(InetAddress.java:928)
    at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1323)
    at java.net.InetAddress.getAllByName0(InetAddress.java:1276)
    at java.net.InetAddress.getAllByName(InetAddress.java:1192)
    at java.net.InetAddress.getAllByName(InetAddress.java:1126)
    at okhttp3.Dns$1.lookup(Dns.java:39)
    ...

Does anyone know how to fix this?

回答1:

First confirm that DNS is actually working with:

› kubectl run -i -t busybox --image=busybox --restart=Never 
Waiting for pod default/busybox to be running, status is Pending, pod ready: false
If you don't see a command prompt, try pressing enter.

/ # nslookup kubernetes.default
Server:    192.168.60.10
Address 1: 192.168.60.10 kube-dns.kube-system.svc.cluster.local

Name:      kubernetes.default
Address 1: 192.168.60.1 kubernetes.default.svc.cluster.local

If that doesn't work check if the DNS pods are running:

kubectl get pods --namespace=kube-system -l k8s-app=kube-dns

Will respond sth like:

NAME                 READY     STATUS    RESTARTS   AGE
kube-dns-v14-3u5zi   3/3       Running   36         166d

Finally checking the related logs is worth a try:

kubectl logs --namespace=kube-system $(kubectl get pods --namespace=kube-system -l k8s-app=kube-dns -o name) -c kube-dns
kubectl logs --namespace=kube-system $(kubectl get pods --namespace=kube-system -l k8s-app=kube-dns -o name) -c dnsmasq
kubectl logs --namespace=kube-system $(kubectl get pods --namespace=kube-system -l k8s-app=kube-dns -o name) -c healthz

Full instructions can be found on kubernetes.io