Chapter 5. Using OpenShift Enterprise


When you initialize the CDK Vagrant box using the rhel-ose Vagrantfile, which is provided as a part of Red Hat Container Tools (located in cdk/components/rhel/rhel-ose/Vagrantfile in the ZIP file), the launched virtual machine automatically provisions an instance of OpenShift Enterprise. (See the CDK Installation Guide for additional information on how to launch CDK with a specific Vagrantfile.)

Note

OpenShift Enterprise is a Platform as a Service (PaaS) offering by Red Hat that extends the functionality of the Docker service and the Kubernetes container orchestration tool to provide a powerful and easy-to-use platform for building, deploying, and orchestrating multi-container applications and services.

Command-line usage of the OpenShift service provided by the CDK box is possible both from within the virtual machine and from the host machine. This section provides examples of basic usage of the oc command. Note that you can also administer a subset of OpenShift features using its web user interface, which is accesible at https://10.1.2.2:8443/console.

See also the OpenShift Enterprise Developer Guide for detailed instructions on how to set up and configure a workstation to develop and deploy applications in an OpenShift cloud environment with a command-line interface (CLI) and the web console.

5.1. Preparing Your Host System for Using OpenShift

To use the oc command on your host system to interact with the OpenShift service running inside the CDK virtual machine, you need to obtain and install the oc executable.

If you intend to use OpenShift (and the oc command) only from within the CDK virtual machine, no preparation is required — the oc command is installed in the CDK box by default.

5.1.1. Obtaining the oc Executable

Download an archive with the executable for your operating system (Linux, Mac OS X, or Windows) from the Red Hat Customer Portal: Red Hat OpenShift Enterprise (you need to log in to the Customer Portal and have an active OpenShift Enterprise subscription to be able to access the download page).

Note that downloading this archive is not necessary if you use Red Hat Enterprise Linux as your host system because the oc executable can be installed from system repositories using yum. See Installing the oc Executable on Red Hat Enterprise Linux for details.

5.1.2. Installing the oc Executable on Red Hat Enterprise Linux

Install the atomic-openshift-clients package, which provides the oc executable. The package is available from the rhel-7-server-ose-3.1-rpms (Red Hat OpenShift Enterprise 3.1) repository. Use the following command as root to enable the repository (you need to have an active OpenShift Enterprise subscription to be able to access the repository):

~]# subscription-manager repos --enable=rhel-7-server-ose-3.1-rpms
Copy to Clipboard Toggle word wrap

Install the atomic-openshift-clients package using the following command as root:

~]# yum install -y atomic-openshift-clients
Copy to Clipboard Toggle word wrap

5.1.3. Installing the oc Executable on Fedora or Other Linux Distribution

Unpack the oc executable from the archive obtained using instructions in Obtaining the oc Executable to a directory of your choice and add that directory to your PATH, so that the oc command can be used without specifying its location.

For example, to unpack the executable to the ~/openshift directory and configure the PATH variable accordingly, run the following commands from the directory to which you downloaded the archive:

~]$ mkdir ~/openshift

~]$ tar xvzf oc-3.1.1.6-linux.tar.gz --strip=8 -C ~/openshift
mnt/redhat/staging-cds/ose-clients-3.1.1.6/usr/share/atomic-openshift/linux/oc

~]$ export PATH=$PATH:~/openshift
Copy to Clipboard Toggle word wrap

5.1.4. Installing the oc Executable on Mac OS X

Unpack the oc executable from the archive obtained using instructions in Obtaining the oc Executable to a directory of your choice and add that directory to your PATH, so that the oc command can be used without specifying its location.

For example, to unpack the executable to the ~/openshift directory and configure the PATH variable accordingly, run the following commands from the directory to which you downloaded the archive:

~]$ mkdir ~/openshift

~]$ tar xvzf oc-3.1.1.6-macosx.tar.gz --strip=8 -C ~/openshift
mnt/redhat/staging-cds/ose-clients-3.1.1.6/usr/share/atomic-openshift/macosx/oc

~]$ export PATH=$PATH:~/openshift
Copy to Clipboard Toggle word wrap

5.1.5. Installing the oc.exe Executable on Windows

Unpack the oc.exe executable from the archive obtained using instructions in Obtaining the oc Executable to a folder of your choice and add that folder to your PATH, so that the oc command can be used without specifying its location.

For example, to unpack the executable to the C:\Program Files (x86)\openshift folder and configure the PATH variable accordingly, run the following commands (using the Command Prompt or other terminal emulator) from the folder to which you downloaded the archive:

C:\Downloads> mkdir C:\Program Files (x86)\openshift

C:\Downloads> cd C:\Program Files (x86)\openshift

