Ask Your Question
3

How can Kubernetes pods export environment variables using a command?

asked 2023-03-04 11:00:00 +0000

ladyg gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2021-04-18 03:00:00 +0000

nofretete gravatar image

Kubernetes pods can export environment variables using the env field in the pod specification. Here's an example:

apiVersion: v1
kind: Pod
metadata:
  name: my-pod
spec:
  containers:
  - name: my-container
    image: my-image
    env:
      - name: MY_ENV_VAR
        value: my-value

This will set the environment variable MY_ENV_VAR to my-value in the container my-container running in the my-pod pod.

If you want to export environment variables using a command, you can use the command and args fields in the container specification, like this:

apiVersion: v1
kind: Pod
metadata:
  name: my-pod
spec:
  containers:
  - name: my-container
    image: my-image
    command: ["sh", "-c", "export MY_ENV_VAR=my-value && <start your application>"]

This will run a shell command that exports the environment variable MY_ENV_VAR with the value my-value, and then starts your application.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-03-04 11:00:00 +0000

Seen: 25 times

Last updated: Apr 18 '21