Skip to main content
AI
  • Get started with AI

    • Red Hat AI

      Accelerate the development and deployment of enterprise AI solutions.

    • AI learning hub

      Explore learning materials and tools, organized by task.

    • AI interactive demos

      Click through scenarios with Red Hat AI, including training LLMs and more.

    • AI/ML learning paths

      Expand your Red Hat OpenShift AI knowledge using these learning resources.

    • AI quickstarts

      Focused AI use cases designed for fast deployment on Red Hat AI platforms.

    • No-cost AI training

      Foundational Red Hat AI training.

  • Featured resources

    • Red Hat OpenShift AI
    • Open source AI for developers
    • AI product application development
    • Open source-powered AI/ML for hybrid cloud
    • AI and Node.js cheat sheet

Red Hat AI Factory with NVIDIA

Red Hat AI Factory with NVIDIA is a co-engineered, enterprise-grade AI solution for building, deploying, and managing AI at scale across hybrid cloud environments.

Learn
  • Self-guided

    • Documentation

      Find answers, get step-by-step guidance, and learn how to use Red Hat products.

    • Learning paths

      Explore curated walkthroughs for common development tasks.

    • Guided learning

      Receive custom learning paths powered by our AI assistant.

    • See all learning
  • Hands-on

    • Developer Sandbox

      Spin up Red Hat's products and technologies without setup or configuration.

    • Interactive labs

      Learn by doing in these hands-on, browser-based experiences.

    • Interactive demos

      Click through product features in these guided tours.

  • Browse by topic

    • AI/ML
    • Automation
    • Java
    • Kubernetes
    • Linux
    • See all topics
  • Training & certifications

    • Courses and exams
    • Certifications
    • Skills assessments
    • Red Hat Academy
    • Learning subscription
    • Explore training
Build
  • Get started

    • Red Hat build of Podman Desktop

      A downloadable, local development hub to experiment with our products and builds.

    • Developer Sandbox

      Spin up Red Hat's products and technologies without setup or configuration.

  • Download products

    • Red Hat Enterprise Linux
    • Red Hat AI
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform
    • See all products
  • Featured

    • Red Hat build of OpenJDK
    • Red Hat JBoss Enterprise Application Platform
    • Red Hat OpenShift Dev Spaces
    • Red Hat Developer Toolset
  • References

    • E-books
    • Documentation
    • Cheat sheets
    • Architecture center
Community
  • Get involved

    • Events
    • Live AI events
    • Red Hat Summit
    • Red Hat Accelerators
    • Community discussions
  • Follow along

    • Articles & blogs
    • Developer newsletter
    • Videos
    • Github
  • Get help

    • Customer service
    • Customer support
    • Regional contacts
    • Find a partner

Join the Red Hat Developer program

Download Red Hat products and project builds, access support documentation, learning content, and more.

ConsoleDocsSupport Search
New For you

Recommended

We'll recommend resources you may like as you browse. Try these suggestions for now.

  • Product downloads
  • Cheat sheets
  • Red Hat Developer learning portal
  • Developer blog
  • E-books
  • Developer Sandbox
Log in

Get more with a Red Hat Developer account

  • Product downloads
  • Console access
  • Event registration
  • Training & trials
Explore more account benefitsLog in or register

A subscription may be required for some services.

Contact us

Learn about OpenShift command-line tools

