01 OpenShift Container Platform 3.11 Getting Started en US
01 OpenShift Container Platform 3.11 Getting Started en US
11
Getting Started
The text of and illustrations in this document are licensed by Red Hat under a Creative Commons
Attribution–Share Alike 3.0 Unported license ("CC-BY-SA"). An explanation of CC-BY-SA is
available at
http://creativecommons.org/licenses/by-sa/3.0/
. In accordance with CC-BY-SA, if you distribute this document or an adaptation of it, you must
provide the URL for the original version.
Red Hat, as the licensor of this document, waives the right to enforce, and agrees not to assert,
Section 4d of CC-BY-SA to the fullest extent permitted by applicable law.
Red Hat, Red Hat Enterprise Linux, the Shadowman logo, the Red Hat logo, JBoss, OpenShift,
Fedora, the Infinity logo, and RHCE are trademarks of Red Hat, Inc., registered in the United States
and other countries.
Linux ® is the registered trademark of Linus Torvalds in the United States and other countries.
XFS ® is a trademark of Silicon Graphics International Corp. or its subsidiaries in the United States
and/or other countries.
MySQL ® is a registered trademark of MySQL AB in the United States, the European Union and
other countries.
Node.js ® is an official trademark of Joyent. Red Hat is not formally related to or endorsed by the
official Joyent Node.js open source or commercial project.
The OpenStack ® Word Mark and OpenStack logo are either registered trademarks/service marks
or trademarks/service marks of the OpenStack Foundation, in the United States and other
countries and are used with the OpenStack Foundation's permission. We are not affiliated with,
endorsed or sponsored by the OpenStack Foundation, or the OpenStack community.
Abstract
Whether you are a developer or a platform administrator, you can get started with OpenShift using
the topics in this book. Administrators can use the installation utility and an interactive CLI tool, to
quickly install and configure a new OpenShift instance across multiple hosts. Developers can use
the OpenShift CLI or the web console to log in to an existing OpenShift instance and start creating
applications.
Table of Contents
Table of Contents
.CHAPTER
. . . . . . . . . . 1.. .OVERVIEW
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3. . . . . . . . . . . . .
1.1. INTRODUCTION 3
1.1.1. Why Should I Use OpenShift? 3
.CHAPTER
. . . . . . . . . . 2.
. . INSTALL
. . . . . . . . . .OPENSHIFT
. . . . . . . . . . . . .CONTAINER
. . . . . . . . . . . . . PLATFORM
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4. . . . . . . . . . . . .
2.1. OVERVIEW 4
2.1.1. Prerequisites 4
2.1.2. Attach OpenShift Container Platform Subscription 4
2.1.3. Set Up Repositories 5
2.1.4. Install the OpenShift Container Platform Package 5
2.1.5. Set up Password-less SSH Access 6
2.1.6. Run the Installation Playbooks 6
2.2. INTERACT WITH OPENSHIFT CONTAINER PLATFORM 7
2.3. UNDERSTAND ROLES AND AUTHENTICATION 7
.CHAPTER
. . . . . . . . . . 3.
. . CONFIGURE
. . . . . . . . . . . . . .OPENSHIFT
. . . . . . . . . . . . .CONTAINER
. . . . . . . . . . . . .PLATFORM
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9. . . . . . . . . . . . .
3.1. OVERVIEW 9
3.2. CHANGE LOG IN IDENTITY PROVIDER 9
3.3. CREATE USER ACCOUNTS 9
3.4. DEPLOY THE OPENSHIFT ROUTER 10
3.5. DEPLOY AN INTERNAL REGISTRY 10
.CHAPTER
. . . . . . . . . . 4.
. . .CREATE
. . . . . . . . .AND
. . . . .BUILD
. . . . . . .AN
. . . IMAGE
. . . . . . . .USING
. . . . . . . THE
. . . . .WEB
. . . . . CONSOLE
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
..............
4.1. OVERVIEW 12
4.1.1. Browser Requirements 13
4.2. BEFORE YOU BEGIN 13
4.3. FORKING THE SAMPLE REPOSITORY 13
4.4. CREATING A PROJECT 14
4.5. CREATING AN APPLICATION 14
4.6. VERIFY THE APPLICATION IS RUNNING 15
4.7. CONFIGURING AUTOMATED BUILDS 15
4.8. WRITING A CODE CHANGE 15
4.8.1. Manually Rebuilding Images 16
.CHAPTER
. . . . . . . . . . 5.
. . CREATE
. . . . . . . . . AND
. . . . . .BUILD
. . . . . . .AN
. . . IMAGE
. . . . . . . .USING
. . . . . . . THE
. . . . .CLI
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
..............
5.1. OVERVIEW 17
5.2. BEFORE YOU BEGIN 18
5.3. FORKING THE SAMPLE REPOSITORY 18
5.4. CREATING A PROJECT 18
5.5. CREATING AN APPLICATION 19
5.6. CREATE A ROUTE 20
5.7. VERIFY THE APPLICATION IS RUNNING 20
5.8. CONFIGURING AUTOMATED BUILDS 20
5.9. WRITING A CODE CHANGE 21
5.9.1. Manually Rebuilding Images 21
5.10. TROUBLESHOOTING 21
1
OpenShift Container Platform 3.11 Getting Started
2
CHAPTER 1. OVERVIEW
CHAPTER 1. OVERVIEW
1.1. INTRODUCTION
OpenShift Container Platform brings together Docker and Kubernetes, and provides an API to manage
these services. OpenShift Container Platform allows you to create and manage containers.
Think of OpenShift as an operating system, images as applications that you run on them, and the
containers as the actual running instances of those applications.
3
OpenShift Container Platform 3.11 Getting Started
2.1. OVERVIEW
This guide introduces you to the basic concepts of OpenShift Container Platform, and helps you install a
basic application. This guide is not suitable for deploying or installing a production environment of
OpenShift Container Platform.
2.1.1. Prerequisites
To install OpenShift Container Platform, you will need:
At least two physical or virtual RHEL 7+ machines, with fully qualified domain names (either real
world or within a network) and password-less SSH access to each other. This guide uses
master.openshift.example.com and node.openshift.example.com. These machines must be
able to ping each other using these domain names. If you use IBM POWER servers, all servers in
your cluster must be IBM POWER servers.
Wildcard DNS resolution that resolves your domain to the IP of the node. So, an entry like the
following in your DNS server:
WHY THE APPS IN YOUR DOMAIN NAME FOR THE WILDCARD ENTRY?
Once these are configured, use the following steps to set up a two-machine OpenShift Container
Platform install.
# subscription-manager register
2. Pull the latest subscription data from Red Hat Subscription Manager (RHSM):
# subscription-manager refresh
4
CHAPTER 2. INSTALL OPENSHIFT CONTAINER PLATFORM
4. Find the pool ID that provides OpenShift Container Platform subscription and attach it.
5. Replace the string <pool_id> with the pool ID of the pool that provides OpenShift Container
Platform. The pool ID is a long alphanumeric string.
These RHEL systems are now authorized to install OpenShift Container Platform. Now you need to tell
the systems from where to get OpenShift Container Platform.
For cloud installations and on-premise installations on x86_64 servers, run the following
command:
For on-premise installations on IBM POWER8 servers, run the following command:
# subscription-manager repos \
--enable="rhel-7-for-power-le-rpms" \
--enable="rhel-7-for-power-le-extras-rpms" \
--enable="rhel-7-for-power-le-optional-rpms" \
--enable="rhel-7-server-ansible-2.6-for-power-le-rpms" \
--enable="rhel-7-server-for-power-le-rhscl-rpms" \
--enable="rhel-7-for-power-le-ose-3.11-rpms"
For on-premise installations on IBM POWER9 servers, run the following command:
# subscription-manager repos \
--enable="rhel-7-for-power-9-rpms" \
--enable="rhel-7-for-power-9-extras-rpms" \
--enable="rhel-7-for-power-9-optional-rpms" \
--enable="rhel-7-server-ansible-2.6-for-power-9-rpms" \
--enable="rhel-7-server-for-power-9-rhscl-rpms" \
--enable="rhel-7-for-power-9-ose-3.11-rpms"
This command tells your RHEL system that the tools required to install OpenShift Container Platform
will be available from these repositories. Now we need the OpenShift Container Platform installer that is
based on Ansible.
5
OpenShift Container Platform 3.11 Getting Started
The installer for OpenShift Container Platform is provided by the openshift-ansible package. Install it
using yum on the master after running yum update.
# yum -y install wget git net-tools bind-utils iptables-services bridge-utils bash-completion kexec-tools
sos psacct
# yum -y update
# reboot
To install CRI-O:
To install Docker:
$ ssh-keygen
Follow the prompts and just hit enter when asked for pass phrase.
IMPORTANT
Running Ansible playbooks with the --tags or --check options is not supported by
Red Hat.
NOTE
6
CHAPTER 2. INSTALL OPENSHIFT CONTAINER PLATFORM
NOTE
1. Edit the example inventory to use your host names, and then save it to a file. The default
location is /etc/ansible/hosts.
2. Change to the playbook directory and run the prerequisites.yml playbook using your inventory
file:
$ cd /usr/share/ansible/openshift-ansible
$ ansible-playbook -i <inventory_file> playbooks/prerequisites.yml
3. Change to the playbook directory and run the deploy_cluster.yml playbook using your inventory
file:
$ cd /usr/share/ansible/openshift-ansible
$ ansible-playbook -i <inventory_file> playbooks/deploy_cluster.yml
After a successful install, but before you add a new project, you must set up basic authentication, user
access, and routes.
In addition, you can use the web console to manage projects and applications. The web console is
available at https://<master_fqdn>:8443/console. In the next section, you will see how to create user
accounts for accessing the console.
NOTE
You can interact with your OpenShift Container Platform instance from a remote system
as well, using these command line utilities. Bundled as the OpenShift CLI, you can
download these utilities for Windows, Mac, or Linux environments in the CLI Reference
section.
7
OpenShift Container Platform 3.11 Getting Started
Before you do anything else, log in at least one time with the default system:admin user. On the master,
run the following command:
$ oc login -u system:admin
NOTE
All commands from now on should be executed on the master, unless otherwise indicated.
By logging in at least one time with this account, you will create the system:admin user’s configuration
file, which will allow you to log in subsequently.
Run the following command to verify that OpenShift Container Platform was installed and started
successfully. You will get a listing of the master and node, in the Ready status.
$ oc get nodes
To continue configuring your basic OpenShift Container Platform environment, follow the steps outlined
in Configure OpenShift Container Platform.
8
CHAPTER 3. CONFIGURE OPENSHIFT CONTAINER PLATFORM
3.1. OVERVIEW
This guide introduces you to the basic concepts of OpenShift Container Platform, and helps you
configure a basic application. This guide provides the configuration steps following the installation of a
basic OpenShift Container Platform environment, and is not suitable for deploying or installing a
production environment of OpenShift.
4. Change the value of the name label to htpasswd_auth and add a new line file:
/etc/origin/master/htpasswd in the provider section.
An example identityProviders section with HTPasswdPasswordIdentityProvider would look
like the following.
oauthConfig:
...
identityProviders:
- challenge: true
login: true
name: htpasswd_auth provider
provider:
apiVersion: v1
kind: HTPasswdPasswordIdentityProvider
file: /etc/origin/master/htpasswd
1. You can use the httpd-tools package to obtain the htpasswd binary that can generate these
accounts.
9
OpenShift Container Platform 3.11 Getting Started
# touch /etc/origin/master/htpasswd
# htpasswd -b /etc/origin/master/htpasswd admin redhat
# master-restart api
# master-restart controllers
When running oc adm commands, you should run them only from the first master listed in the
Ansible host inventory file, by default /etc/ansible/hosts.
5. You can use this username/password combination to log in via the web console or the
command line. To test this, run the following command.
$ oc login -u admin
$ oc project default
Without the router, OpenShift services and pods are unable to communicate with any resource outside
of the OpenShift instance.
Openshift provides an internal, integrated container image registry that can be deployed to locally
10
CHAPTER 3. CONFIGURE OPENSHIFT CONTAINER PLATFORM
Openshift provides an internal, integrated container image registry that can be deployed to locally
manage images. OpenShift uses the docker-registry to store, retrieve, and build container images, as
well as deploy and manage them throughout their lifecycle.
11
OpenShift Container Platform 3.11 Getting Started
4.1. OVERVIEW
This getting started experience walks you through the simplest way to get a sample project up and
running on OpenShift Container Platform. There are a few different ways to launch images within a
project, but this topic focuses on the quickest and easiest method.
If this is the first part of the documentation you have read, and you are unfamiliar with the core concepts
of OpenShift Container Platform version 3 (v3), you might want to start by reading about what’s new.
This version of OpenShift Container Platform is significantly different from version 2 (v2).
OpenShift Container Platform 3 provides out of the box a set of languages and databases for
developers with corresponding implementations and tutorials that allow you to kickstart your application
development. Language support centers around the Quickstart templates, which in turn leverage builder
images.
Ruby Rails
Python Django
Node.js Node.js
PHP CakePHP
Perl Dancer
Java
MySQL
MongoDB
PostgreSQL
Jenkins
In addition, JBoss Middleware has put together a broad range of OpenShift Container Platform
templates.
Integration and Messaging Services provided by JBoss Fuse and JBoss A-MQ
12
CHAPTER 4. CREATE AND BUILD AN IMAGE USING THE WEB CONSOLE
To help illustrate constructing such applications, the following sections guide you through creating a
project that contains a sample Node.js application that will serve a welcome page and the current hit
count (stored in a database).
NOTE
This topic discusses both Quickstart and Instant App templates and applications.
Quickstarts provide a starting point for application development, but they rely on your
development to create a useful application. In contrast, Instant Apps like Jenkins are
instantly usable.
You must be able to access a running instance of OpenShift Container Platform. If you do not
have access, contact your cluster administrator.
Your instance must be pre-configured by a cluster administrator with the Instant App templates
and builder images. If they are not available, direct your cluster administrator to the Loading the
Default Image Streams and Templates topic.
You must have the OpenShift Container Platform CLI downloaded and installed.
NOTE
This topic follows the Ruby example, but you can follow along using any of the
language examples provided in the OpenShift Container Platform GitHub
project.
13
OpenShift Container Platform 3.11 Getting Started
1. Visit the OpenShift Container Platform web console in your browser. The web console uses a
self-signed certificate, so if prompted, continue past a browser warning.
2. Log in using the username and password recommended to you by your administrator.
4. Type a unique name, display name, and description for the new project.
5. Click Create.
The web console’s welcome screen loads.
1. If creating a new project did not automatically redirect you to the Select Image or Template
page, you might need to click Add to Project.
4. Type a name for your application, and specify the Git Repository URL, which is
https://github.com/<your_github_username>/ruby-ex.git.
5. Optionally, click Show advanced routing, build, and deployment options, though by default
this example application automatically creates a route, webhook trigger, and build change
triggers.
6. Click Create.
NOTE
After creation, some of these settings can be modified from the web console by
clicking Browse, Builds, select your build, then click Actions, and either Edit or
Edit YAML.
Creating your application might take some time. You can follow along on the Overview page of the web
console to see the new resources being created, and watch the progress of the build and deployment.
While the Ruby pod is being created, its status is shown as pending. The Ruby pod then starts up and
displays its newly-assigned IP address. When the Ruby pod is running, the build is complete.
14
CHAPTER 4. CREATE AND BUILD AN IMAGE USING THE WEB CONSOLE
1. From the Web Console, navigate to the project containing your application.
4. Click next to GitHub webhook URL to copy your webhook payload URL.
GitHub now attempts to send a ping payload to your OpenShift Container Platform server to ensure
that communication is successful. If you see a green check mark appear next to your webhook URL, then
it is correctly configured. Hover your mouse over the check mark to see the status of the last delivery.
The next time you push a code change to your forked repository, your application will automatically
rebuild.
1. On your local machine, use a text editor to change the sample application’s source for the file
ruby-ex/config.ru
2. Make a code change that will be visible from within your application. For example: on line 229,
change the title from Welcome to your Ruby application on OpenShift to This is my
Awesome OpenShift Application, then save your changes.
3. Commit the change in git, and push the change to your fork.
If your webhook is correctly configured, your application will immediately rebuild itself based on
your changes. Once the rebuild is successful, view your updated application using the route that
was created earlier.
15
OpenShift Container Platform 3.11 Getting Started
Now going forward, all you need to do is push code updates and OpenShift Container Platform handles
the rest.
16
CHAPTER 5. CREATE AND BUILD AN IMAGE USING THE CLI
5.1. OVERVIEW
This getting started experience walks you through the simplest way to get a sample project up and
running on OpenShift Container Platform. There are a few different ways to launch images within a
project, but this topic focuses on the quickest and easiest method.
If this is the first part of the documentation you have read, and you are unfamiliar with the core concepts
of OpenShift Container Platform version 3 (v3), you might want to start by reading about what’s new.
This version of OpenShift Container Platform is significantly different from version 2 (v2).
OpenShift Container Platform 3 provides out of the box a set of languages and databases for
developers with corresponding implementations and tutorials that allow you to kickstart your application
development. Language support centers around the Quickstart templates, which in turn leverage builder
images.
Ruby Rails
Python Django
Node.js Node.js
PHP CakePHP
Perl Dancer
Java
MySQL
MongoDB
PostgreSQL
Jenkins
In addition, JBoss Middleware has put together a broad range of OpenShift Container Platform
templates.
Integration and Messaging Services provided by JBoss Fuse and JBoss A-MQ
17
OpenShift Container Platform 3.11 Getting Started
To help illustrate constructing such applications, the following sections guide you through creating a
project that contains a sample Node.js application that will serve a welcome page and the current hit
count (stored in a database).
NOTE
This topic discusses both Quickstart and Instant App templates and applications.
Quickstarts provide a starting point for application development, but they rely on your
development to create a useful application. In contrast, Instant Apps like Jenkins are
instantly usable.
You must be able to access a running instance of OpenShift Container Platform. If you do not
have access, contact your cluster administrator.
Your instance must be pre-configured by a cluster administrator with the Instant App templates
and builder images. If they are not available, direct your cluster administrator to the Loading the
Default Image Streams and Templates topic.
You must have the OpenShift Container Platform CLI downloaded and installed.
NOTE
This topic follows the Ruby example, but you can follow along using any of the
language examples provided in the OpenShift Container Platform GitHub
project.
18
CHAPTER 5. CREATE AND BUILD AN IMAGE USING THE CLI
To create an application, you must create a new project and specify the location of the source. From
there, OpenShift Container Platform begins the build process and creates a new deployment.
After creating the new project, you will be automatically switched to the new project namespace.
$ oc new-app openshift/ruby-20-centos7~https://github.com/<your_github_username>/ruby-
ex
OpenShift Container Platform finds the matching builder image (which in this case is ruby-20-
centos7) and then creates resources for the application (image stream, build configuration,
deployment configuration, service). It also schedules the build.
$ oc logs -f bc/ruby-ex
3. Once the build is complete and the resulting image has successfully pushed to your registry,
check the status of your application:
$ oc status
Creating your application might take some time. You can follow along on the Overview page of the web
console to see the new resources being created, and watch the progress of the build and deployment.
You can also use the oc get pods command to check when the pod is up and running, or the oc get
builds command to see build statistics.
While the Ruby pod is being created, its status is shown as pending. The Ruby pod then starts up and
displays its newly-assigned IP address. When the Ruby pod is running, the build is complete.
The oc status command tells you what IP address the service is running; the default port it deploys to is
19
OpenShift Container Platform 3.11 Getting Started
The oc status command tells you what IP address the service is running; the default port it deploys to is
8080.
$ oc get route
The example ruby-ex application is a simple welcome screen, and contains details on how to deploy
code changes, manage your application, and other development resources.
Next, configure automated builds via a GitHub webhook trigger, so that code changes in your forked
repository cause your application to rebuild.
1. View the triggers section of the BuildConfig to verify that a GitHub webhook trigger exists:
$ oc edit bc/ruby-ex
triggers
- github:
secret: Q1tGY0i9f1ZFihQbX07S
type: GitHub
The secret ensures that only you and your repository can trigger the build.
2. Run the following command to display the webhook URLs associated with your BuildConfig:
$ oc describe bc ruby-ex
3. Copy the GitHub webhook payload URL output by the above command.
20
CHAPTER 5. CREATE AND BUILD AN IMAGE USING THE CLI
GitHub now attempts to send a ping payload to your OpenShift Container Platform server to ensure
that communication is successful. If you see a green check mark appear next to your webhook URL, then
it is correctly configured. Hover your mouse over the check mark to see the status of the last delivery.
The next time you push a code change to your forked repository, your application will automatically
rebuild.
1. On your local machine, use a text editor to change the sample application’s source for the file
ruby-ex/config.ru
2. Make a code change that will be visible from within your application. For example: on line 229,
change the title from Welcome to your Ruby application on OpenShift to This is my
Awesome OpenShift Application, then save your changes.
3. Commit the change in git, and push the change to your fork.
If your webhook is correctly configured, your application will immediately rebuild itself based on
your changes. Once the rebuild is successful, view your updated application using the route that
was created earlier.
Now going forward, all you need to do is push code updates and OpenShift Container Platform handles
the rest.
$ oc start-build ruby-ex
5.10. TROUBLESHOOTING
Changing Projects
Although the oc new-project command automatically sets your current project to the one you’ve just
created, you can always change projects by running:
$ oc project <project-name>
21
OpenShift Container Platform 3.11 Getting Started
$ oc get projects
If the build does not start automatically, start a build and stream the logs:
Alternatively, do not include --follow in the above command, and instead issue the following command
after triggering the build, where n is the number of the build to track:
$ oc logs -f build/ruby-ex-n
22