OpenShift Set Env Example¶
Introduction¶
oc set env updates environment variables on a Deployment, DeploymentConfig, or pod template. Use it for small runtime configuration changes, then watch the rollout to confirm new pods picked up the value.
Before You Start¶
Make sure you are in the correct project and know whether the application is driven by a Deployment, DeploymentConfig, BuildConfig, ImageStream, or external registry image.
Practical Examples¶
oc set env deployment/web APP_MODE=production -n app
oc rollout status deployment/web -n app
oc set env deployment/web --list -n app
oc describe deployment web -n app
Example output:
deployment.apps/web updated
Waiting for deployment "web" rollout to finish: 1 old replicas are pending termination...
deployment "web" successfully rolled out
Example YAML¶
apiVersion: apps/v1
kind: Deployment
metadata:
name: web
spec:
template:
spec:
containers:
- name: web
env:
- name: APP_MODE
value: production
Verification¶
oc set env deployment/web --list -n app
oc get pods -n app -l app=web
oc exec deploy/web -n app -- printenv APP_MODE
Troubleshooting¶
Check the current environment values, update only the intended workload, watch the rollout, and confirm the new pod sees the expected variable.
Common Mistakes¶
- Setting secrets as plain environment values instead of using Secret references.
- Forgetting that changing pod template environment triggers a rollout.
- Updating the wrong workload because the project was incorrect.
Quick Checklist¶
- Set the variable on the intended workload.
- Watch the rollout.
- Verify the variable inside a new pod.
- Store sensitive values in Secrets.
Related Guides¶
- Openshift New App Explained
- Openshift Imagestream Explained
- Openshift Application Deployment Checklist
Summary¶
OpenShift Set Env Example should be verified with commands that match the OpenShift object being changed or investigated.