DNS在Kubernetes中无法正常工作

时间:2019-05-06 02:10:23

标签: kubernetes

我正在我的本地PC上部署statefulset(用于进行研究),请遵循此link

在此步骤中:

kubectl run -i --tty --image busybox:1.28 dns-test --restart=Never --rm  
nslookup web-0.nginx

我遇到此错误:

nslookup web-0.nginx
Server:    10.96.0.10
Address 1: 10.96.0.10

nslookup: can't resolve 'web-0.nginx'

我的Pod和节点仍然正常工作,而我的coredns运行正常

kube-system   coredns-fb8b8dccf-hbrhw           1/1     Running   0       26m
kube-system   coredns-fb8b8dccf-rmrwp           1/1     Running   0       26m


nguyen@kmaster:~/Documents$ kubectl get --all-namespaces=true -o wide pods
NAMESPACE     NAME                              READY   STATUS    RESTARTS   AGE   IP                NODE      NOMINATED NODE   READINESS GATES
default       busybox                           1/1     Running   1          65m   10.244.1.218      knode     <none>           <none>
default       web-0                             1/1     Running   0          75m   10.244.1.215      knode     <none>           <none>
default       web-1                             1/1     Running   0          75m   10.244.1.216      knode     <none>           <none>
kube-system   coredns-fb8b8dccf-hbrhw           1/1     Running   0          51m   10.244.1.219      knode     <none>           <none>
kube-system   coredns-fb8b8dccf-rmrwp           1/1     Running   0          51m   10.244.0.37       kmaster   <none>           <none>
kube-system   etcd-kmaster                      1/1     Running   20         20d   192.168.146.132   kmaster   <none>           <none>
kube-system   kube-apiserver-kmaster            1/1     Running   514        20d   192.168.146.132   kmaster   <none>           <none>
kube-system   kube-controller-manager-kmaster   1/1     Running   144        20d   192.168.146.132   kmaster   <none>           <none>
kube-system   kube-flannel-ds-amd64-ndpjq       1/1     Running   0          76m   192.168.146.129   knode     <none>           <none>
kube-system   kube-flannel-ds-amd64-s2vhp       1/1     Running   0          76m   192.168.146.132   kmaster   <none>           <none>
kube-system   kube-proxy-dk5jd                  1/1     Running   6          20d   192.168.146.132   kmaster   <none>           <none>
kube-system   kube-proxy-ts79l                  1/1     Running   2          20d   192.168.146.129   knode     <none>           <none>
kube-system   kube-scheduler-kmaster            1/1     Running   172        20d   192.168.146.132   kmaster   <none>           <none>

nguyen@kmaster:~$ kubectl get svc 
NAME         TYPE        CLUSTER-IP  EXTERNAL-IP   PORT(S)   AGE
kubernetes   ClusterIP   10.96.0.1    <none>        443/TCP   21d
nginx        ClusterIP   None         <none>        80/TCP    6h8m

我错过了什么吗?有人可以帮助我。 谢谢!

1 个答案:

答案 0 :(得分:0)

nginx statefulset部署在默认名称空间中,如下所示

default       web-0                             1/1     Running   0          75m   10.244.1.215      knode     <none>           <none>
default       web-1                             1/1     Running   0          75m   10.244.1.216      knode     <none>           <none>

这就是您应该测试的方式

master $ kubectl get po
NAME      READY     STATUS    RESTARTS   AGE
web-0     1/1       Running   0          1m
web-1     1/1       Running   0          1m

master $ kubectl get svc
NAME         TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)   AGE
kubernetes   ClusterIP   10.96.0.1    <none>        443/TCP   35m
nginx        ClusterIP   None         <none>        80/TCP    2m
master $ kubectl run -i --tty --image busybox:1.28 dns-test --restart=Never --rm
If you don't see a command prompt, try pressing enter.
/ # nslookup nginx
Server:    10.96.0.10
Address 1: 10.96.0.10 kube-dns.kube-system.svc.cluster.local

Name:      nginx
Address 1: 10.40.0.1 web-0.nginx.default.svc.cluster.local
Address 2: 10.40.0.2 web-1.nginx.default.svc.cluster.local
/ #
/ # nslookup web-0.nginx
Server:    10.96.0.10
Address 1: 10.96.0.10 kube-dns.kube-system.svc.cluster.local

Name:      web-0.nginx
Address 1: 10.40.0.1 web-0.nginx.default.svc.cluster.local

/ # nslookup web-0.nginx.default.svc.cluster.local
Server:    10.96.0.10
Address 1: 10.96.0.10 kube-dns.kube-system.svc.cluster.local

Name:      web-0.nginx.default.svc.cluster.local
Address 1: 10.40.0.1 web-0.nginx.default.svc.cluster.local