June 16, 2022
Varsha Sharma
Related topics:
Kubernetes
Related products:
Developer ToolsetRed Hat OpenShift Container Platform

    Red Hat OpenShift simplifies application deployment, the management and monitoring of Kubernetes clusters, and other developer tasks. The OpenShift tools, both command-line interface (CLI) and graphical user interface (GUI), cover many crucial deployment tasks. This article focuses on the oc and odo CLI commands, but touches on the GUIs as well.

    The oc client

    The OpenShift oc command helps you develop, build, deploy, and run applications on an OpenShift or Kubernetes cluster. The command includes an adm subcommand for administering the cluster.

    oc can be downloaded from the help menu of your OpenShift web interface, from OpenShift's GitHub releases page, or from the Red Hat web site after you create a Red Hat account. There are binaries for many operating systems, including Linux, Microsoft Windows, and macOS.

    The --help option (flag) offers an overview of the oc command. This option can be also used with subcommands, which can help you build the right command in your early stages of use. For example, the following command displays options for the whoami subcommand:

    $ oc whoami --help
    Show information about the current session
    
     The default options for this command will return the currently authenticated user name or an empty string.  Other flags
    support returning the currently used token or the user context.
    
    Usage:
      oc whoami [flags]
    
    Examples:
      # Display the currently authenticated user
      oc whoami
    
    Options:
          --show-console=false: If true, print the current server's web console URL
      -c, --show-context=false: Print the current user context name
          --show-server=false: If true, print the current server's REST API URL
      -t, --show-token=false: Print the token the current session is using. This will return an error if you are using a
    different form of authentication.
    
    Use "oc options" for a list of global command-line options (applies to all commands).
    $ oc whoami --show-console
    https://console-openshift-console.apps.varsha.lab.upshift.rdu2.redhat.com

    Several more examples of oc commands appear in the following subsections.

    View the console

    You can pull up the OpenShift console from the command line by entering:

    oc whoami --show-console

    Log in to an OpenShift cluster

    The login subcommand connects you to one of your clusters:

    $ oc login -u <username> -p <password> <servername>

    For example:

    $ oc login -u kubeadmin -p asdfghjkliuytr https://upi-o.varsha.lab.upshift.rdu2.redhat.com:6443

    Alternatively, you can use an access token to log in. Obtain a token by visiting:

    https://oauth-openshift.apps.varsha.lab.upshift.rdu2.redhat.com/oauth/token/request

    A login using a token looks like this:

    $ oc login --token=sha256~vNVfZ0VuFK7SkveM_nGRFTS7nrfawCQnQ9FEPNScv-0 --server=https://api.varsha.lab.upshift.rdu2.redhat.com:6443

    Switch to a specific project

    Specify the name of your project with the following command:

    $ oc project <project_name>

    List existing projects

    You can view the projects in your account like this:

    $ oc project list
    $ oc projects

    Display the current project

    To see which project you are logged into, enter:

    $ oc project

    Run applications

    Here are some useful commands to use with applications.

    Execute a command on a particular pod:

    $ oc exec <mypod> -- <command_to_execute_in_pod>

    Start a remote shell so you can enter a series of commands on a pod:

    $ oc rsh <pod_name>

    Debug cluster activities on a pod:

    $ oc debug <pod_name>

    Frequently used commands

    Some more common activities are:

    # See an overview of the current project
    oc status 
    #  -f, --follow=false: Specify if the logs should be streamed.
    oc logs -f <pod_name>
    # list all pods resource in ps output format
    oc get pods
    oc get po
    # list all resources in a namespace
    oc get all
    # Show details of a specific resource or group of resources.
    Print a detailed description of the selected resources, including related
    resources such as events or controllers.
    oc describe pod <pod_name>
    # List all services together in ps output format
    oc get services
    # To display output of yaml file of a resource 
    oc get <resource> <resource_name> -o yaml
    # Delete all resources of the application
    oc delete all -l app=<app_name>
    # Delete all pods
    oc delete pod <pod_name>
    
    

    Scaling applications

    Autoscaling increases or decreases the number of pods in the cluster to meet demand for its service. OpenShift makes autoscaling easy. For instance, the following command creates an autoscaler for the specified deployment, replica set, stateful set, or replication controller:

    $ oc scale dc <resource_name> --replicas=<count>

    You can also specify parameters for autoscaling. For instance, the following command allows OpenShift to scale the application between 2 and 4 pods with a target CPU utilization of 80%:

    $ oc autoscale deployment <resource_name> --min=2 --max=4 --cpu-percent=80%

    Deploy a ConfigMap

    A ConfigMap is a key-value listing used in many aspects of configuration. Normally, the ConfigMap is stored as YAML in a file and pushed to the cluster, as shown in the following command. The --from-file option can be specified multiple times in a single command to create the ConfigMap from a combination of files:

    $ oc create configmap <name> --from-file=<file_name>

    Mount the ConfigMap into the pods via the deployment controller or deployment:

    $ oc set volume deployment/<resource_name> --add --name=<config_map_volume> -m <mount_path> -t configmap --configmap-name=<name> --default-mode='0777'

    Deploying a secret

    A secret is a key-value listing protected by encryption, and is used for sensitive data such as passwords. The following command creates a secret and mounts it as a volume to a deployment configuration:

    $ oc create secret generic <secret_name> --from-literal=username=myuser --from-file=<file_name>
    $ oc set volume dc/<resource_name> --add --name=<secret_volume> -m <mount_path> -t secret --secret-name=<secret_name> --default-mode='0755'

    The odo client

    odo (an abbreviation of OpenShift do) is a developer-focused command that runs OpenShift applications in an expedited and automated manner. odo reduces the developer's cognitive load. This command is for application developers who wish to deploy their applications to Kubernetes easily without spending a lot of time learning the DevOps and Kubernetes procedures for deploying enterprise infrastructure. In contrast, oc focuses on operations and requires a deeper understanding of Kubernetes and OpenShift concepts.

    odo can be installed from its web page and has a GitHub repository with documentation.

    Getting started with odo

    Here are a few commands to try in order to get familiar with odo.

    You can create an application as follows. The final push subcommand builds the application, pushes it to your cluster, and deploys it on OpenShift:

    $ git clone https://github.com/openshift/nodejs-ex
    $ cd nodejs-ex
    $ odo create nodejs
    $ odo push

    The watch subcommand tells odo to automatically redeploy your application after edits:

    
    $ odo watch

    You can edit your code in real time and watch as odo automatically deploys your application.

    You can create a URL where clients can send HTTP requests to your application as follows:

    $ odo url create myurl
    $ odo push

    The following commands give you more information about the cluster, such as logs or what components you've deployed:

    $ odo describe
    $ odo list
    $ odo log

    Visual Studio Code OpenShift Connector for Red Hat OpenShift: An odo GUI

    The OpenShift Connector extension, also known as the Visual Studio Code OpenShift Connector for Red Hat OpenShift, is a plug-in for the VSCode IDE that interacts with Red Hat OpenShift clusters. Basically, the OpenShift Connector extension provides a GUI for odo as well as oc, combining groups of related commands into compact units. Developers can use the interface to accomplish complex tasks with minimal OpenShift experience.

    To start with the connector, choose a predefined template, such as a Project, Application, or Service. The graphical interface can then build the resource and deploy it to your cluster as an OpenShift component. The OpenShift Connector can:

    • Create applications
    • Build applications
    • Debug applications
    • Deploy the applications directly to an OpenShift cluster

    The latest version of OpenShift Connector is available in the VS Code Marketplace. There are several options available for different environments, so you can use the interface directly on a laptop or install it into a local OpenShift cluster. (There are limitations on Apple M1 hardware.)

    Conclusion

    This article should get you started on OpenShift using the command line or a GUI. You will grow in sophistication over time, and use the tools for such advanced tasks as:

    • Gathering information from a cluster for debugging issues
    • Working directly with project source code
    • Managing project content when the web console is not accessible
    Last updated: November 8, 2023

    Recent Posts

    • Run Red Hat Enterprise Linux CoreOS on NVIDIA BlueField DPUs

    • Agent harness engineering: Separating model capabilities from enforcement

    • What's new for developers in Red Hat Enterprise Linux 10.3 and 9.9

    • Control multicluster costs with right-sizing in Red Hat Advanced Cluster Management 5

    • Lightbits is now certified for Red Hat OpenStack Services on OpenShift

    What’s up next?

    Cover of the ebook OpenShift for Developers

    Get a hands-on introduction to daily life as a developer crafting code on OpenShift, the open source container application platform from Red Hat, with OpenShift for Developers.

    Download the e-book
    Red Hat Developers logo

    Platforms

    • Red Hat AI
    • Red Hat Enterprise Linux
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform
    • See all products

    Build

    • Developer Sandbox
    • Developer tools
    • Interactive tutorials
    • API catalog

    Quicklinks

    • Learning resources
    • E-books
    • Cheat sheets
    • Blog
    • Events
    • Newsletter

    Communicate

    • About us
    • Contact sales
    • Find a partner
    • Report a website issue
    • Site status dashboard
    • Report a security problem

    Red Hat Developer

    Build here. Go anywhere.

    We serve the builders. The problem solvers who create careers with code.

    Join us if you’re a developer, software engineer, web designer, front-end designer, UX designer, computer scientist, architect, tester, product manager, project manager or team lead.

    Sign me up

    Red Hat legal and privacy links

    • About Red Hat
    • Jobs
    • Events
    • Locations
    • Contact Red Hat
    • Red Hat Blog
    • Inclusion at Red Hat
    • Cool Stuff Store
    • Red Hat Summit
    © 2026 Red Hat

    Red Hat legal and privacy links

    • Privacy statement
    • Terms of use
    • All policies and guidelines
    • Digital accessibility
    Ask AI