Questo contenuto non è disponibile nella lingua selezionata.

Chapter 33. Managing Environment Variables


33.1. Setting and Unsetting Environment Variables

OpenShift Container Platform provides the oc set 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. This command can also be used on BuildConfig objects.

33.2. List Environment Variables

To list environment variables in pods or pod templates:

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

This example lists all environment variables for pod p1:

$ oc set env pod/p1 --list
Copy to Clipboard Toggle word wrap

33.3. Set Environment Variables

To set environment variables in the pod templates:

$ oc set 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 set env dc/registry STORAGE=/data
$ oc set 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 set 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 set env -f rc.json STORAGE=/opt -o yaml > rc.yaml
Copy to Clipboard Toggle word wrap

33.3.1. Automatically Added Environment Variables

Expand
Table 33.1. Automatically Added Environment Variables
Variable Name

<SVCNAME>_SERVICE_HOST

<SVCNAME>_SERVICE_PORT

Example Usage

The service KUBERNETES which exposes TCP port 53 and has been allocated cluster IP address 10.0.0.11 produces the following environment variables:

KUBERNETES_SERVICE_PORT=53
MYSQL_DATABASE=root
KUBERNETES_PORT_53_TCP=tcp://10.0.0.11:53
KUBERNETES_SERVICE_HOST=10.0.0.11
Copy to Clipboard Toggle word wrap
Note

Use the oc rsh command to SSH into your container and run oc set env to list all available variables.

33.4. Unset Environment Variables

To unset environment variables in the pod templates:

$ oc set 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 set env dc/d1 ENV1- ENV2-
Copy to Clipboard Toggle word wrap

This removes environment variable ENV from all replication controllers:

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

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

$ oc set env rc r1 --containers='c1' ENV-
Copy to Clipboard Toggle word wrap
Torna in cima
Red Hat logoGithubredditYoutubeTwitter

Formazione

Prova, acquista e vendi

Community

Informazioni sulla documentazione di Red Hat

Aiutiamo gli utenti Red Hat a innovarsi e raggiungere i propri obiettivi con i nostri prodotti e servizi grazie a contenuti di cui possono fidarsi. Esplora i nostri ultimi aggiornamenti.

Rendiamo l’open source più inclusivo

Red Hat si impegna a sostituire il linguaggio problematico nel codice, nella documentazione e nelle proprietà web. Per maggiori dettagli, visita il Blog di Red Hat.

Informazioni su Red Hat

Forniamo soluzioni consolidate che rendono più semplice per le aziende lavorare su piattaforme e ambienti diversi, dal datacenter centrale all'edge della rete.

Theme

© 2025 Red Hat