Este conteúdo não está disponível no idioma selecionado.

Chapter 23. Managing Environment Variables


23.1. Overview

You can set, unset or list environment variables in pods or pod templates using the oc env command.

23.2. CLI Interface

OpenShift provides the oc env command to set or unset environment variables for objects that have a pod template, such as replication controllers or deployment configurations. It can also list environment variables in pods or any object that has a pod template.

The oc env command uses the following general syntax:

$ oc env <object-selection> <environment-variables> [options]
Copy to Clipboard Toggle word wrap

There are several ways to express <object-selection>.

Expand
SyntaxDescriptionExample

<object-type> <object-name>

Selects <object-name> of type <object-type>.

dc registry

<object-type>/<object-name>

Selects <object-name> of type <object-type>.

dc/registry

<object-type> --selector=<object-label-selector>

Selects objects of type <object-type> that match <object-label-selector>.

dc --selector="name=registry"

<object-type> --all

Selects all objects of type <object-type>.

dc --all

-f, --filename=<ref>

Look in <ref> — a filename, directory name, or URL — for the definition of the object to edit.

-f registry-dc.json

Supported common options for set, unset or list environment variables:

Expand
OptionDescription

-c, --containers [<name>]

Select containers by <name>. You can use asterisk (*, U+2A) as a wildcard. If unspecified, <name> defaults to *.

-o, --output <format>

Display the changed objects in <format> — either json or yaml — instead of updating them on the server. This option is incompatible with --list.

--output-version <api-version>

Output the changed objects with <api-version> instead of the default API version.

--resource-version <version>

Proceed only if <version> matches the current resource-version in the object. This option is valid only when specifying a single object.

23.3. Set Environment Variables

To set environment variables in the pod templates:

$ oc env <object-selection> KEY_1=VAL_1 ... KEY_N=VAL_N [<set-env-options>] [<common-options>]
Copy to Clipboard Toggle word wrap

Set environment options:

Expand
OptionDescription

-e, --env=<KEY>=<VAL>

Set given key value pairs of environment variables.

--overwrite

Confirm updating existing environment variables.

In the following example, both commands modify environment variable STORAGE in the deployment config registry. The first adds, with value /data. The second updates, with value /opt.

$ oc env dc/registry STORAGE=/data
$ oc env dc/registry --overwrite STORAGE=/opt
Copy to Clipboard Toggle word wrap

The following example finds environment variables in the current shell whose names begin with RAILS_ and adds them to the replication controller r1 on the server:

$ env | grep RAILS_ | oc env rc/r1 -e -
Copy to Clipboard Toggle word wrap

The following example does not modify the replication controller defined in file rc.json. Instead, it writes a YAML object with updated environment STORAGE=/local to new file rc.yaml.

$ oc env -f rc.json STORAGE=/opt -o yaml > rc.yaml
Copy to Clipboard Toggle word wrap

23.4. Unset Environment Variables

To unset environment variables in the pod templates:

$ oc env <object-selection> KEY_1- ... KEY_N- [<common-options>]
Copy to Clipboard Toggle word wrap
Important

The trailing hyphen (-, U+2D) is required.

This example removes environment variables ENV1 and ENV2 from deployment config d1:

$ oc env dc/d1 ENV1- ENV2-
Copy to Clipboard Toggle word wrap

This removes environment variable ENV from all replication controllers:

$ oc env rc --all ENV-
Copy to Clipboard Toggle word wrap

This removes environment variable ENV from container c1 for replication controller r1:

$ oc env rc r1 --containers='c1' ENV-
Copy to Clipboard Toggle word wrap

23.5. List Environment Variables

To list environment variables in pods or pod templates:

$ oc env <object-selection> --list [<common-options>]
Copy to Clipboard Toggle word wrap

This example lists all environment variables for pod p1:

$ oc env pod/p1 --list
Copy to Clipboard Toggle word wrap
Voltar ao topo
Red Hat logoGithubredditYoutubeTwitter

Aprender

Experimente, compre e venda

Comunidades

Sobre a documentação da Red Hat

Ajudamos os usuários da Red Hat a inovar e atingir seus objetivos com nossos produtos e serviços com conteúdo em que podem confiar. Explore nossas atualizações recentes.

Tornando o open source mais inclusivo

A Red Hat está comprometida em substituir a linguagem problemática em nosso código, documentação e propriedades da web. Para mais detalhes veja o Blog da Red Hat.

Sobre a Red Hat

Fornecemos soluções robustas que facilitam o trabalho das empresas em plataformas e ambientes, desde o data center principal até a borda da rede.

Theme

© 2025 Red Hat