找不到“kubectl”。如果需要,请尝试:'minikube kubectl -- get pods -A'

`kubectl` not found. If you need it, try: 'minikube kubectl -- get pods -A'

我在 Windows 10 中安装了 minikube。我可以开始 minikube

**C:\WINDOWS\system32>minikube start
* minikube v1.15.1 on Microsoft Windows 10 Pro 10.0.18363 Build 18363
* Using the hyperv driver based on existing profile
* Starting control plane node minikube in cluster minikube
* Restarting existing hyperv VM for "minikube" ...
* Preparing Kubernetes v1.19.4 on Docker 19.03.13 ...
* Verifying Kubernetes components...
* Enabled addons: storage-provisioner, default-storageclass
* kubectl not found. If you need it, try: 'minikube kubectl -- get pods -A'
* Done! kubectl is now configured to use "minikube" cluster and "default" namespace by default**

但是上面的输出中有一个警告(倒数第二行)说 kubectl not found. If you need it, try: 'minikube kubectl -- get pods -A'

之后我也执行了这个命令minikube kubectl -- get pods -A

尝试时仍然出现以下错误 kubectl

C:\WINDOWS\system32>kubectl
'kubectl' is not recognized as an internal or external command,
operable program or batch file.

这意味着您的机器上可能不存在 kubectl,或者它没有添加到您的 PATH 中。

您可以按照 these instructions 通过下载可执行文件或使用 curl:

安装它
curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.19.0/bin/windows/amd64/kubectl.exe

之后添加 binary to PATH.

您可以运行kubectl version --client确保下载正确的版本。

您已经安装了 minikubekubectl 不是 minikube 包的一部分。

它说当您执行 minikube startkubectl 不存在,如果需要,您可以使用 minikube kubectl 代替。

这个也提到了here

If you already have kubectl installed, you can now use it to access your shiny new cluster

Minikube 在自身内部安装 kubectl

因此,要使用通过 minikube 安装的 kubectl,您必须在命令参数前加上 minikube kubectl --。例如:

# the same as `kubectl version --client`
minikube kubectl -- version --client

为方便起见,您可能需要在 shell 配置中添加一个别名。

来源:https://minikube.sigs.k8s.io/docs/handbook/kubectl/

kubectl 包裹在 minikube.

周围

不要忘记在 minikube kubectl

之后添加一个 --
minikube kubectl -- describe pod kube-scheduler-minikube --namespace kube-system
minikube kubectl -- get pods --namespace kube-system

使用doskey.exe为kubectl创建一个别名。

示例:

doskey kubectl="%PROGRAMFILES%\Kubernetes\Minikube\minikube.exe" kubectl -- $*

如果您在其他地方安装了 minikube,您可能需要更新路径。