Exercise 1.1 - OpenShift Templates

Return to Workshop

kernel

What are OpenShift Templates

A template describes a set of objects that can be parameterized and processed to produce a list of objects for creation by OpenShift Container Platform. A template can be processed to create anything you have permission to create within a project, for example services, build configurations, and deployment configurations. A template may also define a set of labels to apply to every object defined in the template.

You can create a list of objects from a template using the CLI or, if a template has been uploaded to your project or the global template library, using the web console. For a curated set of templates, see the OpenShift Image Streams and Templates library OpenShift Image Streams and Templates library.

Exploring OpenShift Templates

Step 1:

First lets create a new name space to work in. Namespaces are a way to get your own space of computing on a OpenShift cluster where you can deploy applications.

See Template Parameters
oc new-project template --description="Exploring Templates" --display-name="Templates"

Now lets look at a default template for the Nodejs & MongoDB template.

See Template Parameters
oc process --parameters -n openshift nodejs-mongo-persistent
Table 1. Windtrainer workouts
NAME DESCRIPTION GENERATOR VALUE

NAME

The name assigned to all of the frontend objects defined in this template.

NAMESPACE

The OpenShift Namespace where the ImageStream resides.

openshift

MEMORY_LIMIT

Maximum amount of memory the Node.js container can use.

512Mi

MEMORY_MONGODB_LIMIT

Maximum amount of memory the MongoDB container can use.

512Mi

VOLUME_CAPACITY

Volume space available for data, e.g. 512Mi, 2Gi

1Gi

SOURCE_REPOSITORY_URL

The URL of the repository with your application source code.

SOURCE_REPOSITORY_REF

Set this to a branch name, tag or other ref of your repository if you are not using the default branch.

CONTEXT_DIR

Set this to the relative path to your project if it is not in the root of your repository.

APPLICATION_DOMAIN

The exposed hostname that will route to the Node.js service, if left blank a value will be defaulted.

GITHUB_WEBHOOK_SECRET

Github trigger secret. A difficult to guess string encoded as part of the webhook URL. Not encrypted.

expression

[a-zA-Z0-9]{40}

GENERIC_WEBHOOK_SECRET

A secret string used to configure the Generic webhook.

expression

[a-zA-Z0-9]{40}

DATABASE_SERVICE_NAME

mongodb

DATABASE_USER

Username for MongoDB user that will be used for accessing the database.

expression

user[A-Z0-9]{3}

DATABASE_PASSWORD

Password for the MongoDB user.

expression

[a-zA-Z0-9]{16}

DATABASE_NAME

sampledb

DATABASE_ADMIN_PASSWORD

Password for the database admin user.

expression

[a-zA-Z0-9]{16}

In this example we see that we can, from a security angle control exactly what we want to run in our container environment. The Template is how we can configure what source code repositories we want to allow a end user run or developer to develop against. Templates define what the application limits can be for further constraining an applications memory, or storage. This is alo a place where we can pass environmental variables to the application as well.

Step 2:

Lets take a deeper look at Templates by switching over to a higher privileged user to be able to edit the Template with your built in editor of choice, (it’s VIM).

Login as the System user
oc login -u system:admin

OpenShift provides the ability to quickly make changes to templates for users with correct permissions.

View/Edit Template Parameters
oc edit -n openshift template nodejs-mongo-persistent
Exit by esc + : + q
esc + : + q

Step 3:

Lets go ahead and launch a template from the commandline

Launch the Template
oc process -n openshift nodejs-mongo-persistent | oc create -f -
Multiple OpenShift objects created
secret "nodejs-mongo-persistent" created
service "nodejs-mongo-persistent" created
route "nodejs-mongo-persistent" created
imagestream "nodejs-mongo-persistent" created
buildconfig "nodejs-mongo-persistent" created
deploymentconfig "nodejs-mongo-persistent" created
persistentvolumeclaim "mongodb" created
service "mongodb" created
deploymentconfig "mongodb" created

You should be able to login to the web UI (EXAMPLE: http://nodejs-mongo-persistent-myproject.apps.ocp.0.redhatgov.io/) and in your Templates project and see the Nodejs application.

Click the Nodejs route;

node route

Return to Workshop