kubernetes - 无法连接到服务器:拨打tcp i / o超时

时间:2018-03-13 15:35:45

标签: kubernetes

当我运行kubectl version命令时,我收到以下错误消息。

 kubectl version
Client Version: version.Info{Major:"1", Minor:"9", GitVersion:"v1.9.0", GitCommit:"925c127ec6b946659ad0fd596fa959be43f0cc05", GitTreeState:"clean", BuildDate:"2017-12-15T21:07:38Z", GoVersion:"go1.9.2", Compiler:"gc", Platform:"linux/amd64"}
Unable to connect to the server: dial tcp 192.168.99.100:8443: i/o timeout

如何解决此问题?

11 个答案:

答案 0 :(得分:5)

您可以使用以下命令获取有关客户端 - 服务器状态的相关信息。

kubectl config view 

现在,您可以使用以下命令相应地更新或设置k8s上下文。

kubectl config use-context kubernetes

您可以对kubeconfig文件执行进一步操作。以下命令将为您提供所有必要的信息。

kubectl config --help

答案 1 :(得分:5)

当我尝试使用随Docker安装的kubrnetes时,我遇到了同样的问题。事实证明,默认情况下未启用它。 enter image description here

首先,我在Docker选项中启用了kubrnetes,然后更改了docker-for-desktop的上下文

kubectl config get-contexts
kubectl config use-context docker-for-desktop

它解决了这个问题。

答案 2 :(得分:3)

我在Ubuntu 18.04.1 LTS上遇到了同样的问题。

here为我工作的解决方案。

只需将相同的数据放在这里:

  1. 获取当前群集名称和区域:

      

    gcloud container clusters list

  2. 配置Kubernetes以使用当前集群:

      

    gcloud container clusters get-credentials [cluster name] --zone [zone]

希望有帮助。

答案 3 :(得分:3)

由于minikube出现此问题。重新启动minikube将解决此问题。运行以下命令,它将起作用-

minikube stop
minikube delete
minikube start

答案 4 :(得分:2)

我跑步时遇到类似的问题

$ kubectl version
Client Version: version.Info{Major:"1", Minor:"10", GitVersion:"v1.10.11", GitCommit:"637c7e288581ee40ab4ca210618a89a555b6e7e9", GitTreeState:"clean", BuildDate:"2018-11-26T14:38:32Z", GoVersion:"go1.9.3", Compiler:"gc", Platform:"darwin/amd64"}
Unable to connect to the server: dial tcp 192.168.99.100:8443: i/o timeout

这就是我尝试并最终工作的方式。

我首先在Mac(2.0.0.3版)上安装了Docker Desktop。 然后我用命令安装了kubectl

$ brew install kubectl
.....
==> Pouring kubernetes-cli-1.16.0.high_sierra.bottle.tar.gz
Error: The `brew link` step did not complete successfully
The formula built, but is not symlinked into /usr/local
Could not symlink bin/kubectl
Target /usr/local/bin/kubectl
already exists. You may want to remove it:
  rm '/usr/local/bin/kubectl'

To force the link and overwrite all conflicting files:
  brew link --overwrite kubernetes-cli

To list all files that would be deleted:
  brew link --overwrite --dry-run kubernetes-cli

Possible conflicting files are:
/usr/local/bin/kubectl -> /Applications/Docker.app/Contents/Resources/bin/kubectl
.....

没关系,我们已经有了kubectl。 然后我用命令安装minikube

$ brew cask install minikube
...
==> Linking Binary 'minikube-darwin-amd64' to '/usr/local/bin/minikube'.
?  minikube was successfully installed!

第一次启动minikube(未安装VirtualBox)

$ minikube start
?  minikube v1.4.0 on Darwin 10.13.6
?  Downloading VM boot image ...
    > minikube-v1.4.0.iso.sha256: 65 B / 65 B [--------------] 100.00% ? p/s 0s
    > minikube-v1.4.0.iso: 135.73 MiB / 135.73 MiB [-] 100.00% 7.75 MiB p/s 18s
