Absolutely! Here’s a comprehensive list of the Top 100 most frequently used oc
(OpenShift CLI) commands, with a quick explanation for each. This will help you navigate OpenShift clusters efficiently, whether you’re a beginner or an experienced SRE/DevOps engineer.
Top 100 Most Frequently Used oc
Commands and Their Usage
Authentication & Context
oc login <server>
Authenticate to an OpenShift cluster.oc whoami
Show your current user.oc whoami -t
Display your current token.oc projects
List all available projects (namespaces).oc project <project>
Switch to a different project.oc logout
Log out of the current cluster.oc config view
Show kubeconfig details.oc config get-contexts
List contexts.oc config use-context <context>
Switch context.oc config set-context ...
Set context options.
General Cluster Info
oc status
See an overview of your project.oc get all
List all resources in the namespace.oc version
Show client and server versions.oc explain <resource>
Get documentation on a resource.oc api-resources
List all resource types.
Get & List Resources
oc get pods
List all pods.oc get pod <podname>
Show a specific pod.oc get deployments
List all deployments.oc get deployment <name>
Show a deployment.oc get svc
List services.oc get svc <name>
Show a service.oc get routes
List all routes.oc get route <name>
Show a specific route.oc get secrets
List all secrets.oc get configmaps
List configmaps.oc get nodes
List nodes in the cluster.oc get namespaces
List all namespaces.oc get events
Show recent events.oc get pv
List persistent volumes.oc get pvc
List persistent volume claims.oc get rs
List replica sets.oc get dc
List deployment configs (OpenShift classic).oc get builds
List builds.oc get buildconfigs
List build configs.oc get imagestreams
List image streams.
Create & Apply Resources
oc new-project <name>
Create a new project.oc new-app <image/template>
Deploy an app from an image or template.oc create -f <file.yaml>
Create resources from a YAML/JSON file.oc apply -f <file.yaml>
Apply a configuration to a resource by file.oc process -f <template.yaml>
Process a template.oc create secret generic ...
Create a generic secret.oc create configmap ...
Create a configmap.oc expose svc/<svc-name>
Create a route to a service.oc expose deployment/<deploy-name>
Expose a deployment as a service.
Update & Edit Resources
oc edit <resource> <name>
Edit a resource in your default editor.oc set image deployment/<name> <container>=<image>
Update container image.oc set resources ...
Update CPU/memory requests and limits.oc patch <resource> <name> -p '<json-patch>'
Patch a resource.oc annotate <resource> <name> <key>=<value>
Add annotation.oc label <resource> <name> <key>=<value>
Add label.
Delete Resources
oc delete pod <name>
Delete a pod.oc delete deployment <name>
Delete a deployment.oc delete svc <name>
Delete a service.oc delete route <name>
Delete a route.oc delete project <name>
Delete a project.oc delete -f <file.yaml>
Delete resources from file.
Resource Details & Troubleshooting
oc describe <resource> <name>
Show details about a resource.oc logs <pod>
Show logs for a pod.oc logs deployment/<name>
Show logs for a deployment.oc rsh <pod>
Open a remote shell into a pod.oc exec <pod> -- <command>
Execute a command in a pod.oc port-forward <pod> <local-port>:<pod-port>
Forward port from pod to local machine.oc cp <pod>:<src> <dest>
Copy files from pod to local (or vice versa).
Scaling & Rollout
oc scale deployment/<name> --replicas=3
Scale a deployment.oc rollout status deployment/<name>
Watch rollout status.oc rollout history deployment/<name>
View rollout history.oc rollout undo deployment/<name>
Roll back to previous revision.
Builds & Images
oc start-build <buildconfig>
Start a build.oc logs build/<buildname>
Show build logs.oc tag <src-image> <dest-image>
Tag images between streams.
Templates & Catalog
oc get templates
List templates.oc process <template>
Process a template.oc describe template <name>
Show details about a template.
Security & Policies
oc policy who-can <verb> <resource>
See who can do what.oc adm policy add-role-to-user <role> <user>
Add a role to a user.oc adm policy remove-role-from-user <role> <user>
Remove role from user.oc adm policy add-scc-to-user <scc> <user>
Add Security Context Constraint.
Admin & Diagnostics
oc adm top pods
Show pod resource usage.oc adm top nodes
Show node resource usage.oc adm diagnostics
Run diagnostic checks.oc adm prune images
Prune old images.oc adm manage-node <node> ...
Node management commands.oc adm node-logs <node>
Show logs from a node.
Miscellaneous
oc get jobs
List jobs.oc get cronjobs
List cron jobs.oc create job ...
Create a new job.oc debug node/<node>
Start a debug pod on node.oc run ...
Run a new pod.oc set env <resource> <KEY>=<VAL>
Set environment variable(s).oc set volume ...
Attach/detach volumes.oc get networkpolicies
List network policies.oc get serviceaccounts
List service accounts.oc get endpoints
List endpoints.oc get ingress
List ingresses.oc create role ...
Create a role.oc create rolebinding ...
Bind a role.oc explain <resource> --recursive
Show full resource documentation.oc set probe deployment/<name> ...
Set liveness/readiness probes.oc set selector ...
Update resource selector.oc set serviceaccount <resource> <serviceaccount>
Set service account for deployment/pod.
Tips
- Use
-n <namespace>
to specify a namespace/project for any command. - Use
-o yaml|json|wide
to output in different formats. - Tab completion works great for
oc
!
Bonus: Get All Resource Types
oc api-resources
I’m a DevOps/SRE/DevSecOps/Cloud Expert passionate about sharing knowledge and experiences. I have worked at Cotocus. I share tech blog at DevOps School, travel stories at Holiday Landmark, stock market tips at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at TrueReviewNow , and SEO strategies at Wizbrand.
Do you want to learn Quantum Computing?
Please find my social handles as below;
Rajesh Kumar Personal Website
Rajesh Kumar at YOUTUBE
Rajesh Kumar at INSTAGRAM
Rajesh Kumar at X
Rajesh Kumar at FACEBOOK
Rajesh Kumar at LINKEDIN
Rajesh Kumar at WIZBRAND