Exec into kubernetes pod in a particular directory

7/27/2021

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
/
-- subtleseeker
bash
kubernetes

1 Answer

7/27/2021

Change directory first and then sh into it.

kubectl exec -it my-pod-0 -- bash -c "cd /tmp && /bin/bash"
-- Mohsin Amjad
Source: StackOverflow