This documentation is for a release that is no longer maintained
See documentation for the latest supported version 3 or the latest supported version 4.이 콘텐츠는 선택한 언어로 제공되지 않습니다.
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]
$ oc env <object-selection> <environment-variables> [options]
There are several ways to express <object-selection>
.
Syntax | Description | Example |
---|---|---|
| Selects <object-name> of type <object-type>. |
|
| Selects <object-name> of type <object-type>. |
|
| Selects objects of type <object-type> that match <object-label-selector>. |
|
| Selects all objects of type <object-type>. |
|
| Look in <ref> — a filename, directory name, or URL — for the definition of the object to edit. |
|
Supported common options for set, unset or list environment variables:
Option | Description |
---|---|
|
Select containers by |
|
Display the changed objects in |
|
Output the changed objects with |
|
Proceed only if |
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>]
$ oc env <object-selection> KEY_1=VAL_1 ... KEY_N=VAL_N [<set-env-options>] [<common-options>]
Set environment options:
Option | Description |
---|---|
| Set given key value pairs of environment variables. |
| 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
$ oc env dc/registry STORAGE=/data
$ oc env dc/registry --overwrite STORAGE=/opt
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 -
$ env | grep RAILS_ | oc env rc/r1 -e -
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
$ oc env -f rc.json STORAGE=/opt -o yaml > rc.yaml
23.4. Unset Environment Variables 링크 복사링크가 클립보드에 복사되었습니다!
To unset environment variables in the pod templates:
oc env <object-selection> KEY_1- ... KEY_N- [<common-options>]
$ oc env <object-selection> KEY_1- ... KEY_N- [<common-options>]
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-
$ oc env dc/d1 ENV1- ENV2-
This removes environment variable ENV
from all replication controllers:
oc env rc --all ENV-
$ oc env rc --all ENV-
This removes environment variable ENV
from container c1
for replication controller r1
:
oc env rc r1 --containers='c1' ENV-
$ oc env rc r1 --containers='c1' ENV-
23.5. List Environment Variables 링크 복사링크가 클립보드에 복사되었습니다!
To list environment variables in pods or pod templates:
oc env <object-selection> --list [<common-options>]
$ oc env <object-selection> --list [<common-options>]
This example lists all environment variables for pod p1
:
oc env pod/p1 --list
$ oc env pod/p1 --list