C:\Program Files (x86)\openshift> unzip -j oc-3.1.1.6-windows.zip
Archive:  oc-3.1.1.6-windows.zip
  inflating: oc.exe

C:\Program Files (x86)\openshift> set PATH=%PATH%;"C:\Program Files (x86)\openshift"
Copy to Clipboard Toggle word wrap

5.2. Verifying the OpenShift Installation

Upon initializing the CDK Vagrant box using the rhel-ose Vagrantfile, the following information is output about the OpenShift service that has been provisioned for you:

You can now access the OpenShift console on: https://10.1.2.2:8443/console

To use OpenShift CLI, run:
$ vagrant ssh
$ oc login 10.1.2.2:8443

Configured users are (<username>/<password>):
openshift-dev/devel
admin/admin

If you have the oc client library on your host, you can also login from your host.
Copy to Clipboard Toggle word wrap

The automatically provisioned instance of OpenShift Enterprise in CDK is provided in the form of a container. You can check that the OpenShift container is installed and running by examining the output of the docker ps command:

~]$ docker ps
CONTAINER ID  IMAGE      COMMAND                 CREATED      STATUS      PORTS  NAMES
...
ddb2d13604ef  openshift  "/usr/bin/openshift s"  2 hours ago  Up 2 hours         openshift
Copy to Clipboard Toggle word wrap

You can also run a health check to determine whether OpenShift is running properly by querying its network interface using the curl command:

~]$ curl -k https://10.1.2.2:8443/healthz
ok
Copy to Clipboard Toggle word wrap

5.3. Displaying Information about the OpenShift Service

The command-line interface of OpenShift is accessed using the oc command. This command has a number of subcommands that help to interact with various features of the OpenShift service. This section describes how to use the oc command to gather basic information about the current OpenShift instance.

5.3.1. Checking the Version of OpenShift and Kubernetes

Use the oc version command to display the version of OpenShift Enterprise and the Kubernetes service currently in use:

~]$ oc version
oc v3.1.0.4-16-g112fcc4
kubernetes v1.1.0-origin-1107-g4c8e6f4
Copy to Clipboard Toggle word wrap

5.4. Logging in and out of the OpenShift Server

Use the oc login command to log into specific user profiles. Upon start up, the CDK box logs you in automatically to the openshift-dev account.

5.4.1. Logging in to the OpenShift Server

Use the oc login command to log into the OpenShift server. If you want top log in from your hosty system, you to specify a host address (10.1.2.2:8443). The command asks for the username and password interactively, but you can also supply this information on the command line using the -u (--username) and -p (--password) options respectively. For example, to log into the default OpenShift instance in CDK from your host system, use the following command:

~]$ oc login -u openshift-dev -p devel https://10.1.2.2:8443
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://10.1.2.2:8443 (openshift)
Username: openshift-dev
Password:
Login successful.

You have access to the following projects and can switch between them with 'oc project <projectname>':

  * sample-project (current)

Using project "sample-project".
Welcome! See 'oc help' to get started.
Copy to Clipboard Toggle word wrap

Use the oc whoami command to check the user account to which you are currently logged:

~]$ oc whoami
openshift-dev
Copy to Clipboard Toggle word wrap

5.4.2. Viewing Current OpenShift CLI Configuration

To display the configuration values for the command-line environment, use the oc config view. For example, to show the part of the configuration pertaining to the default user name (openshift-dev), issue the following command:

~]$ oc config view | grep -A2 "name: openshift-dev"
- name: openshift-dev/10-1-2-2:8443
  user:
    token: THdHS4sw1qgzs95CnCf5ic6D8eOrZss1aT5jyGOmd2w
Copy to Clipboard Toggle word wrap

5.4.3. Logging out of the OpenShift Server

To log out, use the oc logout command:

~]$ oc logout
Logged "openshift-dev" out on "https://10.1.2.2:8443"
Copy to Clipboard Toggle word wrap

5.5. Working with OpenShift Projects

In OpenShift, projects are used to organize and manage applications by groups of users. Individual projects keep their content separated from each other, and individual users need to be granted access to projects. Upon start up, the CDK box automatically creates the sample-project project.

5.5.1. Creating a New OpenShift Project

Use the oc new-project command to create a new project on the OpenShift server you are currently logged in to. The following example uses the optional --display-name option to set a user-friendly name for the project:

~]$ oc new-project testing --display-name="Test Project"
Now using project "testing" on server "https://127.0.0.1:8443".

You can add applications to this project with the 'new-app' command. For example, try:

    $ oc new-app centos/ruby-22-centos7~https://github.com/openshift/ruby-hello-world.git

to build a new hello-world application in Ruby.
Copy to Clipboard Toggle word wrap

5.5.2. Switching to a Different OpenShift Project

