Exercise 1.0 - Deploy OpenShift

Return to Workshop

openshift ocp

OpenShift v3 is a layered system designed to expose underlying Docker-formatted container image and Kubernetes concepts as accurately as possible, with a focus on easy composition of applications by a developer. For example, install Ruby, push code, and add MySQL.

OpenShift

Step 1:

Use the oc command

These instances have been preconfigured with docker and the oc command. The oc command makes deploying OpenShift for development purposes incredibly easy. The oc cluster up command starts a OpenShift all-in-one cluster with a configured registry, router, image streams, and default templates.

switch to root
sudo -i
make a /data dir
mkdir /data

Next use the following command to bring up the cluster on your local machine.

<div class="alert alert-warning">

<span class="pficon pficon-warning-triangle-o"></span>

But first! export your student number to sync up with the wildcard DNS mapped to your instance. For example below, if you are student 0 then export STUDENT=0.

</div>

Change the number to your student number
export STUDENT=0
Run the oc command (you can cut & paste this)
oc cluster up --public-hostname=$(curl -s http://169.254.169.254/latest/meta-data/public-ipv4) --routing-suffix=apps.ocp.$STUDENT.redhatgov.io --host-pv-dir=/data --host-data-dir=/data
Successful Build (example)
Using nsenter mounter for OpenShift volumes
Using public hostname IP 107.21.72.239 as the host IP
Using 107.21.72.239 as the server IP
Starting OpenShift using openshift/origin:v3.9.0 ...
OpenShift server started.
The server is accessible via web console at:
    https://107.21.72.239:8443 (1)
You are logged in as:
    User:     developer
    Password: <any value>
To login as administrator:
    oc login -u system:admin
1 OpenShift Web Console, EXAMPLE: https://107.21.72.239:8443 or use the DNS name with your student number, Example: https://openshiftsecurity.0.redhatgov.io:8443

Step 2:

Launch your first application.

see what user you are loged in as
oc whoami

You should be logged in as developer

Create a new Project for your first app.

create new project
oc new-project flask --description="Python Flask App" --display-name="Flask App"

Now use the new-app command to create the new app from a simple Python flask repository on GitHub. By using the --strategy=source we can pass it the type of container to build and launch the app. In this case we are using python:3.5.

create the app
oc new-app --strategy=source python:3.5~https://github.com/RedHatGov/OCP-App.git --name=flask-app

Now follow the logs as its being built.

follow the logs
oc logs -f bc/flask-app

Open a browser next to the terminal so you can see the app get created

Step 3:

Login to OpenShift

Login as developer
Username:  developer

Password:  developer
login ocp
Figure 1. OpenShift Main Login

Click on the new project you created Flask App.

flask app
Figure 2. Flask App

Now we need to create a route to see the app.

Click Create Route in the top right corner. Accept the defaults and click create.

create route
Figure 3. create route

Now lets see your first app. Click the new route. It should look similar to this http://http://flask-app-flask.apps.ose.0.redhatgov.io.

Congratulations! You have launched your first app in OpenShift!

To recap:

  • You just launched OpenShift on AWS

  • You launched a containerized python app

Extra credit

Details on the oc command (Informational Only)
oc cluster up \
   --public-hostname=$(curl -s http://169.254.169.254/latest/meta-data/public-ipv4) \ (1)
   --routing-suffix=apps.ocp.$STUDENT.redhatgov.io \ (2)
   --host-pv-dir=/data \ (3)
   --host-data-dir=/data  (4)
1 This sets OpenShift’s public name to the public ip of the AMI, via the AWS metadata service (169.254.169.254).
2 This sets the wildcard domain for all of the applications you provision in OpenShift.
3 Cluster up creates a set of persistent volumes by default. It exposes a new flag that allows setting the directory on the host for these volumes.
4 To persist data across restarts, specify a valid host directory when starting your cluster with oc cluster up.

Return to Workshop