Reputation: 195
I have two different projects checked in Gitlab, frontend and backend. For both the projects i have a Dockerfile each. I have set the env variables in gitlab ci/cd . I am running docker container in kubernetes, but i am not able to access the gitlab env variables either in my react or node.js (express) application.
I was thinking that those env variable would be available to me when i do process.env.variable_name, but i am not able to access them.
What’s the best way to access Gitlab env variables in kubernetes (deployment.yaml) env variables ?
UPDATE
I have found that we can specify env variables in kubernetes, deployment.yaml file (under env section). How can i pass gitlab env variables to deployment.yaml?
Upvotes: 4
Views: 2703
Reputation: 2102
To inject environment variables to a react app created with create-react-app you should add the prefix REACT_APP_ to every env var.
During the build, webpack will pick all the environment variables with that prefix and will add them to environment.
Upvotes: 1
Reputation: 21
I was able to access environment variable in Node js application using Gitlab K8S_SECRET_
variable naming convention.
For example define a variable like K8S_SECRET_MY_TEST_API
in gitlab.
In Node js, you can access this variable using process.env.MY_TEST_API
.
Only issue I am facing is that those variables are not available in React app. Still trying to figure that out. I will update here once I resolve that issue.
Upvotes: 1
Reputation: 1957
Docker containers require that you set environment variables when you run them:
--env , -e Set environment variables
Upvotes: 1