OpenShift - Create deployment environment variables

If you are not familiar with the oc command, refer to OpenShift - Getting Started with the oc command.

There are different ways to configure a container with environment variables.

The oc set env command can be used to create environment variables for a deployment. You could also update a replica set, but this is kind of uncommon, and results in the creation of a new replica set that contains the environment variable, and the pods associated with the replica set will not have the environment variable.

~]$ oc set env deployment my-deployment my-environment-variable="Hello World"
deployment.apps/my-deployment updated

 

The oc set env command simply updates the deployments template YAML file to have the environment variable, so you could just as well use the oc edit command to update a deployments template YAML file to have the environment variable.

spec:
  containers:
  - name: my-app
    env:
    - name: my-environment-variable
      value: Hello World

 

A new pod should immediately be created after the oc edit or oc set env commands have been issued, which can be seen with the AGE of the oc get pods command.

~]# oc get pods
NAME            READY   STATUS     RESTARTS  AGE
my-pod-276pc    1/1     Running    0         22s

 

And the oc describe pod command can be used to see that the pod is now has the environment variable.

~]$ oc describe pod my-pod-276pc
Containers:
  my-container:
    Environment:
      my-environment-variable:  Hello World

 

The oc set env command with the --list option can be used the list the environment variables associate with the deployment.

~]$ oc set env deployment my-deployment --list
my-environment-variable=Hello World

 

And the pod.

~]$ oc set env pod my-pod-276pc --list
my-environment-variable=Hello World

 

And the replica set.

~]$ oc set env replicaset my-deployment-5755cd7b85 --list
my-environment-variable=Hello World

 

Also, the oc exec command and the env or printenv command can be used to see if the "my_secret" variable contains a value of "Hello" in the container.

~]$ oc exec/my-pod-276pc -- env
my-environment-variable=Hello World

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee

Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.





Please enter 446d6 in the box below so that we can be sure you are a human.




Comments

Web design by yours truely - me, myself, and I   |   jeremy.canfield@freekb.net   |