This is a cache of https://docs.openshift.com/enterprise/3.1/architecture/core_concepts/templates.html. It is a snapshot of the page at 2024-11-27T04:31:36.547+0000.
Templates - Core Concepts | Architecture | OpenShift Enterprise 3.1
×

Overview

A template describes a set of objects that can be parameterized and processed to produce a list of objects for creation by OpenShift Enterprise . The objects to create can include anything that users 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.

Example 1. A Simple Template Object Definition (YAML)
apiVersion: v1
kind: Template
metadata:
  name: redis-template (1)
  annotations:
    description: "Description" (2)
    iconClass: "icon-redis" (3)
    tags: "database,nosql" (4)
objects:   (5)
- apiVersion: v1
  kind: Pod
  metadata:
    name: redis-master
  spec:
    containers:
    - env:
      - name: REDIS_PASSWORD
        value: ${REDIS_PASSWORD} (6)
      image: dockerfile/redis
      name: master
      ports:
      - containerPort: 6379
        protocol: TCP
parameters:  (7)
- description: Password used for Redis authentication
  from: '[A-Z0-9]{8}'   (8)
  generate: expression
  name: REDIS_PASSWORD
labels:      (9)
  redis: master
1 The name of the template
2 Optional description for the template
3 The icon that will be shown in the UI for this template; the name of a CSS class defined in the web console source (search content for "openshift-logos-icon").
4 A list of arbitrary tags that this template will have in the UI
5 A list of objects the template will create (in this case, a single pod)
6 Parameter value that will be substituted during processing
7 A list of parameters for the template
8 An expression used to generate a random password if not specified
9 A list of labels to apply to all objects on create

A template describes a set of related object definitions to be created together, as well as a set of parameters for those objects. For example, an application might consist of a frontend web application backed by a database; each consists of a service object and deployment configuration object, and they share a set of credentials (parameters) for the frontend to authenticate to the backend. The template can be processed, either specifying parameters or allowing them to be automatically generated (for example, a unique DB password), in order to instantiate the list of objects in the template as a cohesive application.

Templates can be processed from a definition in a file or from an existing OpenShift Enterprise API object. Cluster administrators can define standard templates in the API that are available for all users to process, while users can define their own templates within their own projects.

Administrators and developers can interact with templates using the CLI and web console.

Parameters

Templates allow you to define parameters which take on a value. That value is then substituted wherever the parameter is referenced. References can be defined in any text field in the objects list field.

Each parameter describes a variable and the variable value which can be referenced in any text field in the objects list field. During processing, the value can be set explicitly or it can be generated by OpenShift Enterprise.

An explicit value can be set as the parameter default using the value field:

parameters:
  - name: USERNAME
    description: "The user name for Joe"
    value: joe

The generate field can be set to 'expression' to specify generated values. The from field should specify the pattern for generating the value using a pseudo regular expression syntax:

parameters:
  - name: PASSWORD
    description: "The random user password"
    generate: expression
    from: "[a-zA-Z0-9]{12}"

In the example above, processing will generate a random password 12 characters long consisting of all upper and lowercase alphabet letters and numbers.

The syntax available is not a full regular expression syntax. However, you can use \w, \d, and \a modifiers:

  • [\w]{10} produces 10 alphabet characters, numbers, and underscores. This follows the PCRE standard and is equal to [a-zA-Z0-9_]{10}.

  • [\d]{10} produces 10 numbers. This is equal to [0-9]{10}.

  • [\a]{10} produces 10 alphabetical characters. This is equal to [a-zA-Z]{10}.