?  Creating virtualbox VM (CPUs=2, Memory=2000MB, Disk=20000MB) ...
?  Retriable failure: create: precreate: VBoxManage not found. Make sure VirtualBox is installed and VBoxManage is in the path
...
?  Unable to start VM
❌  Error: [VBOX_NOT_FOUND] create: precreate: VBoxManage not found. Make sure VirtualBox is installed and VBoxManage is in the path
?  Suggestion: Install VirtualBox, or select an alternative value for --vm-driver
?  Documentation: https://minikube.sigs.k8s.io/docs/start/
⁉️   Related issues:
    ▪ https://github.com/kubernetes/minikube/issues/3784

安装VirtualBox,然后再次启动minikube(已安装VirtualBox)

$ minikube start
?  13:37:01.006849   35511 cache_images.go:79] CacheImage kubernetesui/dashboard:v2.0.0-beta4 -> /Users/kaka.go/.minikube/cache/images/kubernetesui/dashboard_v2.0.0-beta4 failed: read tcp 10.49.52.206:50350->104.18.125.25:443: read: operation timed out
?  Preparing Kubernetes v1.16.0 on Docker 18.09.9 ...
E1002 13:37:33.632298   35511 start.go:706] Error caching images:  Caching images for kubeadm: caching images: caching image /Users/kaka.go/.minikube/cache/images/kubernetesui/dashboard_v2.0.0-beta4: read tcp 10.49.52.206:50350->104.18.125.25:443: read: operation timed out
❌  Unable to load cached images: loading cached images: loading image /Users/kaka.go/.minikube/cache/images/kubernetesui/dashboard_v2.0.0-beta4: stat /Users/kaka.go/.minikube/cache/images/kubernetesui/dashboard_v2.0.0-beta4: no such file or directoryminikube v1.4.0 on Darwin 10.13.6
?  Creating virtualbox VM (CPUs=2, Memory=2000MB, Disk=20000MB) ...
E1002 
?  Downloading kubeadm v1.16.0
?  Downloading kubelet v1.16.0
?  Pulling images ...
?  Launching Kubernetes ... 

?  Error starting cluster: timed out waiting to elevate kube-system RBAC privileges: Temporary Error: creating clusterrolebinding: Post https://192.168.99.100:8443/apis/rbac.authorization.k8s.io/v1beta1/clusterrolebindings: dial tcp 192.168.99.100:8443: i/o timeout

?  Sorry that minikube crashed. If this was unexpected, we would love to hear from you:
?  https://github.com/kubernetes/minikube/issues/new/choose
❌  Problems detected in kube-addon-manager [b17d460ddbab]:
    error: no objects passeINFO:d  == Kuto apberneply
    error: no objectNsF Op:a == Kubernetssed tes ado appdon ely

第三次启动minikube

$ minikube start
?  minikube v1.4.0 on Darwin 10.13.6
?  Tip: Use 'minikube start -p <name>' to create a new cluster, or 'minikube delete' to delete this one.
?  Using the running virtualbox "minikube" VM ...
⌛  Waiting for the host to be provisioned ...
?  Preparing Kubernetes v1.16.0 on Docker 18.09.9 ...
?  Relaunching Kubernetes using kubeadm ... 

!仍然停留在重新启动

我在Docker首选项设置中启用了Kubernetes配置,重新启动Mac,并将Kubernetes上下文切换到 docker-for-desktop

哦,这次是kubectl版本,但是使用了docker-for-desktop

$ kubectl version
Client Version: version.Info{Major:"1", Minor:"10", GitVersion:"v1.10.11", GitCommit:"637c7e288581ee40ab4ca210618a89a555b6e7e9", GitTreeState:"clean", BuildDate:"2018-11-26T14:38:32Z", GoVersion:"go1.9.3", Compiler:"gc", Platform:"darwin/amd64"}
Server Version: version.Info{Major:"1", Minor:"10", GitVersion:"v1.10.11", GitCommit:"637c7e288581ee40ab4ca210618a89a555b6e7e9", GitTreeState:"clean", BuildDate:"2018-11-26T14:25:46Z", GoVersion:"go1.9.3", Compiler:"gc", Platform:"linux/amd64"}

