kubernetes secrets files to environment variables kubernetes secrets files to environment variables kubernetes kubernetes

kubernetes secrets files to environment variables


I noted your use case in the feature request for exposing secrets as environment variables:https://github.com/kubernetes/kubernetes/issues/4710

It's mainly the quoting that makes this tricky in shell. The following worked for me interactively and should work in a script, but additional quoting would be needed if specified as an argument to "sh -c".

(ls -1 secretdir | while read var ; do echo export ${var}=$(cat secretdir/${var}) ; done; echo yourcommand) | sh -

There may be more elegant ways to do this.