Skip to main content
Redhat Developers  Logo
  • Products

    Platforms

    • Red Hat Enterprise Linux
      Red Hat Enterprise Linux Icon
    • Red Hat AI
      Red Hat AI
    • Red Hat OpenShift
      Openshift icon
    • Red Hat Ansible Automation Platform
      Ansible icon
    • View All Red Hat Products

    Featured

    • Red Hat build of OpenJDK
    • Red Hat Developer Hub
    • Red Hat JBoss Enterprise Application Platform
    • Red Hat OpenShift Dev Spaces
    • Red Hat OpenShift Local
    • Red Hat Developer Sandbox

      Try Red Hat products and technologies without setup or configuration fees for 30 days with this shared Openshift and Kubernetes cluster.
    • Try at no cost
  • Technologies

    Featured

    • AI/ML
      AI/ML Icon
    • Linux
      Linux Icon
    • Kubernetes
      Cloud icon
    • Automation
      Automation Icon showing arrows moving in a circle around a gear
    • View All Technologies
    • Programming Languages & Frameworks

      • Java
      • Python
      • JavaScript
    • System Design & Architecture

      • Red Hat architecture and design patterns
      • Microservices
      • Event-Driven Architecture
      • Databases
    • Developer Productivity

      • Developer productivity
      • Developer Tools
      • GitOps
    • Automated Data Processing

      • AI/ML
      • Data Science
      • Apache Kafka on Kubernetes
    • Platform Engineering

      • DevOps
      • DevSecOps
      • Ansible automation for applications and services
    • Secure Development & Architectures

      • Security
      • Secure coding
  • Learn

    Featured

    • Kubernetes & Cloud Native
      Openshift icon
    • Linux
      Rhel icon
    • Automation
      Ansible cloud icon
    • AI/ML
      AI/ML Icon
    • View All Learning Resources

    E-Books

    • GitOps Cookbook
    • Podman in Action
    • Kubernetes Operators
    • The Path to GitOps
    • View All E-books

    Cheat Sheets

    • Linux Commands
    • Bash Commands
    • Git
    • systemd Commands
    • View All Cheat Sheets

    Documentation

    • Product Documentation
    • API Catalog
    • Legacy Documentation
  • Developer Sandbox

    Developer Sandbox

    • Access Red Hat’s products and technologies without setup or configuration, and start developing quicker than ever before with our new, no-cost sandbox environments.
    • Explore Developer Sandbox

    Featured Developer Sandbox activities

    • Get started with your Developer Sandbox
    • OpenShift virtualization and application modernization using the Developer Sandbox
    • Explore all Developer Sandbox activities

    Ready to start developing apps?

    • Try at no cost
  • Blog
  • Events
  • Videos

Learn about OpenShift command-line tools

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

Share:

    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 Qwen3-Next on vLLM with Red Hat AI: A step-by-step guide

    • How to implement observability with Python and Llama Stack

    • Deploy a lightweight AI model with AI Inference Server containerization

    • vLLM Semantic Router: Improving efficiency in AI reasoning

    • Declaratively assigning DNS records to virtual machines

    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 LinkedIn YouTube Twitter Facebook

    Products

    • Red Hat Enterprise Linux
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform

    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
    © 2025 Red Hat

    Red Hat legal and privacy links

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

    Report a website issue