I'm trying to write a script that runs some commands inside the container using kubectl exec. I'd like to use the environment variables that exist inside the container, but struggling to figure out how to prevent my local shell from evaluating the var and still have it evaluated in the container.
This was my first try, but $MONGODB_ROOT_PASSWORD get evaluated by my local shell instead of inside the container:
kubectl -n enterprise exec mycontainer -- mongodump --username root --password $MONGODB_ROOT_PASSWORD --out /dump
I tried this, but the had the same issue with pipe, it was evaluated in my local instead of in the container:
kubectl -n enterprise exec mycontainer -- echo 'mongodump --username root --password $MONGODB_ROOT_PASSWORD --out /dump' | sh
Is there a way to do this with kubectl exec?
You need a sh -c
in there, like exec -- sh -c 'whatever $PASSWORD'
.