kubernetes-retired / cluster-api-provider-nested

Cluster API Provider for Nested Clusters
Apache License 2.0
301 stars 67 forks source link

[Quick Start] Failed to connect to cluster #74

Closed gyliu513 closed 3 years ago

gyliu513 commented 3 years ago
Guangyas-MacBook-Pro:kubernetes-sigs guangyaliu$ kubectl --kubeconfig kubeconfig get all -A
Unable to connect to the server: dial tcp: lookup cluster-sample-apiserver on 1.1.1.2:53: server misbehaving
Guangyas-MacBook-Pro:kubernetes-sigs guangyaliu$ kubectl get svc
NAME                       TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)    AGE
cluster-sample-apiserver   ClusterIP   10.96.206.199   <none>        6443/TCP   5m7s
cluster-sample-etcd        ClusterIP   None            <none>        <none>     5m9s
kubernetes                 ClusterIP   10.96.0.1       <none>        443/TCP    24m

@charleszheng44 ^^

charleszheng44 commented 3 years ago

@gyliu513 could you try to run nslookup cluster-sample-apiserver and share the output?

christopherhein commented 3 years ago

@charleszheng44 it appears macOS doesn't support HOSTALIASES - https://apple.stackexchange.com/questions/356972/how-can-i-make-macos-respect-hostaliases-environment-variable

christopherhein commented 3 years ago

/kind bug

gyliu513 commented 3 years ago

@christopherhein @charleszheng44 seems Linux also does not work.

root@gyliu-dev21:~/go/src/github.com/kubernetes-sigs# cat /root/.hosts
127.0.0.1 cluster-sample-apiserver
root@gyliu-dev21:~/go/src/github.com/kubernetes-sigs# env | grep HOST
HOSTALIASES=/root/.hosts
root@gyliu-dev21:~/go/src/github.com/kubernetes-sigs# nslookup cluster-sample-apiserver
Server:     172.16.200.52
Address:    172.16.200.52#53

** server can't find cluster-sample-apiserver: NXDOMAIN
root@gyliu-dev21:~/go/src/github.com/kubernetes-sigs# kubectl --kubeconfig kubeconfig get all -A
Unable to connect to the server: dial tcp: lookup cluster-sample-apiserver on 172.16.200.52:53: no such host
christopherhein commented 3 years ago

Interesting, yeah I think we just need to have this say the instructions (for now) should tell you to just add it to /etc/hosts so it will actually work or at least that is what I do.

gyliu513 commented 3 years ago

Thanks @christopherhein , /etc/hosts works for me, but not sure why nslookup cluster-sample-apiserver always failed.

Any side impact if we update /etc/hosts?

root@gyliu-dev21:~/go/src/github.com/kubernetes-sigs# kubectl --kubeconfig kubeconfig get all -A
NAMESPACE   NAME                 TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)   AGE
default     service/kubernetes   ClusterIP   10.32.0.1    <none>        443/TCP   159m
root@gyliu-dev21:~/go/src/github.com/kubernetes-sigs# nslookup cluster-sample-apiserver
Server:     172.16.200.52
Address:    172.16.200.52#53

** server can't find cluster-sample-apiserver: NXDOMAIN
root@gyliu-dev21:~/go/src/github.com/kubernetes-sigs# cat /etc/hosts
127.0.0.1 localhost
127.0.0.1 cluster-sample-apiserver

# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
172.16.164.91 gyliu-dev21.fyre.ibm.com gyliu-dev21
christopherhein commented 3 years ago

Seems like nslookup does purely DNS resolution but when you just add to the hosts file that's not populated in DNS. For /etc/hosts you should use ping or at least that's what https://askubuntu.com/questions/627906/why-is-my-etc-hosts-file-not-queried-when-nslookup-tries-to-resolve-an-address says.