我在我的 Fedora 机器上用一个 vagrant 节点创建了一个 kubeadm (Kubernetes 1.8) 集群。集群运行良好,但我在测试 dns 时遇到了一个奇怪的问题:
$ kubectl exec busybox -- nslookup friendservice.mynamespace
Server: 10.96.0.10
Address 1: 10.96.0.10 kube-dns.kube-system.svc.cluster.local
Name: friendservice.mynamespace
Address 1: 10.44.0.2 friendservice-
0.friendservice.mynamespace.svc.cluster.local
$ kubectl -n mynamespace exec userservice-0 -- nslookup
friendservice.mynamespace
nslookup: can't resolve '(null)': Name does not resolve
Name: friendservice
Address 1: 10.44.0.2 friendservice-
0.friendservice.mynamespace.svc.cluster.local
在 mynamespace 命名空间中运行的服务的默认命名空间中,busybox pod 中的 nslookup 工作正常,但似乎当我尝试对同一自定义命名空间(mynamespace)中的服务进行 nslookup 时,dns 首先无法解析,但随后解析. 我在这里想念什么?
$ kubectl get pods --all-namespaces
kubectl get pods --all-namespaces
NAMESPACE NAME READY STATUS RESTARTS AGE
default busybox 1/1 Running 2 2h
kube-system etcd-fed-master 1/1 Running 6 2h
kube-system kube-apiserver-fed-master 1/1 Running 0 2h
kube-system kube-controller-manager-fed-master 1/1 Running 0 2h
kube-system kube-dns-545bc4bfd4-jkhrr 3/3 Running 0 2h
kube-system kube-proxy-5vcvr 1/1 Running 0 2h
kube-system kube-proxy-f4765 1/1 Running 0 2h
kube-system kube-scheduler-fed-master 1/1 Running 1 2h
kube-system weave-net-jw647 2/2 Running 0 2h
kube-system weave-net-z25rv 2/2 Running 0 2h
mynamespace friendservice-0 1/1 Running 5 10m
mynamespace userservice-0 1/1 Running 0 26m
$ kubectl exec busybox -- cat /etc/resolv.conf
nameserver 10.96.0.10
search default.svc.cluster.local svc.cluster.local cluster.local
options ndots:5
$ kubectl -n mynamespace exec bookentryservice-0 -- cat /etc/resolv.conf
nameserver 10.96.0.10
search mynamespace.svc.cluster.local svc.cluster.local cluster.local
options ndots:5
任何帮助将不胜感激。