Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
573 views
in Technique[技术] by (71.8m points)

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

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
question from:https://stackoverflow.com/questions/65857913/kubectl-exec-it-pod-getting-sh-cant-open-export-no-such-file-or-director

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share

2.1m questions

2.1m answers

62 comments

56.7k users

...