$ oc new-app https://github.com/<your_user>/<your_git_repo>
The OpenShift cli exposes commands for managing your applications, as well as lower level tools to interact with each component of your system. This topic guides you through getting started with the cli, including installation and logging in to create your first project.
Certain operations require Git to be locally installed on a client. For example, the command to create an application using a remote Git repository:
$ oc new-app https://github.com/<your_user>/<your_git_repo>
Before proceeding, install Git on your workstation. See the official Git documentation for instructions per your workstation’s operating system.
You can download and unpack the cli from the Red Hat Customer Portal for use on Linux, MacOSX, and Windows clients. After logging in with your Red Hat account, you must have an active OpenShift Enterprise subscription to access the downloads page.
The oc login
command is the best way to initially set up the OpenShift cli,
and it serves as the entry point for most users. The interactive flow helps you
establish a session to an OpenShift server with the provided credentials. The
information is automatically saved in a cli
configuration file that is then used for subsequent commands.
The following example shows the interactive setup and login using the oc
login
command:
$ oc login OpenShift server [https://localhost:8443]: https://openshift.example.com (1) Username: alice (2) Authentication required for https://openshift.example.com (openshift) Password: ****** Login successful. (3) You don't have any projects. You can try to create a new project, by running $ oc new-project <projectname> (4) Welcome to OpenShift! See 'oc help' to get started.
1 | The command prompts for the OpenShift server URL. |
2 | The command prompts for login credentials: a user name and password. |
3 | A session is established with the server, and a session token is received. |
4 | If you do not have a project, information is given on how to create one. |
When you have completed the cli configuration, subsequent commands use the configuration file for the server, session token, and project information.
You can log out of cli using the oc logout
command:
$ oc logout User, alice, logged out of https://openshift.example.com
If you log in after creating or being granted access to a project, a project you have access to is automatically set as the current default, until switching to another one:
$ oc login Username: alice Authentication required for https://openshift.example.com (openshift) Password: Login successful. Using project "aliceproject".
Additional options are also available for
the oc login
command.
If you have access to administrator credentials but are no longer logged in as the default system user system:admin, you can log back in as this user at any time as long as the credentials are still present in your cli configuration file. The following command logs in and switches to the default project: $ oc login -u system:admin -n default |
A cli configuration file permanently stores oc
options and contains a series
of authentication
mechanisms and OpenShift server connection information associated with
nicknames.
As described in the previous section, the oc login
command automatically
creates and manages cli configuration files. All information gathered by the
command is stored in a configuration file located in
~/.kube/config. The current cli configuration can be viewed using the following command:
$ oc config view apiVersion: v1 clusters: - cluster: server: https://openshift.example.com name: openshift contexts: - context: cluster: openshift namespace: aliceproject user: alice name: alice current-context: alice kind: Config preferences: {} users: - name: alice user: token: NDM2N2MwODgtNjI1Yy10N3VhLTg1YmItYzI4NDEzZDUyYzVi
cli configuration files can be used to setup multiple cli profiles using various OpenShift servers, namespaces, and users so that you can switch easily between them. The cli can support multiple configuration files; they are loaded at runtime and merged together along with any override options specified from the command line.
A project in OpenShift contains multiple objects to make up a logical "application".
Most oc
commands run in the context of a
project. The oc login
selects a default
project during initial setup to be used with
subsequent commands. Use the following command to display the project currently
in use:
$ oc project
If you have access to multiple projects, use the following syntax to switch to a particular project by specifying the project name:
$ oc project <project_name>
For example:
$ oc project project02 Now using project 'project02'. $ oc project project03 Now using project 'project03'. $ oc project Using project 'project03'.
The oc status
command shows a high level overview of the project currently in
use, with its components and their relationships, as shown in the following
example:
$ oc status In project OpenShift 3 Sample (test) service database-test (172.30.17.113:6434 -> 3306) database-test deploys docker.io/library/mysql:latest #1 deployed 47 hours ago service frontend-test (172.30.17.236:5432 -> 8080) frontend-test deploys origin-ruby-sample:test <- builds https://github.com/openshift/ruby-hello-world with docker.io/openshift/ruby-20-centos7:latest not built yet #1 deployment waiting on image To see more information about a service or deployment config, use 'oc describe service <name>' or 'oc describe dc <name>'. You can use 'oc get pods,svc,dc,bc,builds' to see lists of each of the types described above.
After you have logged in, you can create a new application and explore some common cli operations.