第4次启动minikube(也许在重启系统之后)

$ minikube start
?  minikube v1.4.0 on Darwin 10.13.6
?  Tip: Use 'minikube start -p <name>' to create a new cluster, or 'minikube delete' to delete this one.
?  Starting existing virtualbox VM for "minikube" ...
⌛  Waiting for the host to be provisioned ...
?  Preparing Kubernetes v1.16.0 on Docker 18.09.9 ...
?  Relaunching Kubernetes using kubeadm ... 
⌛  Waiting for: apiserver proxy etcd scheduler controller dns
?  Done! kubectl is now configured to use "minikube"

最后,它适用于minikube上下文...

$ kubectl version
Client Version: version.Info{Major:"1", Minor:"10", GitVersion:"v1.10.11", GitCommit:"637c7e288581ee40ab4ca210618a89a555b6e7e9", GitTreeState:"clean", BuildDate:"2018-11-26T14:38:32Z", GoVersion:"go1.9.3", Compiler:"gc", Platform:"darwin/amd64"}
Server Version: version.Info{Major:"1", Minor:"16", GitVersion:"v1.16.0", GitCommit:"2bd9643cee5b3b3a5ecbd3af49d09018f0773c77", GitTreeState:"clean", BuildDate:"2019-09-18T14:27:17Z", GoVersion:"go1.12.9", Compiler:"gc", Platform:"linux/amd64"}

答案 5 :(得分:2)

从Google Cloud Shell访问GKE主站时遇到同样的问题。

然后我按照this GCloud doc进行了解决。

  1. 打开GCloud Shell

  2. 使用以下命令获取当前GCloud Shell的外部IP:

    dig +short myip.opendns.com @resolver1.opendns.com

  3. 将此外部IP添加到GKE群集的“ 主授权网络”部分-CIDR后缀为/32

之后,立即从GCloud Shell运行kubectl get nodes

答案 6 :(得分:1)

如果您使用minikube,则应运行kubectl config use-context minikube 如果您将最新的docker用于kubernetes随附的台式机,则应运行kubectl config use-context docker-for-desktop

答案 7 :(得分:1)

您必须先运行

minikube start

在您的终端上。这将为您做以下事情:

 Restarting existing virtualbox VM for "minikube" ...
⌛  Waiting for SSH access ...
  "minikube" IP address is 192.168.99.100
  Configuring Docker as the container runtime ...
  Version of container runtime is 18.06.3-ce
⌛  Waiting for image downloads to complete ...
✨  Preparing Kubernetes environment ...
  Pulling images required by Kubernetes v1.14.1 ...
  Relaunching Kubernetes v1.14.1 using kubeadm ... 
⌛  Waiting for pods: apiserver proxy etcd scheduler controller dns
  Updating kube-proxy configuration ...
  Verifying component health ......
  kubectl is now configured to use "minikube"
  Done! Thank you for using minikube!

答案 8 :(得分:0)

我检查了防火墙端口并关闭了它,我打开了它并开始工作。

答案 9 :(得分:0)

如果您正在使用azure并且最近更改了密码,请尝试以下操作:

az account clear
az login

成功登录后:

az aks get-credentials --name project_name --resource-group resource_group_name

现在运行

kubectl get nodes

您应该看到一些东西。另外,请确保使用正确的kubectl上下文。

答案 10 :(得分:0)

我的问题是我在我的 VM 上使用了 2 个虚拟网络。 Kubernetes 使用的网络始终是默认网关之一。然而,我的虚拟机之间的通信网络是另一个。

您可以使用以下标志强制 Kubernetes 使用不同的网络:

sudo kubeadm init --pod-network-cidr=192.168.0.0/16 --apiserver-cert-extra-sans=xxx.xxx.xxx.xxx --apiserver-advertise-address=xxx.xxx.xxx.xxx

将xxx.xxx.xxx.xxx改成你的K8S master的通信IP地址。