Skip to content
Tutorials Center
My learning

Topics

Lesson 3 of 37 ยท Getting Started

The oc CLI and the Web Console

Install and use the oc command line tool, log in with a token, read oc get and oc describe output, and find your way around the Developer and Administrator consoles.

You talk to OpenShift in two ways: the web console in a browser and the oc command line tool. Both call the same API, so anything one does the other can do. Learning the CLI early pays off because every tutorial, pipeline and runbook uses it.

What oc is

oc is the OpenShift client. It includes everything in kubectl, the Kubernetes client, so oc get pods and kubectl get pods do the same thing. On top of that it adds commands for OpenShift features: oc login, oc new-project, oc new-app, oc start-build, oc expose, oc rollout, oc adm and more.

You get oc from the console's help menu (Command line tools), from the Red Hat downloads page, or as part of OpenShift Local. After installing, check it:

Terminal
oc version --client

Logging in

The API server of every cluster has a URL such as https://api.mycluster.example.com:6443. There are two common ways to log in.

With a token (copy login command). In the web console, click your user name at the top right and choose Copy login command. It shows a token and a command like this:

Terminal
oc login --token=<your-token> --server=https://api.mycluster.example.com:6443

Tokens are secrets. Do not paste them into chat, tickets or shell history that others can read. They expire, so you will repeat this regularly.

With a username and password when your cluster uses a simple identity provider:

Terminal
oc login -u developer https://api.mycluster.example.com:6443

After logging in, oc stores the cluster, user and current project in a kubeconfig file (by default ~/.kube/config). You can check who you are and where you point:

Terminal
oc whoami
oc whoami --show-server
oc project

The first commands to learn

Command What it does
oc projects Lists projects you can access
oc project <name> Switches the current project
oc get pods Lists Pods in the current project
oc get all Lists common workload objects (not literally everything)
oc describe pod <name> Shows details and recent events
oc logs <pod> Prints container output
oc status Gives a short overview of the current project
oc explain deployment.spec Prints API documentation for a field
oc help Lists commands

A useful habit is adding -o wide for more columns, -o yaml for the complete object and -w to watch changes. Add -n <project> to run a command against another project without switching.

Terminal
oc get pods -o wide
oc get deployment web -o yaml
oc get pods -w
oc get pods -n shop-test

Reading oc get columns

A typical Pod listing has columns NAME, READY, STATUS, RESTARTS and AGE. READY 1/1 means one of one containers passed its readiness check. Common statuses you will see:

  • Running - containers started.
  • Pending - not yet scheduled or still pulling the image.
  • ContainerCreating - the node is setting the container up.
  • CrashLoopBackOff - the container keeps exiting; read oc logs.
  • ImagePullBackOff or ErrImagePull - the image name or credentials are wrong.
  • Completed - a job-like container finished.

The stand-in below parses a made-up listing so you can practice spotting trouble. The text it parses is invented sample data, not captured output.

Python Stand-in: triage a Pod listing

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Output formats and filtering

oc get can print JSON, YAML and a few smart formats:

Terminal
oc get pods -o name
oc get pods -o jsonpath='{.items[*].metadata.name}'
oc get pods -l app=web
oc get pods --field-selector status.phase=Running

-l filters by label, which you will use constantly. -o jsonpath pulls specific fields out of the JSON. If the jq tool is installed you can also pipe -o json into it.

Getting help from the CLI itself

oc explain documents every field of every resource, including ones added by Operators:

Terminal
oc explain route.spec
oc explain pod.spec.containers.resources
oc api-resources

oc api-resources lists every kind your cluster knows. We use it in the API objects lesson.

The web console

The console has two perspectives you switch between with the dropdown at the top left.

Developer perspective is application-centric:

  • Topology shows your workloads as circles with their routes, builds and connections. Clicking one opens a side panel with Pods, logs and the URL.
  • +Add is the place to deploy: from Git, from a container image, from a template, from a YAML file, or from a catalog.
  • Builds, Pipelines, Observe and Search help with CI and monitoring.

Administrator perspective is cluster-centric: Home, Operators (OperatorHub and installed Operators), Workloads, Networking, Storage, Builds, Observe, Compute (nodes and machines), User Management and Administration (cluster settings and updates). If you are not a cluster administrator some of these entries are hidden or empty.

You can always press the + button in the top bar to open the YAML editor, and every object page has a YAML tab that shows the same object oc get -o yaml prints.

Never share your login token or a kubeconfig file. Anyone holding them acts as you until the token expires.

A tiny command lookup

This stand-in matches console clicks to CLI commands. It is a study aid, not a real oc client.

Python Stand-in: console action to command

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What is the relationship between oc and kubectl?

    oc is a superset: everything kubectl does works, plus login, new-app, start-build, adm and other OpenShift commands.
  2. 2. Which command shows which user you are logged in as?

    oc whoami prints the current user. oc project shows the current project.
  3. 3. A Pod shows CrashLoopBackOff. What is the best first step?

    CrashLoopBackOff means the container keeps exiting, and its logs usually say why.
  4. 4. Which option filters oc get output by label?

    -l (label selector) filters objects, -n picks the project, -w watches and -o wide adds columns.

Summary

  • oc is a superset of kubectl; it logs in, switches projects and drives OpenShift features.
  • Log in with a token copied from the console or with a username and password, and keep tokens private.
  • Learn oc get, describe, logs, status, explain and the -o, -l, -n, -w flags.
  • The console has Developer and Administrator perspectives and a YAML view for every object.

Next: Deploy Your First Application