This documentation is for a release that is no longer maintained
See documentation for the latest supported version 3 or the latest supported version 4.10.4. Creating objects from templates by using the CLI
You can use the CLI to process templates and use the configuration that is generated to create objects.
10.4.1. Adding labels 复制链接链接已复制到粘贴板!
Labels are used to manage and organize generated objects, such as pods. The labels specified in the template are applied to every object that is generated from the template.
Procedure
Add labels in the template from the command line:
oc process -f <filename> -l name=otherLabel
$ oc process -f <filename> -l name=otherLabel
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
10.4.2. Listing parameters 复制链接链接已复制到粘贴板!
The list of parameters that you can override are listed in the parameters
section of the template.
Procedure
You can list parameters with the CLI by using the following command and specifying the file to be used:
oc process --parameters -f <filename>
$ oc process --parameters -f <filename>
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Alternatively, if the template is already uploaded:
oc process --parameters -n <project> <template_name>
$ oc process --parameters -n <project> <template_name>
Copy to Clipboard Copied! Toggle word wrap Toggle overflow For example, the following shows the output when listing the parameters for one of the Quickstart templates in the default
openshift
project:oc process --parameters -n openshift rails-postgresql-example
$ oc process --parameters -n openshift rails-postgresql-example
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example output
Copy to Clipboard Copied! Toggle word wrap Toggle overflow The output identifies several parameters that are generated with a regular expression-like generator when the template is processed.
10.4.3. Generating a list of objects 复制链接链接已复制到粘贴板!
Using the CLI, you can process a file defining a template to return the list of objects to standard output.
Procedure
Process a file defining a template to return the list of objects to standard output:
oc process -f <filename>
$ oc process -f <filename>
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Alternatively, if the template has already been uploaded to the current project:
oc process <template_name>
$ oc process <template_name>
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Create objects from a template by processing the template and piping the output to
oc create
:oc process -f <filename> | oc create -f -
$ oc process -f <filename> | oc create -f -
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Alternatively, if the template has already been uploaded to the current project:
oc process <template> | oc create -f -
$ oc process <template> | oc create -f -
Copy to Clipboard Copied! Toggle word wrap Toggle overflow You can override any parameter values defined in the file by adding the
-p
option for each<name>=<value>
pair you want to override. A parameter reference appears in any text field inside the template items.For example, in the following the
POSTGRESQL_USER
andPOSTGRESQL_DATABASE
parameters of a template are overridden to output a configuration with customized environment variables:Creating a List of objects from a template
oc process -f my-rails-postgresql \ -p POSTGRESQL_USER=bob \ -p POSTGRESQL_DATABASE=mydatabase
$ oc process -f my-rails-postgresql \ -p POSTGRESQL_USER=bob \ -p POSTGRESQL_DATABASE=mydatabase
Copy to Clipboard Copied! Toggle word wrap Toggle overflow The JSON file can either be redirected to a file or applied directly without uploading the template by piping the processed output to the
oc create
command:oc process -f my-rails-postgresql \ -p POSTGRESQL_USER=bob \ -p POSTGRESQL_DATABASE=mydatabase \ | oc create -f -
$ oc process -f my-rails-postgresql \ -p POSTGRESQL_USER=bob \ -p POSTGRESQL_DATABASE=mydatabase \ | oc create -f -
Copy to Clipboard Copied! Toggle word wrap Toggle overflow If you have large number of parameters, you can store them in a file and then pass this file to
oc process
:cat postgres.env POSTGRESQL_USER=bob POSTGRESQL_DATABASE=mydatabase
$ cat postgres.env POSTGRESQL_USER=bob POSTGRESQL_DATABASE=mydatabase
Copy to Clipboard Copied! Toggle word wrap Toggle overflow oc process -f my-rails-postgresql --param-file=postgres.env
$ oc process -f my-rails-postgresql --param-file=postgres.env
Copy to Clipboard Copied! Toggle word wrap Toggle overflow You can also read the environment from standard input by using
"-"
as the argument to--param-file
:sed s/bob/alice/ postgres.env | oc process -f my-rails-postgresql --param-file=-
$ sed s/bob/alice/ postgres.env | oc process -f my-rails-postgresql --param-file=-
Copy to Clipboard Copied! Toggle word wrap Toggle overflow