无法在Kubernetes Pod中执行Shell命令的问题求助
解决Kubectl Exec提示"/bin/bash: no such file or directory"的问题
问题根源
执行命令时Kubernetes默认选择了linkerd-proxy容器,该容器的基础镜像未包含bash;而你实际需要进入的是backstage-backend容器。
具体解决方案
指定目标容器执行bash
明确指定要进入的backstage-backend容器,执行命令:kubectl exec -it backstage-test01-5d877c7f54-425s6 -n customer-namespaces -c backstage-backend -- /bin/bash若backstage-backend无bash,改用sh
部分轻量级镜像(如Alpine)仅提供sh而非bash,替换命令:kubectl exec -it backstage-test01-5d877c7f54-425s6 -n customer-namespaces -c backstage-backend -- /bin/sh确认容器内可用shell
不确定容器有哪些shell时,先查询:kubectl exec backstage-test01-5d877c7f54-425s6 -n customer-namespaces -c backstage-backend -- which bash sh根据返回的可用路径,替换到exec命令中即可。
内容的提问来源于stack exchange,提问作者Ghassen
相关产品推荐
相关产品推荐

