We’re defining some environment variables in kubernetes pods and when i try to use them in either node or React FE code using process.env.TEST(as TEST is present in env as secrets), i always got undefined but when i see variables on pods it was there.
Is there any other way to access those variables or we need to do something explicitly either on Node.js or React.js.
2
Answers
Environment variables in a Kubernetes pod can be accessed in Node.js using
process.env.<VARIABLE_NAME>
, similar to how you’d access them in any Node.js application. You are doing it the right way, so if the values are undefined, then something might not be set up correctly.React Environment Variables: If you’re trying to use the environment variables in a React app, they need to be prefixed with
REACT_APP_
. Only environment variables that start with this prefix will be embedded into the build. So you’ll access them in your code usingprocess.env.REACT_APP_<VARIABLE_NAME>
.The secrets for frontend service like react, secrets must to be passed during the build time i.e while building the docker image
we build react apps and also call secrets from the vault during build time and it works.
pipeline steps for frontend apps should be :
hope this helps you