简体   繁体   English

执行到特定目录中的 kube.netes pod

[英]Exec into kubernetes pod in a particular directory

How do I make this work?我如何使这项工作?

[alan@stormfather-0be642-default-1 ~]$ kubectl exec -it my-pod-0 -- bash -c "/bin/bash && cd /tmp"
[root@my-pod-0 /]# pwd
/

先更改目录,然后 sh 进入。

kubectl exec -it my-pod-0 -- bash -c "cd /tmp && /bin/bash"

Mohsin Amjad's answer is both simple and correct, if you are getting the Mohsin Amjad 的回答既简单又正确,如果你得到

..."bash": executable file not found in $PATH... ...“bash”:在 $PATH 中找不到可执行文件...

error, this just means the container inside the pod does not have bash installed, instead try sh or other shells.错误,这只是意味着 pod 内的容器没有安装 bash,而是尝试 sh 或其他 shell。 Ie something like:即是这样的:

kubectl exec -it my-pod-0 -- sh -c "cd /tmp && echo $0 $SHELL"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM