Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Advice on setting environment variables for a process in a container #40394

Closed
xlouba opened this issue Mar 29, 2023 · 7 comments
Closed

Advice on setting environment variables for a process in a container #40394

xlouba opened this issue Mar 29, 2023 · 7 comments
Labels
kind/support Categorizes issue or PR as a support question. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one.

Comments

@xlouba
Copy link

xlouba commented Mar 29, 2023

kubernetes can define environment variable for container with name and value.
env: - name: DEMO_GREETING value: "Hello from the environment" - name: DEMO_FAREWELL value: "Such a sweet sorrow"
How can I define the variable by executing command like this:
env: - name: DEMO_GREETING value: "$(cat demo_greeting.md)"

@k8s-ci-robot k8s-ci-robot added the needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. label Mar 29, 2023
@k8s-ci-robot
Copy link
Contributor

This issue is currently awaiting triage.

SIG Docs takes a lead on issue triage for this website, but any Kubernetes member can accept issues by applying the triage/accepted label.

The triage/accepted label can be added by org members by writing /triage accepted in a comment.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@sftim
Copy link
Contributor

sftim commented Mar 29, 2023

/kind support
/retitle Advice on setting environment variables for a process in a container

@k8s-ci-robot k8s-ci-robot changed the title Define environment variables for a container by executing linux commands Advice on setting environment variables for a process in a container Mar 29, 2023
@k8s-ci-robot k8s-ci-robot added the kind/support Categorizes issue or PR as a support question. label Mar 29, 2023
@utkarsh-singh1
Copy link
Contributor

Hey @xlouba, you can find about setting env variables and use them with the bash commands here -
https://kubernetes.io/docs/tasks/inject-data-application/define-environment-variable-container/#using-environment-variables-inside-of-your-config

@utkarsh-singh1
Copy link
Contributor

You can also try like this -

In terminal -

  1. Setting environment varible -
export hello="cat demo_greeting.md"
  1. Invoking it -
$hello

In k8s Yaml -

# setting env variable
env:
    - name: DEMO_GREETING
      value: "cat demo_greeting.md"

# Invoking it
command: [$DEMO_GREETING]

@xlouba
Copy link
Author

xlouba commented Mar 30, 2023

You can also try like this -

In terminal -

  1. Setting environment varible -
export hello="cat demo_greeting.md"
  1. Invoking it -
$hello

In k8s Yaml -

# setting env variable
env:
    - name: DEMO_GREETING
      value: "cat demo_greeting.md"

# Invoking it
command: [$DEMO_GREETING]

Thanks! However, it seems that definitions like this in yaml can only execute commands, rather than assigning the results of command execution to variable DEMO_GREETING. Is there any way to assign the results of command execution to environment variables?

@utkarsh-singh1
Copy link
Contributor

Hi @xlouba, then u can use it as

export DEMO_GREETING=$(cat demo_greeting.md)

@xlouba
Copy link
Author

xlouba commented Mar 31, 2023

Ok, I see. I will take this way. Thank you!

@xlouba xlouba closed this as completed Mar 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/support Categorizes issue or PR as a support question. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one.
Projects
None yet
Development

No branches or pull requests

4 participants