简体   繁体   中英

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

..."bash": executable file not found in $PATH...

error, this just means the container inside the pod does not have bash installed, instead try sh or other shells. Ie something like:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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