0

I have an environment variable file that is declared like following inside a deployment.yaml file:

          env:
            - name: NATS_CLIENT_ID
              valueFrom:
                fieldRef:
                  fieldPath: metadata.name

I am just wondering to know if I want to use an .env file instead of the deployment.yaml file, how can I declare the above port within the .env?

best_of_man
  • 643
  • 2
  • 15
  • 1
    Where would this `.env` file be? I suspect it isn't possible, since a `.env` file would normally contain only static values but this YAML block gives the environment variable a different dynamic value for each pod. – David Maze Jan 14 '23 at 11:55
  • @DavidMaze: Yes I think I should manually define different variables for each pad within the `.env` file. – best_of_man Jan 14 '23 at 17:29

1 Answers1

2

Maybe you can create a configmap that contains your .env and use your configmap to inject the environment variables.

An example here: https://humanitec.com/blog/handling-environment-variables-with-kubernetes

pida
  • 328
  • 3
  • 12