当我运行命令
kubectl exec -it backstage-test01-5d877c7f54-425s6 -n customer-namespaces -- /bin/bash
时,它返回此错误:
Defaulted container "linkerd-proxy" out of: linkerd-proxy, backstage-backend, linkerd-init (init)
error: Internal error occurred: error executing command in container: failed to exec in container: failed to start exec "eec3a58e120807f9dbea37e3c827850cc69690a4c0febd03ef6174b30a314fb7": OCI runtime exec failed: exec failed: unable to start container process: exec: "/bin/bash": stat /bin/bash: no such file or directory: unknown
这是我在 pod 的 Containers 选项卡中看到的视图。
我尝试在 kubernetes pod 内执行 shell,但收到错误消息“bin/bash:没有 sush 文件或目录:未知”
有时这个 Pod 会在 PodsCreation 上堆积并进入错误循环,如果你检查一下,你可能会发现那里有错误。你可以使用以下命令轻松检查它;
kubectl logs -f myPodName
从日志记录中 - 确保您的 Pod 正在运行,然后您可以执行类似的操作;
kubectl exec --stdin --tty myPodName -- sh
然后检查是否可以进入shell..
可能只是因为环境还没有安装bash?
例如(不确定你的 pod 环境):
kubectl exec -it backstage-test01-5d877c7f54-425s6 -n customer-namespaces -- apk add bash
快速检查:
kubectl exec -it backstage-test01-5d877c7f54-425s6 -n customer-namespaces -- sh -c 'which yum || which apt-get || which apk'
# e.g.
/sbin/apk
您的 Pod 中有两个容器:
linkerd-proxy
:Linkerd Sidecar 代理backstage-backend
:你的容器尝试指定容器而不是使用默认容器:
kubectl exec -it backstage-test01-5d877c7f54-425s6 -n customer-namespaces -c backstage-backend -- /bin/bash
为了避免将来出现这种情况,请在 pod 规范内的部署中添加以下注释(从 v1.21 开始提供):
kubectl.kubernetes.io/default-container
此注释将保证您访问正确的容器而不是
linkerd-proxy
参考资料: