Getting started with the CLI - OpenShift CLI (oc) | CLI tools (2024)

  • About the CLI
  • Installing the CLI
    • Installing the CLI by downloading the binary
    • Installing the CLI by using an RPM
  • Logging in to the CLI
  • Using the CLI
    • Creating a project
    • Creating a new app
    • Viewing pods
    • Viewing pod logs
    • Viewing the current project
    • Viewing the status for the current project
    • Listing supported API resources
  • Getting help
  • Logging out of the CLI

About the CLI

With the OpenShift Container Platform command-line interface (CLI), you can createapplications and manage OpenShift Container Platform projects from a terminal. The CLI isideal in situations where you:

  • Work directly with project source code.

  • Script OpenShift Container Platform operations.

  • Are restricted by bandwidth resources and can not use the web console.

Installing the CLI

You can install the OpenShift CLI (oc) either by downloading the binary or by using an RPM.

Installing the CLI by downloading the binary

You can install the OpenShift CLI (oc) in order to interact with OpenShift Container Platform from acommand-line interface. You can install oc on Linux, Windows, or macOS.

If you installed an earlier version of oc, you cannot use it to complete allof the commands in OpenShift Container Platform 4.3. Download andinstall the new version of oc.

Installing the CLI on Linux

You can install the OpenShift CLI (oc) binary on Linux by using the following procedure.

Procedure

  1. Navigate to the Infrastructure Provider page on the Red Hat OpenShift Cluster Manager site.

  2. Select your infrastructure provider, and, if applicable, your installation type.

  3. In the Command-line interface section, select Linux from the drop-down menu and click Download command-line tools.

  4. Unpack the archive:

    $ tar xvzf <file>
  5. Place the oc binary in a directory that is on your PATH.

    To check your PATH, execute the following command:

    $ echo $PATH

After you install the CLI, it is available using the oc command:

$ oc <command>

Installing the CLI on Windows

You can install the OpenShift CLI (oc) binary on Windows by using the following procedure.

Procedure

  1. Navigate to the Infrastructure Provider page on the Red Hat OpenShift Cluster Manager site.

  2. Select your infrastructure provider, and, if applicable, your installation type.

  3. In the Command-line interface section, select Windows from the drop-down menu and click Download command-line tools.

  4. Unzip the archive with a ZIP program.

  5. Move the oc binary to a directory that is on your PATH.

    To check your PATH, open the command prompt and execute the following command:

    C:\> path

After you install the CLI, it is available using the oc command:

C:\> oc <command>

Installing the CLI on macOS

You can install the OpenShift CLI (oc) binary on macOS by using the following procedure.

Procedure

  1. Navigate to the Infrastructure Provider page on the Red Hat OpenShift Cluster Manager site.

  2. Select your infrastructure provider, and, if applicable, your installation type.

  3. In the Command-line interface section, select MacOS from the drop-down menu and click Download command-line tools.

  4. Unpack and unzip the archive.

  5. Move the oc binary to a directory on your PATH.

    To check your PATH, open a terminal and execute the following command:

    $ echo $PATH

After you install the CLI, it is available using the oc command:

$ oc <command>

Installing the CLI by using an RPM

For Red Hat Enterprise Linux (RHEL), you can install the OpenShift CLI (oc) as an RPM if you have an active OpenShift Container Platform subscription on your Red Hat account.

Prerequisites

  • Must have root or sudo privileges.

Procedure

  1. Register with Red Hat Subscription Manager:

    # subscription-manager register
  2. Pull the latest subscription data:

    # subscription-manager refresh
  3. List the available subscriptions:

    # subscription-manager list --available --matches '*OpenShift*'
  4. In the output for the previous command, find the pool ID for an OpenShift Container Platform subscription and attach the subscription to the registered system:

    # subscription-manager attach --pool=<pool_id>
  5. Enable the repositories required by OpenShift Container Platform 4.3.

    • For Red Hat Enterprise Linux 8:

      # subscription-manager repos --enable="rhocp-4.3-for-rhel-8-x86_64-rpms"
    • For Red Hat Enterprise Linux 7:

      # subscription-manager repos --enable="rhel-7-server-ose-4.3-rpms"
  6. Install the openshift-clients package:

    # yum install openshift-clients

After you install the CLI, it is available using the oc command:

$ oc <command>

Logging in to the CLI

You can log in to the oc CLI to access and manage your cluster.

Prerequisites

  • You must have access to an OpenShift Container Platform cluster.

  • You must have installed the CLI.

To access a cluster that is accessible only over an HTTP proxy server, you can set the HTTP_PROXY, HTTPS_PROXY and NO_PROXY variables.These environment variables are respected by the oc CLI so that all communication with the cluster goes through the HTTP proxy.

Procedure

  • Log in to the CLI using the oc login command and enter the requiredinformation when prompted.

    $ oc loginServer [https://localhost:8443]: https://openshift.example.com:6443 (1)The server uses a certificate signed by an unknown authority.You can bypass the certificate check, but any data you send to the server could be intercepted by others.Use insecure connections? (y/n): y (2)Authentication required for https://openshift.example.com:6443 (openshift)Username: user1 (3)Password: (4)Login successful.You don't have any projects. You can try to create a new project, by running oc new-project <projectname>Welcome! See 'oc help' to get started.
    1Enter the OpenShift Container Platform server URL.
    2Enter whether to use insecure connections.
    3Enter the user name to log in as.
    4Enter the user’s password.

You can now create a project or issue other commands for managing your cluster.

Using the CLI

Review the following sections to learn how to complete common tasks using the CLI.

Creating a project

Use the oc new-project command to create a new project.

$ oc new-project my-projectNow using project "my-project" on server "https://openshift.example.com:6443".

Creating a new app

Use the oc new-app command to create a new application.

$ oc new-app https://github.com/sclorg/cakephp-ex--> Found image 40de956 (9 days old) in imagestream "openshift/php" under tag "7.2" for "php"... Run 'oc status' to view your app.

Viewing pods

Use the oc get pods command to view the pods for the current project.

$ oc get pods -o wideNAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODEcakephp-ex-1-build 0/1 Completed 0 5m45s 10.131.0.10 ip-10-0-141-74.ec2.internal <none>cakephp-ex-1-deploy 0/1 Completed 0 3m44s 10.129.2.9 ip-10-0-147-65.ec2.internal <none>cakephp-ex-1-ktz97 1/1 Running 0 3m33s 10.128.2.11 ip-10-0-168-105.ec2.internal <none>

Viewing pod logs

Use the oc logs command to view logs for a particular pod.

$ oc logs cakephp-ex-1-deploy--> Scaling cakephp-ex-1 to 1--> Success

Viewing the current project

Use the oc project command to view the current project.

$ oc projectUsing project "my-project" on server "https://openshift.example.com:6443".

Viewing the status for the current project

Use the oc status command to view information about the current project, suchas Services, DeploymentConfigs, and BuildConfigs.

$ oc statusIn project my-project on server https://openshift.example.com:6443svc/cakephp-ex - 172.30.236.80 ports 8080, 8443 dc/cakephp-ex deploys istag/cakephp-ex:latest <- bc/cakephp-ex source builds https://github.com/sclorg/cakephp-ex on openshift/php:7.2 deployment #1 deployed 2 minutes ago - 1 pod3 infos identified, use 'oc status --suggest' to see details.

Listing supported API resources

Use the oc api-resources command to view the list of supported API resourceson the server.

$ oc api-resourcesNAME SHORTNAMES APIGROUP NAMESPACED KINDbindings true Bindingcomponentstatuses cs false ComponentStatusconfigmaps cm true ConfigMap...

Getting help

You can get help with CLI commands and OpenShift Container Platform resources in thefollowing ways.

  • Use oc help to get a list and description of all available CLI commands:

    Example: Get general help for the CLI

    $ oc helpOpenShift ClientThis client helps you develop, build, deploy, and run your applications on any OpenShift or Kubernetes compatibleplatform. It also includes the administrative commands for managing a cluster under the 'adm' subcommand.Usage: oc [flags]Basic Commands: login Log in to a server new-project Request a new project new-app Create a new application...
  • Use the --help flag to get help about a specific CLI command:

    Example: Get help for the oc create command

    $ oc create --helpCreate a resource by filename or stdinJSON and YAML formats are accepted.Usage: oc create -f FILENAME [flags]...
  • Use the oc explain command to view the description and fields for aparticular resource:

    Example: View documentation for the Pod resource

    $ oc explain podsKIND: PodVERSION: v1DESCRIPTION: Pod is a collection of containers that can run on a host. This resource is created by clients and scheduled onto hosts.FIELDS: apiVersion<string> APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#resources...

Logging out of the CLI

You can log out the CLI to end your current session.

  • Use the oc logout command.

    $ oc logoutLogged "user1" out on "https://openshift.example.com"

This deletes the saved authentication token from the server and removes it fromyour configuration file.

Getting started with the CLI - OpenShift CLI (oc) | CLI tools (2024)
Top Articles
This may be Carter Kieboom’s last chance. He hopes to make the most of it.
First game since TJ surgery a 'big win' for Kieboom
Laura Loomer, far-right provocateur who spread 9/11 conspiracy theory, influencing Trump as he searches for a message | CNN Politics
Nerdwallet Chase
Sams Gurnee Gas Price
Goodwill Bellingham Donation Hours
Lvc Final Exam Schedule
What Auto Parts Stores Are Open
Gopher Hockey Forum
Giant Egg Classic Wow
Warren County Skyward
Craigslist Worcester Massachusetts: Your Guide to the City's Premier Marketplace - First Republic Craigslist
Guide to Gold Farming in Guild Wars 2 - MMOPIXEL
Estragon South End
Lyons Prismhr
Asoiaf Spacebattles
Kitchen Exhaust Cleaning Companies Clearwater
O'reilly's El Dorado Kansas
Hellraiser 3 Parents Guide
Dimbleby Funeral Home
Enloe Bell Schedule
Fd Photo Studio New York
Devotion Showtimes Near Amc Classic Shiloh 14
Orlando Magic Account Manager
Autoplay Media Studio 9.5 Full
ASVAB Test: The Definitive Guide (updated 2024) by Mometrix
Central Nj Craiglist
Dr. Katrina (Katrina Hutchins) on LinkedIn: #dreambig #classof2025 #bestclassever #leadershipaugusta
Server - GIGABYTE Costa Rica
Arch Aplin Iii Felony
Taco Bell Fourth Of July Hours
Horseware Deken Amigo Bravo 100gr Donkerblauw - 130/183 | bol
Affordable Prom Dresses for Women | Fashion Nova
Cia Decrypter
Examination Policies: Finals, Midterms, General
Unveiling AnonIB: The Controversial Online Haven for Explicit Images - The Technology For The Next Generation.
Dl 646
Prot Pally Wrath Pre Patch
201-654-6727
Lkq Pull-A-Part
Journal articles: 'State of New York and the Military Society of the War of 1812' – Grafiati
Franco Loja Net Worth
Osrs Desert Heat
Chloe Dicarlo
Mercy Baggot Street Mypay
Nail salons near me in West Hartford. Find a nail shop on Booksy!
Ap Bio Unit 2 Progress Check Mcq
What is 9xMovies - Everything You Need to Know with Best Alternatives 2023-LDPlayer's Choice-LDPlayer
Epiq Document Delivery
Online-Shopping bei Temu: Solltest du lieber die Finger davon lassen?
Swaquickbase
Google Halloween Game 2018 Unblocked
Latest Posts
Article information

Author: Rob Wisoky

Last Updated:

Views: 5760

Rating: 4.8 / 5 (68 voted)

Reviews: 83% of readers found this page helpful

Author information

Name: Rob Wisoky

Birthday: 1994-09-30

Address: 5789 Michel Vista, West Domenic, OR 80464-9452

Phone: +97313824072371

Job: Education Orchestrator

Hobby: Lockpicking, Crocheting, Baton twirling, Video gaming, Jogging, Whittling, Model building

Introduction: My name is Rob Wisoky, I am a smiling, helpful, encouraging, zealous, energetic, faithful, fantastic person who loves writing and wants to share my knowledge and understanding with you.