Cover graphics_Red Hat OpenShift

Red Hat OpenShift Cheat Sheet

Ben Pritchett
English

About

Red Hat OpenShift is a unified platform to build, modernize, and deploy applications at scale. OpenShift uses the Kubernetes upstream project to provide a secure, robust, and extendable way to orchestrate applications. OpenShift works to further the access management and build and deploy services that the upstream Kubernetes project provides. 

The oc tool is a command-line interface (CLI) tool designed for managing Kubernetes clusters. It streamlines various operations, such as deploying applications, inspecting and managing cluster resources, and viewing logs. 

The Red Hat OpenShift cheat sheet presents oc commands for managing an application’s lifecycle, including:

  • Login and user management
  • Project management
  • Resource management
  • Cluster management
  • Additional resource management
  • Operational commands
  • Build and deploy commands

Red Hat Developer cheat sheets give you essential information right at your fingertips so you can work faster and smarter. Easily learn new technologies and coding concepts and quickly find the answers you need.

Excerpt

Login and user management

oc login # Use --token to log in with an OAuth token or --username and --password to log in with your OpenShift developer credentials.

oc logout # End the current session.

oc whoami # Show the current user context.

Project management

oc project # Shows the current project context, if a name is specified the project context is changed.

oc get projects # Show all projects the current login has access to.

oc status # Show overview of current project resources.

oc new-project # Create a new OpenShift project and change the context to it. Requires that the user has the appropriate permissions to create projects.

Resource management

oc new-app # Create a new OpenShift application from an image, image stream, template or url. Use -S [name] to search for images, image streams, and templates that match to [name].

oc new-build # Create a new OpenShift build configuration from an image, image stream or url. 

oc label # Add/update/remove labels from an OpenShift resource.

oc annotate # Add/update/remove annotations from an OpenShift resource.

oc create # Create a new resource like a Pod or ConfigMap. Use -f [filename] to create from a manifest.

oc apply -f #Applies an object using a predefined yaml file 

oc get # Retrieve a resource. Use -o for additional output options, and -f [filename] to retrieve resources defined in a manifest.

oc get svc #Retrieves a list of services that have been defined. These services can be edited, similar to other resources. 

oc run # Create a pod from an image.

oc expose # Expose pods externally or internally. Use the pods/[name] argument to expose a pod to the greater internet.    

oc api-resources # List the supported api resources on the server.

oc explain # Get verbose details of an API resource.  

oc replace # Replace an existing resource from a file name or stdin. Use -f - to replace resources taken from stdin and -f [filename] to replace resources from a manifest.

oc delete # Delete a resource. Use -f [filename] to delete resources defined in a manifest.

oc edit # Modify a resource from a text editor. Use -f [filename] to modify resources defined in the manifest.

oc describe # Retrieve a resource with details. Use -f [filename] to retrieve resource(s) defined in a manifest.

Related Cheat sheets