在 Windows 10 主页上设置 KUBECTL 时出现问题

Issue in setting up KUBECTL on Windows 10 Home

我正在尝试学习 Kubernetes,所以我在本地 Windows 10 家用计算机上安装了 Minikube,然后尝试安装 kubectl。但是到目前为止,我一直没有成功。 所以这是我到目前为止所做的: 从 https://storage.googleapis.com/kubernetes-release/release/v1.18.0/bin/windows/amd64/kubectl.exe

下载 kubectl.exe 文件

然后我在path environment variable中添加了这个exe的路径如下图:

然而,当我在命令提示符下甚至在 pwoershell 上(在管理模式下)执行 kubectl version 时,这不起作用

接下来我尝试使用文档中给出的 curl 命令 - https://kubernetes.io/docs/tasks/tools/install-kubectl/#install-kubectl-binary-with-curl-on-windows

然而,这也不起作用,如下所示:

在寻找解决问题的答案时,我偶然发现了这个 ,它解释了如何创建 .kube 配置文件夹,因为它在我的本地计算机上不存在。我按照说明操作,但也失败了。

所以现在我完全没有想法,不确定这里的问题是什么。仅供参考,我能够在我的 Mac 上轻而易举地安装所有东西,但是 Windows 只是表现得很疯狂。

任何帮助都会很有帮助。

正如用户@paltaa 提到的:

did you do a minikube start ? – paltaa

您没有启动 minikube 是您收到此错误的最可能原因。


此外,当 minikube 停止时会显示此错误消息,因为停止会更改 config 文件中的 current-context


无需在 .kube 目录中创建 config 文件,因为 minikube start 会自动为您创建适当的文件和目录。

如果您 运行 minikube start 命令成功,您应该在配置过程结束时收到以下消息,表明 kubectl 已自动设置为 minikube

Done! kubectl is not configured to use "minikube"

此外,如果您调用命令 $ kubectl config,您将获得更多信息 kubectl 如何查找配置文件:

 The loading order follows these rules:

  1.  If the --kubeconfig flag is set, then only that file is loaded. The flag may only be set once and no merging takes
place.
  2.  If $KUBECONFIG environment variable is set, then it is used as a list of paths (normal path delimiting rules for
your system). These paths are merged. When a value is modified, it is modified in the file that defines the stanza. When
a value is created, it is created in the first file that exists. If no files in the chain exist, then it creates the
last file in the list.
  3.  Otherwise, ${HOME}/.kube/config is used and no merging takes place.

请仔细看部分:

  1. Otherwise, ${HOME}/.kube/config is used

即使你没有设置KUBECONFIG环境变量kubectl也会默认为$USER_DIRECTORY(例如C:\Users\yoda\.

如果由于某种原因您的集群 运行ning 并且文件已 deleted/corrupted 您可以:

  • minikube stop
  • minikube start

这将重新创建 .kube/config


运行在 Windows 上 minikube 的步骤在这种情况下可能是: