This documentation is for a release that is no longer maintained
See documentation for the latest supported version 3 or the latest supported version 4.Chapter 1. Getting started with the CLI
1.1. About the CLI Copy linkLink copied to clipboard!
With the OpenShift Container Platform command-line interface (CLI), you can create applications and manage OpenShift Container Platform projects from a terminal. The CLI is ideal 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.
1.2. Installing the CLI Copy linkLink copied to clipboard!
You can install the CLI in order to interact with OpenShift Container Platform using a command-line interface.
Procedure
- From the Infrastructure Provider page on the Red Hat OpenShift Cluster Manager site, navigate to the page for your installation type and click Download Command-line Tools.
- Click the folder for your operating system and architecture and click the compressed file.
- Save the file to your file system.
- Extract the compressed file.
-
Place it in a directory that is on your
PATH.
After you install the CLI, it is available using the oc command:
oc <command>
$ oc <command>
1.3. Logging in to the CLI Copy linkLink copied to clipboard!
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.
Procedure
Log in to the CLI using the
oc logincommand and enter the required information when prompted.Copy to Clipboard Copied! Toggle word wrap Toggle overflow
You can now create a project or issue other commands for managing your cluster.
1.4. Using the CLI Copy linkLink copied to clipboard!
Review the following sections to learn how to complete common tasks using the CLI.
1.4.1. Creating a project Copy linkLink copied to clipboard!
Use the oc new-project command to create a new project.
oc new-project my-project
$ oc new-project my-project
Now using project "my-project" on server "https://openshift.example.com:6443".
1.4.2. Creating a new app Copy linkLink copied to clipboard!
Use the oc new-app command to create a new application.
1.4.3. Viewing pods Copy linkLink copied to clipboard!
Use the oc get pods command to view the pods for the current project.
oc get pods -o wide
$ 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>
1.4.4. Viewing pod logs Copy linkLink copied to clipboard!
Use the oc logs command to view logs for a particular pod.
oc logs cakephp-ex-1-deploy
$ oc logs cakephp-ex-1-deploy
--> Scaling cakephp-ex-1 to 1
--> Success
1.4.5. Viewing the current project Copy linkLink copied to clipboard!
Use the oc project command to view the current project.
oc project
$ oc project
Using project "my-project" on server "https://openshift.example.com:6443".
1.4.6. Viewing the status for the current project Copy linkLink copied to clipboard!
Use the oc status command to view information about the current project, such as Services, DeploymentConfigs, and BuildConfigs.
1.4.7. Listing supported API resources Copy linkLink copied to clipboard!
Use the oc api-resources command to view the list of supported API resources on the server.
1.5. Getting help Copy linkLink copied to clipboard!
You can get help with CLI commands and OpenShift Container Platform resources in the following ways.
Use
oc helpto get a list and description of all available CLI commands:Example: Get general help for the CLI
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Use the
--helpflag to get help about a specific CLI command:Example: Get help for the
oc createcommandCopy to Clipboard Copied! Toggle word wrap Toggle overflow Use the
oc explaincommand to view the description and fields for a particular resource:Example: View documentation for the Pod resource
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
1.6. Logging out of the CLI Copy linkLink copied to clipboard!
You can log out the CLI to end your current session.
Use the
oc logoutcommand.oc logout
$ oc logout Logged "user1" out on "https://openshift.example.com"Copy to Clipboard Copied! Toggle word wrap Toggle overflow
This deletes the saved authentication token from the server and removes it from your configuration file.