为什么我进入 Kubernetes pod 时会出现 exec failed: container_linux.go:380?

Why I get exec failed: container_linux.go:380 when I go inside Kubernetes pod?

我开始学习 Kubernetes 并在 Windows 7.

上安装了 minikube 和 kubectl

之后我用命令创建了一个 pod:

kubectl run firstpod --image=nginx

一切都很好:

[![在此处输入图片描述][1]][1]

现在我想使用此命令进入 pod 内部:kubectl exec -it firstpod -- /bin/bash 但它不工作并且出现此错误:

OCI runtime exec failed: exec failed: container_linux.go:380: starting container
 process caused: exec: "C:/Program Files/Git/usr/bin/bash.exe": stat C:/Program
Files/Git/usr/bin/bash.exe: no such file or directory: unknown
command terminated with exit code 126

我该如何解决这个问题?

另一个问题是关于这个 firstpod 连播的。使用此命令 kubectl describe pod firstpod 我可以看到有关 pod 的信息:

Name:         firstpod
Namespace:    default
Priority:     0
Node:         minikube/192.168.99.100
Start Time:   Mon, 08 Nov 2021 16:39:07 +0200
Labels:       run=firstpod
Annotations:  <none>
Status:       Running
IP:           172.17.0.3
IPs:
  IP:  172.17.0.3
Containers:
  firstpod:
    Container ID:   docker://59f89dad2ddd6b93ac4aceb2cc0c9082f4ca42620962e4e692e3d6bcb47d4a9e
    Image:          nginx
    Image ID:       docker-pullable://nginx@sha256:644a70516a26004c97d0d85c7fe1d0c3a67ea8ab7ddf4aff193d9f301670cf36
    Port:           <none>
    Host Port:      <none>
    State:          Running
      Started:      Mon, 08 Nov 2021 16:39:14 +0200
    Ready:          True
    Restart Count:  0
    Environment:    <none>
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-9b8mx (ro)
Conditions:
  Type              Status
  Initialized       True
  Ready             True
  ContainersReady   True
  PodScheduled      True
Volumes:
  kube-api-access-9b8mx:
    Type:                    Projected (a volume that contains injected data from multiple sources)
    TokenExpirationSeconds:  3607
    ConfigMapName:           kube-root-ca.crt
    ConfigMapOptional:       <nil>
    DownwardAPI:             true
QoS Class:                   BestEffort
Node-Selectors:              <none>
Tolerations:                 node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
                             node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:
  Type    Reason     Age   From               Message
  ----    ------     ----  ----               -------
  Normal  Scheduled  32m   default-scheduler  Successfully assigned default/firstpod to minikube
  Normal  Pulling    32m   kubelet            Pulling image "nginx"
  Normal  Pulled     32m   kubelet            Successfully pulled image "nginx" in 3.677130128s
  Normal  Created    31m   kubelet            Created container firstpod
  Normal  Started    31m   kubelet            Started container firstpod

所以我可以看到它是一个 docker 容器 ID 并且它已启动,还有图像,但是如果我这样做 docker imagesdocker ps 则什么也没有。这些图像和容器在哪里?谢谢! [1]: https://i.stack.imgur.com/xAcMP.jpg

一个错误肯定是 gitbash 添加 Windows 路径。您可以使用双斜杠禁用它:

kubectl exec -it firstpod -- //bin/bash

此命令只有在图像中有 bash 时才有效。如果不这样做,则需要选择与 运行 不同的命令,例如/bin/sh。有些图像是无发行版的或基于 scratch 以明确不包含 shell 之类的东西,这将阻止您 运行ning 这样的命令(为了安全,有意)。