我在带有 Hyper-V 的 Windows 10 Professional 上使用 Docker for Desktop,也没有使用 minikube。我已经通过 Docker for Desktop 安装了 Kubernetes 集群,如下图:
它显示 Kubernetes 已成功安装并运行。
当我运行以下命令时:
kubectl config view
我得到以下输出:
apiVersion: v1
clusters:
- cluster:
insecure-skip-tls-verify: true
server: https://localhost:6445
name: docker-for-desktop-cluster
contexts:
- context:
cluster: docker-for-desktop-cluster
user: docker-for-desktop
name: docker-for-desktop
current-context: docker-for-desktop
kind: Config
preferences: {}
users:
- name: docker-for-desktop
user:
client-certificate-data: REDACTED
client-key-data: REDACTED
但是,当我运行
kubectl cluster-info
我收到以下错误:
Unable to connect to the server: dial tcp [::1]:6445: connectex: No connection could be made because the target machine actively refused it.
似乎有一些网络问题,我不知道如何解决这个问题。
最佳答案
我知道这是一个老问题,但以下内容帮助我解决了类似的问题。根本原因是我之前安装了 minikube,它被用作我的默认上下文。
我收到以下错误:
Unable to connect to the server: dial tcp 192.168.1.8:8443: connectex: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
在 power-shell 中运行以下命令:
> kubectl config get-contexts
CURRENT NAME CLUSTER AUTHINFO NAMESPACE
docker-desktop docker-desktop docker-desktop
docker-for-desktop docker-desktop docker-desktop
* minikube minikube minikube
这将列出所有上下文并查看是否有多个。如果您过去安装了 minikube,则会显示 * 标记作为当前选择的默认上下文。您可以将其更改为指向 docker 桌面上下文如下:
> kubectl config use-context docker-desktop
再次运行 get-contexts 命令以验证 * 标记。
现在,以下命令应该可以工作:
> kubectl get pods
关于Docker for Desktop Kubernetes 无法连接到服务器:拨号 tcp [::1]:6445,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57297337/