This topic provides information on the CLI operations and their syntax. You must setup and login with the CLI before you can perform these operations.
The CLI allows interaction with the various objects that are managed by
OpenShift. Many common oc
operations are invoked using the following syntax:
$ oc <action> <object_type> <object_name_or_id>
This specifies:
-
An
<action>
to perform, such asget
ordescribe
. -
The
<object_type>
to perform the action on, such asservice
or the abbreviatedsvc
. -
The
<object_name_or_id>
of the specified<object_type>
.
For example, the oc get
operation returns a complete list of services that
are currently defined:
$ oc get svc NAME LABELS SELECTOR IP PORT(S) docker-registry docker-registry=default docker-registry=default 172.30.78.158 5000/TCP kubernetes component=apiserver,provider=kubernetes <none> 172.30.0.2 443/TCP kubernetes-ro component=apiserver,provider=kubernetes <none> 172.30.0.1 80/TCP
The oc describe
operation can then be used to return detailed information
about a specific object:
$ oc describe svc docker-registry Name: docker-registry Labels: docker-registry=default Selector: docker-registry=default IP: 172.30.78.158 Port: <unnamed> 5000/TCP Endpoints: 10.1.0.2:5000 Session Affinity: None No events.
Warning
|
Versions of |
The following table describes basic oc
operations and their general syntax:
Operation | Syntax | Description |
---|---|---|
|
|
Display an introduction to some core OpenShift concepts. |
|
|
Log in to the OpenShift server. |
|
|
End the current session. |
|
|
Create a new project. |
|
|
Creates a new application based on the source code in the current directory. |
|
|
Show an overview of the current project. |
|
|
Switch to another project. Run without options to display the current project. To view all projects you have access to run |
Operation | Syntax | Description |
---|---|---|
|
|
Return a list of objects for the specified object type. If
the optional |
|
|
Returns information about the specific object returned by the query. A specific
|
|
|
Edit the desired object type. |
|
Edit the desired object type with a specified text editor. |
|
|
Edit the desired object in a specified format (eg: JSON). |
|
|
|
Update the desired object type with a new environment variable |
|
|
Modify a volume. |
|
|
Update the labels on a object. |
|
|
Look up a service and expose it as a route. There is also the ability to expose a deployment configuration, replication controller, service, or pod as a new service on a specified port. If no labels are specified, the new object will re-use the labels from the object it exposes. |
|
|
Delete the specified object. An object configuration can also be passed in
through STDIN. The |
One of the fundamental capabilities of OpenShift is the ability to build applications into a container from source. The following table describes the CLI operations for working with application builds:
OpenShift provides CLI access to inspect and manipulate
deployment configurations using standard
oc
resource operations, such as get
, create
, and describe
.
Operation | Syntax | Description |
---|---|---|
|
|
Manually start the build process with the specified build configuration file. |
|
Manually start the build process by specifying the name of a previous build as a starting point. |
|
|
Manually start the build process by specifying either a configuration file or the name of a previous build and retrieve its build logs. |
|
|
Wait for a build to complete and exit with a non-zero return code if the build fails. |
|
|
Set or override environment variables for the current build without changing
the build configuration. Alternatively, use |
|
|
Set or override the default build log level output during the build. |
|
|
Specify the source code commit identifier the build should use; requires a build based on a Git repository. |
|
|
Re-run build with name |
|
|
Archive |
|
|
Use <file_name> as the binary input for the build. This file must be the only one in the build source. For example, pom.xml or Dockerfile. |
|
|
The path to a local source code repository to use as the binary input for a build. |
|
|
Specify a webhook URL for an existing build configuration to trigger. |
|
|
The contents of the post-receive hook to trigger a build. |
|
|
The path to the Git repository for post-receive; defaults to the current directory. |
|
|
List the webhooks for the specified build configuration or build; accepts
|
|
|
|
View a deployment, or manually start, cancel, or retry a deployment. |
|
|
Perform a rollback. |
|
|
Create a build config based on the source code in the current Git repository (with a public remote) and a Docker image |
|
|
Stop a build that is in progress. |
|
|
Import tag and image information from an external Docker image repository. |
|
|
Set the number of desired replicas for a replication controller or a deployment configuration to the number of specified replicas. |
|
|
Take an existing tag or image from an image stream, or a Docker image pull spec, and set it as the most recent image for a tag in one or more other image streams. |
Operation | Syntax | Description |
---|---|---|
|
|
Parse a configuration file and create one or more OpenShift objects based on
the file contents. The |
|
|
Attempt to modify an existing object based on the contents of the specified
configuration file. The |
|
|
Transform a project template into a project configuration file. |
|
|
Export resources to be used elsewhere |
|
|
Manage authorization policies |
|
|
Configure secrets. |
Operation | Syntax | Description |
---|---|---|
|
|
Retrieve the log output for a specific build, deployment, or pod. This command works for builds, build configurations, deployment configurations, and pods. |
|
|
Execute a command in a already-running container. It will default to the first container if none is specified. |
|
|
Open a remote shell session to a container. |
|
|
Copy contents of local directory to a directory in an already-running pod container. It will default to the first container if none is specified. |
|
|
Forward one or more local ports to a pod. |
|
|
Run a proxy to the Kubernetes API server |
Important
|
For security purposes, the
|
The CLI supports the following object types, some of which have abbreviated syntax:
Object Type | Abbreviated Version |
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|