Use the oc project <project-name> command to switch to another project on the OpenShift server you are currently logged in to. The following switches to the default sample-project project:

~]$ oc project sample-project
Now using project "sample-project" on server "https://10.1.2.2:8443".
Copy to Clipboard Toggle word wrap

5.5.3. Listing Available Projects

To list projects available on the server and their status, use the oc get projects command. Note that the oc get command can be used to display information about a number of other resources besides projects (pods, builds, services, etc.). In the following example, only the project created in the preceeding example is shown:

~]$ oc get project
NAME      DISPLAY NAME   STATUS
testing   Test Project   Active
Copy to Clipboard Toggle word wrap

5.5.4. Displaying Status Information about the Currently Used Project

Run the oc status command to display information about the currently used project and about activities (services, builds, deployments, etc.) within that project. When executed in a new (empty) project, the output looks like the following:

~]$ oc status
In project Test Project (testing) on server https://10.1.2.2:8443

You have no services, deployment configs, or build configs.
Run 'oc new-app' to create an application.
Copy to Clipboard Toggle word wrap

Alternatively, you can also use the oc project command to display project information:

~]$ oc project
Using project "testing" from context named "testing/10-1-2-2:8443/openshift-dev" on server "https://10.1.2.2:8443".
Copy to Clipboard Toggle word wrap

5.5.5. Deleting a Project

To remove a project from the server, use the oc delete project command and specify the name of the project you want deleted. To remove all projects, include the --all option. Note that the oc delete command can be used to delete other resources (pods, services, etc.) as well. For example, to delete the project created in this section, run the following command:

~]$ oc delete project testing
project "testing" deleted
Copy to Clipboard Toggle word wrap

5.6. Working with OpenShift Templates

A template in OpenShift is a text file (in the JSON or YAML format) that defines a set of objects. The object definitions, such as services or build configurations, can be parametrized. Templates can be processed to create the objects they describe and thus populate your current project.

To get you quickly started with application development, OpenShift offers a number of basic templates, which are included in the global openshift project. In order to use these templates as the foundation block of a new application, they need to be downloaded from the openshift project and subsequently uploaded to your current project. You can also create a new application (using the oc new-app command) directly from a template.

5.6.1. Listing Available Templates

To display the templates available in a project, issue the oc get templates command and use the -n option to specify the project from which you wish to list the templates. For example, to list the templates available in the global openshift project, run:

~]$ oc get templates -n openshift
NAME                                DESCRIPTION                        PARAMETERS     OBJECTS
cakephp-example                     An example CakePHP application...  15 (8 blank)   5
cakephp-mysql-example               An example CakePHP application...  16 (3 blank)   7
eap64-basic-s2i                     Application template for EAP 6...  12 (3 blank)   5
eap64-mysql-persistent-s2i          Application template for EAP 6...  34 (16 blank)  10
jws30-tomcat7-mysql-persistent-s2i  Application template for JWS M...  28 (11 blank)  10
nodejs-example                      An example Node.js application...  12 (8 blank)   5
nodejs-mongodb-example              An example Node.js application...  13 (3 blank)   7
Copy to Clipboard Toggle word wrap

5.6.2. Downloading an InstantApp Template

To obtain a template definition file, which can be used for uploading to your project, use the oc get templates command and specify the project in which the template is located (using the -n or --namespace option), choose the format in which you wish to store the template (typically JSON or YAML — use the -o or --output option), and supply the name of the requested template. Note that by default, the oc get command outputs the requested data to the standard output. To store the template in a file, redirect the output of the command to a file.

For example, to download the nodejs-mongodb-example template from the global openshift project and save it in the JSON format on your local syastem, use the following command:

~]$ oc get templates -o json -n openshift nodejs-mongodb-example \ > nodejs-mongodb-example.json

~]$ ls
nodejs-mongodb-example.json
Copy to Clipboard Toggle word wrap

5.6.3. Modifying the Namespace (Project Name)

When you download an InstantApp template from the default openshift project, the namespace (project name) in the template is set to openshift. To be able to upload the template to your project, you need to modify the template accordingly. If you do not do that, the upload fails with the following error message:

~]$ oc create -f nodejs-mongodb-example.json -n testing
the namespace from the provided object "openshift" does not match the namespace "testing". You must pass '--namespace=openshift' to perform this operation.
Copy to Clipboard Toggle word wrap

To modify the namespace, edit the file using a text editor, such as vi, and in the metadata section, replace the value of the namespace parameter with the name of your project. For example, to use the name testing, the beginning of the nodejs-mongodb-example.json template file would look like this:

