I'm trying to run the following command:
kubectl exec vault-1 -- vault operator raft join -leader-ca-cert=`cat "$VAULT_CACERT"` https://vault-0.vault-internal:8200
The goal here is to get the contents of the cert file at the path stored in $VAULT_CACERT (variable on the pod) and pass that in as the -leader-ca-cert using kubectl. When I run I get cat: '': No such file or directory
which seems to indicate is possibly using my local machines env. Connecting to the pod and running the command that way does work.
I've tried a few different commands and I can seem to find a way to achieve what I want through kubectl. Is there a better way to pass this data in somehow?
CodePudding user response:
If the ENV
is inside the container, then you should not use backtick in the exec command. Use single quotes to avoid shell expansion on your local machine terminal.
so you can try something like below
kubectl exec vault-1 -- vault operator raft join -leader-ca-cert='cat "$VAULT_CACERT"' https://vault-0.vault-internal:8200
I tested out something like below and it seems working for me
kubectl exec demo -- sh -c 'cat "$FILE_PATH"'