How to use environment variables with Kubernetes. With and without using secrets when you are deploying pods

What are we using environment variables for and when it makes sense to use secrets for environment variables in Kubernetes? And why not commit my .env file directly into my project?

I will explain why you should use environment variables in Kubernetes and not use the .env file directly into your container image and how you can make your environment variables easier to maintain in your Kubernetes cluster when you are using secrets.

Why not commit .env files to my build container image?

First of all, committing your .env file into a container build image will save your settings forever inside this container, it will be hard to change if you need to change database connection, change application name, and stuff like that.

If you see it from a security risk, you will store your settings in the git project, when you do this rest of the team will have access to all the production areas just by looking into the .env file, so you should really never commit your .env file even not when you are working with the container and build processing.

--

--

Paris Nakita Kejser
DevOps Engineer, Software Architect and Software Developering

DevOps Engineer, Software Architect, Software Developer, Data Scientist and identify me as a non-binary person.