CloudsArk
oc Commands Openshift

oc Set Env Examples

Learn practical oc set env examples with oc commands, OpenShift manifests, verification steps, common mistakes, and production-focused guidance.

oc Set Env Examples

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.

When You Need This Command

Use this command when you need to inspect, change, or verify OpenShift resources from the terminal without relying on the web console.

Syntax

oc <command> <resource> [name] -n <project>

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

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

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.

Production Notes

Run read-only commands first, check the active project, and prefer declarative manifests for repeatable changes.

Example YAML

apiVersion: apps/v1
kind: Deployment
metadata:
  name: web
spec:
  template:
    spec:
      containers:
        - name: web
          env:
            - name: APP_MODE
              value: production

Quick Checklist

  • Set the variable on the intended workload.
  • Watch the rollout.
  • Verify the variable inside a new pod.
  • Store sensitive values in Secrets.

Summary

oc Set Env Examples is most useful when paired with verification. Check the project, run the command against the intended object, and confirm the resulting OpenShift state.