Kubectl:获取 Windows 下正在运行的容器的 shell

9il*_*0lo 3 windows shell kubectl

根据https://kubernetes.io/docs/tasks/debug-application-cluster/get-shell-running-container/ 中的说明,我正在尝试使用 Kubectl 登录正在运行的容器,但我失败了:

kubectl exec -it mycontainer -- /bin/bash
Run Code Online (Sandbox Code Playgroud)

无法使用 TTY - 输入不是终端或正确类型的文件 rpc 错误:代码 = 2 desc = oci 运行时错误:exec 失败:container_linux.go:247:启动容器进程导致“exec:\”D:/ Applications/Git/usr/bin/bash\": stat D:/Applications/Git/usr/bin/bash: no such file or directory"

命令以退出代码 126 终止

看起来 kubectl 试图在我的机器上执行 bash,这完全不是我想要实现的。

我可以执行没有空格的命令:

$ kubectl exec mycontainer 'ls'
lib
start.sh
Run Code Online (Sandbox Code Playgroud)

但没有:

$ kubectl exec mycontainer 'ls .'
rpc error: code = 2 desc = oci runtime error: exec failed: container_linux.go:247: starting container process caused "exec: \"ls .\": executable file not found in $PATH"

command terminated with exit code 126
Run Code Online (Sandbox Code Playgroud)

我做错了什么?

我已经在 mingw git shell 中尝试过,就像普通的 Windows 控制台一样。

aur*_*ius 7

似乎它可能与这个 github问题有关。

其中一个解决方法可能是按规定使用winpty这里
winpty kubectl.exe exec -it pod-name -- sh

您也可以尝试/bin/sh代替/bin/bash它对我有用,但是我没有 Windows 机器可以在与您相同的环境中检查它。

  • 请注意,无论是 Windows 的 bash 还是 Windows 的“cmd”,“/bin/sh”都不是更好。 (2认同)