oc cheat sheet: everyday OpenShift CLI commands
The oc commands you use every day, grouped by task: login and projects, apps and builds, routes, config, debugging, permissions and admin checks. Everything kubectl does works with oc too.
Drafted with AI from official documentation. Scripts were run in a test environment and repository links verified. Awaiting a human check. Did it work for you? Last edited Outdated?
oc contains all of kubectl, so get, describe, apply, logs, exec and the rest behave as you know them. This sheet focuses on the commands and flags that are specific to OpenShift or most useful there. Add -n PROJECT to any project-scoped command to run it somewhere other than the current project.
Session and projects
oc login https://api.cluster.example.com:6443 -u developer
oc login https://api.cluster.example.com:6443 --web
oc whoami
oc logout
oc projects
oc project shop-dev
oc new-project shop-dev --display-name="Shop (dev)"
oc status --suggest
Create applications
oc new-app registry.access.redhat.com/ubi9/httpd-24 --name=web
oc new-app registry.access.redhat.com/ubi9/python-311~https://github.com/example/api.git --name=api
oc new-app https://github.com/example/app.git --strategy=docker
oc new-app --list
oc new-app -f template.yaml -p PARAM=value
Builds and image streams
oc get bc,builds,is
oc start-build api --follow
oc start-build api --from-dir=.
oc logs -f bc/api
oc cancel-build bc/api
oc tag api:latest api:prod
oc import-image api --all
Deployments
oc get deploy,rs,pods -o wide
oc rollout status deployment/web
oc rollout restart deployment/web
oc rollout undo deployment/web
oc scale deployment/web --replicas=3
oc set image deployment/web web=registry.example.com/web:1.2
oc set resources deployment/web --limits=cpu=500m,memory=512Mi
oc set probe deployment/web --readiness --get-url=http://:8080/healthz
Routes and services
oc expose service/web
oc create route edge web --service=web --insecure-policy=Redirect
oc create route passthrough web-tls --service=web --port=8443
oc create route reencrypt web-secure --service=web
oc get route web -o jsonpath='{.spec.host}'
Configuration and storage
oc create configmap web-config --from-file=app.properties
oc create secret generic db-cred --from-env-file=db.env
oc set env deployment/web --from=secret/db-cred --prefix=DB_
oc set env deployment/web --list
oc set data secret/db-cred password=CHANGE_ME
oc set volume deployment/web --add --name=data --type=persistentVolumeClaim --claim-name=web-data --mount-path=/data
oc set volume deployment/web
oc extract secret/db-cred --to=-
Debugging
oc get events --sort-by=.lastTimestamp
oc describe pod POD
oc logs POD --previous
oc logs -f deployment/web --all-containers
oc rsh POD
oc exec POD -- env
oc debug deployment/web
oc port-forward svc/web 8080:8080
oc rsync POD:/var/log/app ./logs
oc debug starts a copy of the pod with a shell instead of the normal command, which is ideal for a container that crashes on start.
Permissions
oc auth can-i create deployments -n shop-dev
oc auth can-i list pods -n shop-dev --as=system:serviceaccount:shop-dev:builder
oc adm policy add-role-to-user edit alice -n shop-dev
oc adm policy who-can delete pods -n shop-dev
oc get rolebindings -n shop-dev
oc get pod POD -o jsonpath='{.metadata.annotations.openshift\.io/scc}'
Cluster administration (cluster-admin)
oc get clusterversion
oc adm upgrade
oc get clusteroperators
oc get nodes -o wide
oc adm top nodes
oc get machineconfigpools
oc get csr
oc adm cordon NODE
oc adm drain NODE --ignore-daemonsets --delete-emptydir-data
oc adm uncordon NODE
oc debug node/NODE
oc adm must-gather
Warning: oc adm drain evicts every pod from a node and --delete-emptydir-data discards their emptyDir data. Check what runs there first with oc get pods -A -o wide --field-selector spec.nodeName=NODE.
Output tricks
oc get pods -o wide
oc get deployment web -o yaml
oc get pods -o jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.status.phase}{"\n"}{end}'
oc get pods -l app=web --show-labels
oc explain route.spec.tls
oc api-resources | grep openshift.io
Official documentation
Did this work for you?
No votes yet. Be the first.
If it did not work, the report form below tells the editors what went wrong.
See also
- 0150 Logging in with oc and working with OpenShift projects Install the oc client, log in with a password, browser or token, then create, switch and inspect projects. Covers where oc stores… Beginner · Step by step · Any system Article Concepts · Deploying applications 15 Oct 2026
- 0151 Tutorial: deploy a small web app on OpenShift and expose it with a Route A step-by-step first deployment: create a project, build a static website from Git with Source-to-Image, publish it on an HTTPS Route, then… Beginner · Step by step · Any system Article Deploying applications 15 Oct 2026
- 0152 Build and deploy from source with oc new-app and Source-to-Image How oc new-app turns a Git repository or an image into a running app, how Source-to-Image and Docker builds are chosen, and… Intermediate · Step by step · Any system Article Deploying applications 15 Oct 2026
- 0153 Expose apps with OpenShift Routes: edge, passthrough and re-encrypt TLS A Route publishes a service on a host name through the OpenShift router. Learn when to use plain HTTP, edge, passthrough or… Intermediate · Step by step · Any system Article Deploying applications · Ingress & networking 15 Oct 2026
- 0154 OpenShift app configuration: environment, ConfigMaps, Secrets and persistent storage Set environment variables, load ConfigMaps and Secrets into a Deployment as variables or files, and give it persistent storage with a PersistentVolumeClaim,… Intermediate · Step by step · Any system Article Config, secrets & storage · Deploying applications 15 Oct 2026
- 0158 Collect an OpenShift project report with oc A read-only bash script that gathers a project's workloads, pods, routes, builds, storage and warning events, plus describe output and logs of… Intermediate · Step by step · Linux, macOS Script Deploying applications · Troubleshooting 15 Oct 2026
Repos in the wild
- openshift/oc: the OpenShift command line client openshift/oc Source code of oc, the OpenShift CLI. It is built on top of kubectl, so it can do everything kubectl does, and adds commands for projects, builds, routes, image streams and cluster administration. GitHub
History
Every saved edit is kept. The plot on the sleeve draws one line per edit. Open any edit to see exactly what changed.
- Dominik +3,939 chars