在 Windows 10 中安装 kubectl 时出错

Error while installing kubectl in Windows 10

在 windows 10 上安装 kubectl 无效。我关注这个 URL.

我尝试了不同的安装选项,在 powershell 中和使用 chocolote。 None 其中对我有用。错误很明显,windows os 不支持此可执行文件。我确实检查了 SHA,但它是不同的。

PS D:\chocoloate_tmpdir> curl -o kubectl.exe.sha256 https://amazon-eks.s3-us-west-2.amazonaws.com/1.14.6/2019-08-22/bin/windows/amd64/kubectl.exe.sha256
PS D:\chocoloate_tmpdir> Get-FileHash kubectl.exe                                                                                                                                               
Algorithm       Hash                                                                   Path
---------       ----                                                                   ----
SHA256          02F984988E490046CBC831A582D34505C28C7DD9AB61C357E264C7178596B701       D:\chocoloate_tmpdir\kubectl.exe

PS D:\chocoloate_tmpdir> Get-FileHash .\kubectl.exe.sha256                                                                                                                                      
Algorithm       Hash                                                                   Path
---------       ----                                                                   ----
SHA256          98BCEB6AF839704828C28709B60628E25CF5F624A6D6E7D06F1FC255AA4254CB       D:\chocoloate_tmpdir\kubectl.exe.sha256

问题是,可能是什么问题以及在 windows 中安装 kubectl 有哪些其他方法可用。

以下是尝试过的命令和错误输出:

一个:

PS D:\chocoloate_tmpdir> choco install kubernetes-cli                                                                                                                                           Chocolatey v0.10.15
Installing the following packages:
kubernetes-cli
By installing you accept licenses for the packages.
Progress: Downloading kubernetes-cli 1.17.1... 100%

kubernetes-cli v1.17.1 [Approved]
kubernetes-cli package files install completed. Performing other installation steps.
The package kubernetes-cli wants to run 'chocolateyInstall.ps1'.
Note: If you don't run this script, the installation will fail.
Note: To confirm automatically next time, use '-y' or consider:
choco feature enable -n allowGlobalConfirmation
Do you want to run the script?([Y]es/[A]ll - yes to all/[N]o/[P]rint): Y

Extracting 64-bit C:\ProgramData\chocolatey\lib\kubernetes-cli\tools\kubernetes-client-windows-amd64.tar.gz to C:\ProgramData\chocolatey\lib\kubernetes-cli\tools...
C:\ProgramData\chocolatey\lib\kubernetes-cli\tools
Extracting 64-bit C:\ProgramData\chocolatey\lib\kubernetes-cli\tools\kubernetes-client-windows-amd64.tar to C:\ProgramData\chocolatey\lib\kubernetes-cli\tools...
C:\ProgramData\chocolatey\lib\kubernetes-cli\tools
 ShimGen has successfully created a shim for kubectl.exe
 The install of kubernetes-cli was successful.
  Software installed to 'C:\ProgramData\chocolatey\lib\kubernetes-cli\tools'

Chocolatey installed 1/1 packages.
 See the log for details (C:\ProgramData\chocolatey\logs\chocolatey.log).
PS D:\chocoloate_tmpdir> kubectl version --client                                                                                                                                               Program 'kubectl.exe' failed to run: The specified executable is not a valid application for this OS platform.At line:1 char:1
+ kubectl version --client
+ ~~~~~~~~~~~~~~~~~~~~~~~~.
At line:1 char:1
+ kubectl version --client
+ ~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ResourceUnavailable: (:) [], ApplicationFailedException
    + FullyQualifiedErrorId : NativeCommandFailed

两个:

PS D:\chocoloate_tmpdir> curl -o kubectl.exe https://amazon-eks.s3-us-west-2.amazonaws.com/1.14.6/2019-08-22/bin/windows/amd64/kubectl.exe 
PS D:\chocoloate_tmpdir> cp .\kubectl.exe C:\bin\ 
PS D:\chocoloate_tmpdir> kubectl version                                                                                                                                                        Program 'kubectl.exe' failed to run: The specified executable is not a valid application for this OS platform.At line:1 char:1
+ kubectl version
+ ~~~~~~~~~~~~~~~.
At line:1 char:1
+ kubectl version
+ ~~~~~~~~~~~~~~~
    + CategoryInfo          : ResourceUnavailable: (:) [], ApplicationFailedException
    + FullyQualifiedErrorId : NativeCommandFailed

从当前路径调用命令就可以了。我已将可执行文件添加到 c:\bin 路径并将路径添加到系统环境变量,不知何故未设置,不知道为什么。这是在路径中找不到可执行文件的问题。

PS D:\chocoloate_tmpdir> kubectl version                                                                                                                                                        Program 'kubectl.exe' failed to run: The specified executable is not a valid application for this OS platform.At line:1 char:1
+ kubectl version
+ ~~~~~~~~~~~~~~~.
At line:1 char:1
+ kubectl version
+ ~~~~~~~~~~~~~~~
    + CategoryInfo          : ResourceUnavailable: (:) [], ApplicationFailedException
    + FullyQualifiedErrorId : NativeCommandFailed

PS D:\chocoloate_tmpdir> .\kubectl.exe version                                                                                                                                                  Client Version: version.Info{Major:"1", Minor:"14+", GitVersion:"v1.14.7-eks-1861c5", GitCommit:"1861c597586f84f1498a9f2151c78d8a6bf47814", GitTreeState:"clean", BuildDate:"2019-09-24T22:12:08Z", GoVersion:"go1.12.9", Compiler:"gc", Platform:"windows/amd64"}
Unable to connect to the server: dial tcp [::1]:8080: connectex: No connection could be made because the target machine actively refused it.

您可能错过了其中的一些步骤:

Copy the binary to a folder in your PATH. If you have an existing directory in your PATH that you use for command line utilities, copy the binary to that directory. Otherwise, complete the following steps.

  1. Create a new directory for your command line binaries, such as C:\bin.

  2. Copy the kubectl.exe binary to your new directory.

  3. Edit your user or system PATH environment variable to add the new directory to your PATH.

  4. Close your PowerShell terminal and open a new one to pick up the new PATH variable.

请验证您的 PATH 的当前内容是什么。您可以将 kubectl 二进制文件直接移动到已添加到您的 PATH 中的文件夹之一。或者,您可以编辑它并添加包含 kubectl 的所需目录。保存更改后,您是否重新启动了 PowerShell 终端?配置非常简单,无需使用可执行文件的完整路径。

查看官方 kubernetes 文档中的 this 文章。

如果有帮助,请告诉我。