{
    "kind": "Template",
    "apiVersion": "v1",
    "metadata": {
        "name": "nodejs-mongodb-example",
        "namespace": "testing",
[...]
Copy to Clipboard Toggle word wrap

5.6.4. Uploading a Template to the Current Project

For a template to be available for use in your project, it must be first uploaded to it. Use the oc create command to do this and specify the template file using the -f or --filename option. For example, to upload the nodejs-mongodb-example InstantApp template obtained from the openshift project, run the following command:

~]$ oc create -f nodejs-mongodb-example.json
template "nodejs-mongodb-example" created
Copy to Clipboard Toggle word wrap

To verify that the template has been successfully uploaded, use the oc get templates command. Optionally, you can specify the namespace from which you wish to list by using the -n or --namespace option. By default, templates from the currently used project are listed:

~]$ oc get templates
NAME                     DESCRIPTION                                              PARAMETERS     OBJECTS
nodejs-mongodb-example   An example Node.js application with a MongoDB database   11 (3 blank)   7
Copy to Clipboard Toggle word wrap

5.6.5. Listing Template Parameters

To list the parameters that a template specifies along with short descriptions and predefined values, use the oc process command with the --parameters option. For example, to list the parameters used by the nodejs-mongodb-example template, use the following command:

~]$ oc process --parameters nodejs-mongodb-example
NAME                     DESCRIPTION                              GENERATOR   VALUE
SOURCE_REPOSITORY_URL    The URL of the repository with your...               https://github.com/openshift/nodejs-ex.git
SOURCE_REPOSITORY_REF    Set this to a branch name, tag or ot...
CONTEXT_DIR              Set this to the relative path to you...
APPLICATION_DOMAIN       The exposed hostname that will route...
GITHUB_WEBHOOK_SECRET    A secret string used to configure th...  expression  [a-zA-Z0-9]{40}
GENERIC_WEBHOOK_SECRET   A secret string used to configure th...  expression  [a-zA-Z0-9]{40}
DATABASE_SERVICE_NAME    Database service name                                         mongodb
DATABASE_USER            Username for MongoDB user that will...   expression  user[A-Z0-9]{3}
DATABASE_PASSWORD        Password for the MongoDB user            expression  [a-zA-Z0-9]{16}
DATABASE_NAME            Database name                                        sampledb
DATABASE_ADMIN_PASSWORD  Password for the database admin user...  expression  [a-zA-Z0-9]{16}
Copy to Clipboard Toggle word wrap

5.6.6. Creating Objects from a Template

To process a template and use it to create the objects it defines in your project, use a combination of the oc process and oc create commands. The template processed by the oc process command can be piped to the oc create command.

Note that in most cases, the template parameters need to be modified, so that the resulting application can be useful in a real-world scenario. To modify the template parameters when creating the objects, use the -v or --value option.

For example, to create objects using the nodejs-mongodb-example template and to set a different source repository for the application (the original repository would need to be forked to the repository specified on the command line), use the following combination of commands:

~]$ oc process nodejs-mongodb-example \
-v SOURCE_REPOSITORY_URL=https://github.com/username/nodejs-ex.git | \
oc create -f -
service "nodejs-mongodb-example" created
route "nodejs-mongodb-example" created
imagestream "nodejs-mongodb-example" created
buildconfig "nodejs-mongodb-example" created
deploymentconfig "nodejs-mongodb-example" created
service "mongodb" created
deploymentconfig "mongodb" created
Copy to Clipboard Toggle word wrap

In the above example, substitute username for the name of the GitHub account into which the original repository was forked.

5.7. Additional Resources

  • See the output of the oc help command for an overview of all oc subcommands available. More detailed help for individual subcommands can be accessed by running oc help [subcommand].
  • See the OpenShift Enterprise CLI Reference for detailed descriptions of the command-line user interface used to interact with OpenShift Enterprise.
  • See the OpenShift Enterprise Developer Guide for detailed instructions and examples to help developers configure a workstation to develop and deploy applications in an OpenShift Enterprise cloud environment with a command-line interface.
トップに戻る
Red Hat logoGithubredditYoutubeTwitter

詳細情報

試用、購入および販売

コミュニティー

Red Hat ドキュメントについて

Red Hat をお使いのお客様が、信頼できるコンテンツが含まれている製品やサービスを活用することで、イノベーションを行い、目標を達成できるようにします。 最新の更新を見る.

多様性を受け入れるオープンソースの強化

Red Hat では、コード、ドキュメント、Web プロパティーにおける配慮に欠ける用語の置き換えに取り組んでいます。このような変更は、段階的に実施される予定です。詳細情報: Red Hat ブログ.

会社概要

Red Hat は、企業がコアとなるデータセンターからネットワークエッジに至るまで、各種プラットフォームや環境全体で作業を簡素化できるように、強化されたソリューションを提供しています。

Theme

© 2025 Red Hat