kubectl exec -it <POD> getting sh: can't open 'export': No such file or directory

1/23/2021

i try to execute this command :

alias kubectl_winpty='winpty kubectl'   ( using winpty due to [bug][1] 
kubectl_winpty exec -it vault-0 -n vault-xxx -- sh export VAULT_CACERT=/vault/userconfig/vault-tls/vault.ca

but I'm getting this error :

sh: can't open 'export': No such file or directory
command terminated with exit code 2

the pod do exist and running

$ kubectl get pods vault-0 -n vault-xxx
NAME      READY   STATUS    RESTARTS   AGE
vault-0   0/1     Running   0          17m
-- user63898
kubectl
kubernetes
sh

1 Answer

1/23/2021

I guess sh export makes shell to assume export as a filename (some script that shell will run). Hence the error can't open 'export': No such file or directory.

Try to make use of -c option.

kubectl_winpty exec -it vault-0 -n vault-xxx -- sh -c "export VAULT_CACERT=/vault/userconfig/vault-tls/vault.ca"

Also it's better to set env variable when you create this pod.

Also make sure your pod is healthy and in ready state, which is not the case as per kubectl get output.

-- mchawre
Source: StackOverflow