4

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?

3 Answers 3

1

Docker containers require that you set environment variables when you run them:

https://docs.docker.com/engine/reference/commandline/run/#set-environment-variables--e---env---env-file

--env , -e      Set environment variables
Sign up to request clarification or add additional context in comments.

Comments

1

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.

1 Comment

Just realized its 1 year old post. If you know the answer to my issue please respond here.
1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.