Upgrade & Secure Your Future with DevOps, SRE, DevSecOps, MLOps!

We spend hours scrolling social media and waste money on things we forget, but won’t spend 30 minutes a day earning certifications that can change our lives.
Master in DevOps, SRE, DevSecOps & MLOps by DevOpsSchool!

Learn from Guru Rajesh Kumar and double your salary in just one year.


Get Started Now!

Openshift: Top oc Commands

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

  1. oc login <server>
    Authenticate to an OpenShift cluster.
  2. oc whoami
    Show your current user.
  3. oc whoami -t
    Display your current token.
  4. oc projects
    List all available projects (namespaces).
  5. oc project <project>
    Switch to a different project.
  6. oc logout
    Log out of the current cluster.
  7. oc config view
    Show kubeconfig details.
  8. oc config get-contexts
    List contexts.
  9. oc config use-context <context>
    Switch context.
  10. oc config set-context ...
    Set context options.

General Cluster Info

  1. oc status
    See an overview of your project.
  2. oc get all
    List all resources in the namespace.
  3. oc version
    Show client and server versions.
  4. oc explain <resource>
    Get documentation on a resource.
  5. oc api-resources
    List all resource types.

Get & List Resources

  1. oc get pods
    List all pods.
  2. oc get pod <podname>
    Show a specific pod.
  3. oc get deployments
    List all deployments.
  4. oc get deployment <name>
    Show a deployment.
  5. oc get svc
    List services.
  6. oc get svc <name>
    Show a service.
  7. oc get routes
    List all routes.
  8. oc get route <name>
    Show a specific route.
  9. oc get secrets
    List all secrets.
  10. oc get configmaps
    List configmaps.
  11. oc get nodes
    List nodes in the cluster.
  12. oc get namespaces
    List all namespaces.
  13. oc get events
    Show recent events.
  14. oc get pv
    List persistent volumes.
  15. oc get pvc
    List persistent volume claims.
  16. oc get rs
    List replica sets.
  17. oc get dc
    List deployment configs (OpenShift classic).
  18. oc get builds
    List builds.
  19. oc get buildconfigs
    List build configs.
  20. oc get imagestreams
    List image streams.

Create & Apply Resources

  1. oc new-project <name>
    Create a new project.
  2. oc new-app <image/template>
    Deploy an app from an image or template.
  3. oc create -f <file.yaml>
    Create resources from a YAML/JSON file.
  4. oc apply -f <file.yaml>
    Apply a configuration to a resource by file.
  5. oc process -f <template.yaml>
    Process a template.
  6. oc create secret generic ...
    Create a generic secret.
  7. oc create configmap ...
    Create a configmap.
  8. oc expose svc/<svc-name>
    Create a route to a service.
  9. oc expose deployment/<deploy-name>
    Expose a deployment as a service.

Update & Edit Resources

  1. oc edit <resource> <name>
    Edit a resource in your default editor.
  2. oc set image deployment/<name> <container>=<image>
    Update container image.
  3. oc set resources ...
    Update CPU/memory requests and limits.
  4. oc patch <resource> <name> -p '<json-patch>'
    Patch a resource.
  5. oc annotate <resource> <name> <key>=<value>
    Add annotation.
  6. oc label <resource> <name> <key>=<value>
    Add label.

Delete Resources

  1. oc delete pod <name>
    Delete a pod.
  2. oc delete deployment <name>
    Delete a deployment.
  3. oc delete svc <name>
    Delete a service.
  4. oc delete route <name>
    Delete a route.
  5. oc delete project <name>
    Delete a project.
  6. oc delete -f <file.yaml>
    Delete resources from file.

Resource Details & Troubleshooting

  1. oc describe <resource> <name>
    Show details about a resource.
  2. oc logs <pod>
    Show logs for a pod.
  3. oc logs deployment/<name>
    Show logs for a deployment.
  4. oc rsh <pod>
    Open a remote shell into a pod.
  5. oc exec <pod> -- <command>
    Execute a command in a pod.
  6. oc port-forward <pod> <local-port>:<pod-port>
    Forward port from pod to local machine.
  7. oc cp <pod>:<src> <dest>
    Copy files from pod to local (or vice versa).

Scaling & Rollout

  1. oc scale deployment/<name> --replicas=3
    Scale a deployment.
  2. oc rollout status deployment/<name>
    Watch rollout status.
  3. oc rollout history deployment/<name>
    View rollout history.
  4. oc rollout undo deployment/<name>
    Roll back to previous revision.

Builds & Images

  1. oc start-build <buildconfig>
    Start a build.
  2. oc logs build/<buildname>
    Show build logs.
  3. oc tag <src-image> <dest-image>
    Tag images between streams.

Templates & Catalog

  1. oc get templates
    List templates.
  2. oc process <template>
    Process a template.
  3. oc describe template <name>
    Show details about a template.

Security & Policies

  1. oc policy who-can <verb> <resource>
    See who can do what.
  2. oc adm policy add-role-to-user <role> <user>
    Add a role to a user.
  3. oc adm policy remove-role-from-user <role> <user>
    Remove role from user.
  4. oc adm policy add-scc-to-user <scc> <user>
    Add Security Context Constraint.

Admin & Diagnostics

  1. oc adm top pods
    Show pod resource usage.
  2. oc adm top nodes
    Show node resource usage.
  3. oc adm diagnostics
    Run diagnostic checks.
  4. oc adm prune images
    Prune old images.
  5. oc adm manage-node <node> ...
    Node management commands.
  6. oc adm node-logs <node>
    Show logs from a node.

Miscellaneous

  1. oc get jobs
    List jobs.
  2. oc get cronjobs
    List cron jobs.
  3. oc create job ...
    Create a new job.
  4. oc debug node/<node>
    Start a debug pod on node.
  5. oc run ...
    Run a new pod.
  6. oc set env <resource> <KEY>=<VAL>
    Set environment variable(s).
  7. oc set volume ...
    Attach/detach volumes.
  8. oc get networkpolicies
    List network policies.
  9. oc get serviceaccounts
    List service accounts.
  10. oc get endpoints
    List endpoints.
  11. oc get ingress
    List ingresses.
  12. oc create role ...
    Create a role.
  13. oc create rolebinding ...
    Bind a role.
  14. oc explain <resource> --recursive
    Show full resource documentation.
  15. oc set probe deployment/<name> ...
    Set liveness/readiness probes.
  16. oc set selector ...
    Update resource selector.
  17. 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

Subscribe
Notify of
guest
0 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments

Certification Courses

DevOpsSchool has introduced a series of professional certification courses designed to enhance your skills and expertise in cutting-edge technologies and methodologies. Whether you are aiming to excel in development, security, or operations, these certifications provide a comprehensive learning experience. Explore the following programs:

DevOps Certification, SRE Certification, and DevSecOps Certification by DevOpsSchool

Explore our DevOps Certification, SRE Certification, and DevSecOps Certification programs at DevOpsSchool. Gain the expertise needed to excel in your career with hands-on training and globally recognized certifications.

0
Would love your thoughts, please comment.x
()
x