$ tar xvf <file>
Install and configure the OpenShift CLI (oc) to manage OKD clusters and deploy applications directly from a terminal.
With the OpenShift CLI (oc), you can create applications and manage OKD projects from a terminal.
The OpenShift CLI is ideal in the following situations:
Working directly with project source code.
Scripting OKD operations
Managing projects while restricted by bandwidth resources and the web console is unavailable.
To interact with a OKD cluster from the terminal, install the OpenShift CLI (oc). Depending on your operating system, you can install oc by downloading the binary from the Customer Portal or OKD web console, or by using Homebrew.
You can download the OpenShift CLI (oc) from the Customer Portal and install it to interact with OKD clusters from a terminal on Linux, Windows, or macOS.
To manage your cluster and deploy applications from the command line on Linux, install the OpenShift CLI (oc) binary. You can download the OpenShift CLI (oc) from the Red Customer Portal.
|
If you installed an earlier version of Download and install the new version of |
Navigate to https://mirror.openshift.com/pub/openshift-v4/clients/oc/latest/ and choose the folder for your operating system and architecture.
Download oc.tar.gz.
Unpack the archive:
$ tar xvf <file>
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 OpenShift CLI, it is available using the oc command:
$ oc <command>
To manage your cluster and deploy applications from the command line on Windows, install the OpenShift CLI (oc) binary. You can download the OpenShift CLI (oc) from the Red Customer Portal.
|
If you installed an earlier version of Download and install the new version of |
Navigate to https://mirror.openshift.com/pub/openshift-v4/clients/oc/latest/ and choose the folder for your operating system and architecture.
Download oc.zip.
Extract the archive with a ZIP program.
Move the oc binary to a directory that is on your PATH variable.
To check your PATH variable, open the command prompt and execute the following command:
C:\> path
After you install the OpenShift CLI, it is available using the oc command:
C:\> oc <command>
To manage your cluster and deploy applications from the command line on macOS, install the OpenShift CLI (oc) binary. You can download the OpenShift CLI (oc) from the Red Customer Portal.
|
If you installed an earlier version of Download and install the new version of |
Navigate to https://mirror.openshift.com/pub/openshift-v4/clients/oc/latest/ and choose the folder for your operating system and architecture.
Download oc.tar.gz.
Unpack and unzip the archive.
Move the oc binary to a directory on your PATH variable.
To check your PATH variable, open a terminal and execute the following command:
$ echo $PATH
Verify your installation by using an oc command:
$ oc <command>
You can download the OpenShift CLI (oc) from the web OKD console and install it to interact with OKD clusters from a terminal on Linux, Windows, or macOS.
|
If you installed an earlier version of |
To manage your cluster and deploy applications from the command line on Linux, install the OpenShift CLI (oc) binary. You can download the OpenShift CLI (oc) from the web console.
From the web console, click ?.
Click Command Line Tools.
Select appropriate oc binary for your Linux platform, and then click Download oc for Linux.
Save the file.
Unpack the archive.
$ tar xvf <file>
Move the oc binary to a directory that is on your PATH.
To check your PATH, execute the following command:
$ echo $PATH
After you install the OpenShift CLI, you can use the oc command:
$ oc <command>
To manage your cluster and deploy applications from the command line on Windows, install the OpenShift CLI (oc) binary. You can download the OpenShift CLI (oc) from the web console.
From the web console, click ?.
Click Command Line Tools.
Select the oc binary for Windows platform, and then click Download oc for Windows for x86_64.
Save the file.
Unzip the archive with a ZIP program.
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 OpenShift CLI, you can use the oc command:
C:\> oc <command>
To manage your cluster and deploy applications from the command line on macOS, install the OpenShift CLI (oc) binary. You can download the OpenShift CLI (oc) from the web console.
From the web console, click ?.
Click Command Line Tools.
Select the oc binary for macOS platform, and then click Download oc for Mac for x86_64.
|
For macOS arm64, click Download oc for Mac for ARM 64. |
Save the file.
Unpack and unzip the archive.
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 OpenShift CLI, you can use the oc command:
$ oc <command>
For macOS, you can install the OpenShift CLI (oc) by using the Homebrew package manager.
You must have Homebrew (brew) installed.
Install the openshift-cli package by running the following command:
$ brew install openshift-cli
Verify your installation by using an oc command:
$ oc <command>
You can log in to the OpenShift CLI (oc) to access and manage your cluster.
|
To access a cluster that is accessible only over an HTTP proxy server, you can set the Authentication headers are sent only when using HTTPS transport. |
You must have access to a OKD cluster.
The OpenShift CLI (oc) is installed.
Enter the oc login command and pass in a user name:
$ oc login -u user1
When prompted, enter the required information:
Server [https://localhost:8443]: https://openshift.example.com:6443
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
Authentication required for https://openshift.example.com:6443 (openshift)
Username: user1
Password:
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.
For the Server prompt, enter the OKD server URL.
For the Use insecure connections? prompt, enter whether to use insecure connections.
For the Username prompt, enter the username to log in with.
For the Password prompt, enter the user’s password.
|
If you are logged in to the web console, you can generate an |
You can now create a project or issue other commands for managing your cluster.
You can log in to the OpenShift CLI (oc) with the help of a web browser to access and manage your cluster. This allows you to avoid inserting your access token into the command line.
|
Logging in to the CLI through the web browser runs a server on localhost with HTTP, not HTTPS; use with caution on multi-user workstations. |
You must have access to an OKD cluster.
You must have installed the OpenShift CLI (oc).
You must have a browser installed.
Enter the oc login command with the --web flag:
$ oc login <cluster_url> --web
Optionally, you can specify the server URL and callback port. For example, oc login <cluster_url> --web --callback-port 8280 localhost:8443.
The web browser opens automatically. If it does not, click the link in the command output. If you do not specify the OKD server oc tries to open the web console of the cluster specified in the current oc configuration file. If no oc configuration exists, oc prompts interactively for the server URL.
Opening login URL in the default browser: https://openshift.example.com
Opening in existing browser session.
If more than one identity provider is available, select your choice from the options provided.
Enter your username and password into the corresponding browser fields. After you are logged in, the browser displays the text access token received successfully; please return to your terminal.
Check the CLI for a login confirmation.
Login successful.
You don't have any projects. You can try to create a new project, by running
oc new-project <projectname>
|
The web console defaults to the profile used in the previous session. To switch between Administrator and Developer profiles, log out of the OKD web console and clear the cache. |
You can now create a project or issue other commands for managing your cluster.
Review how to complete common tasks with the OpenShift CLI (oc).
Use the oc new-project command to create a new project.
Create a new project by running the following command:
$ oc new-project my-project
Now using project "my-project" on server "https://openshift.example.com:6443".
Use the oc new-app command to create a new application.
Create a new application by running the following command:
$ 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.
Use the oc get pods command to view the pods for the current project.
|
When you run |
View pods for the current project by running the following command:
$ oc get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE
cakephp-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>
Use the oc logs command to view logs for a particular pod.
View logs for a pod by running the following command:
$ oc logs cakephp-ex-1-deploy
--> Scaling cakephp-ex-1 to 1
--> Success
Use the oc project command to view the current project.
View the current project by running the following command:
$ oc project
Using project "my-project" on server "https://openshift.example.com:6443".
Use the oc status command to view information about the current project, such as services, deployments, and build configs.
View the status of the current project by running the following command:
$ oc status
In project my-project on server https://openshift.example.com:6443
svc/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 pod
3 infos identified, use 'oc status --suggest' to see details.
Use the oc api-resources command to view the list of supported API resources on the server.
View the supported API resources by running the following command:
$ oc api-resources
NAME SHORTNAMES APIGROUP NAMESPACED KIND
bindings true Binding
componentstatuses cs false ComponentStatus
configmaps cm true ConfigMap
...
Review the ways to get help with CLI commands and OKD resources.
Use oc help to get a list and description of all available CLI commands:
$ oc help
OpenShift Client
This client helps you develop, build, deploy, and run your applications on any OpenShift or Kubernetes compatible
platform. 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:
oc create command$ oc create --help
Create a resource by filename or stdin
JSON and YAML formats are accepted.
Usage:
oc create -f FILENAME [flags]
...
Use the oc explain command to view the description and fields for a
particular resource:
Pod resource$ oc explain pods
KIND: Pod
VERSION: v1
DESCRIPTION:
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
...
You can log out the OpenShift CLI (oc) to end your current session.
Use the oc logout command.
$ oc logout
Logged "user1" out on "https://openshift.example.com"
This deletes the saved authentication token from the server and removes it from your configuration file.