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.
Asked: 2023-03-04 11:00:00 +0000
Seen: 25 times
Last updated: Apr 18 '21