Bootstrap FreeKB - OpenShift - Create a Project
OpenShift - Create a Project

Updated:   |  OpenShift articles

If you are not familiar with the oc command, refer to OpenShift - Getting Started with the oc command.

Before creating a new project, you might want to use the oc get templates command to determine if there is a template in the openshift-config project / namespace. 

~]$ oc get templates --namespace openshift-config
NAME              DESCRIPTION   PARAMETERS    OBJECTS
project-request                 5 (5 blank)   3

 

If there is a template in the openshift-config namespace, use the oc describe command to determine if project.config.openshift.io/cluster is configured to use the template. If so, the template in the openshift-config namespace is being used to define default settings when a project is created.

~]$ oc describe project.config.openshift.io/cluster
Spec:
  Project Request Template:
    Name:  project-request

 

The oc new-project command is used to create a project. In this example, a project named "foo" is created.

oc new-project foo

 

When using the oc new-project command, the following options can optionally be included

oc new-project foo \
--description "my foo project" \
--display-name "foo project" \
--skip-config-write=false

 

Or, the oc adm new-project command can be used which has two additional options.

oc new-project foo \
--description "my foo project" \
--display-name "foo project" \
--skip-config-write=false \
--admin "john.doe" \
--node-selector ""

 

Or, a JSON or YAML file that contains key value pairs used to create an object, such as a config map, deployment, a project, a pod, a route, a secret, a service, et cetera. These files are known as templates. The oc explain command can be used to get the list of keys that can be used in the JSON or YAML template file.

oc explain namespace

 

And then more details on each key can be displayed.

oc explain namespace.spec

 

For example, let's say you have a YAML file named namespace.yml that contains the following markup. Notice "kind: Namespace", which means this template will be used to create a project / namespace.

In this example, the project / namespace named "foo" will be created.

apiVersion: v1
kind: Namespace
metadata:
  name: foo

 

The oc apply or oc create command with the -f or --filename option can be used to create the project / namespace using the template JSON or YAML file.

The oc replace command can be used to replace a project / namespace using a new or updated template JSON or YAML file.

The oc edit command can be used to update a project / namespace template YAML file.

~]# oc create -f foo.yml
namespace/foo created

 

If the project is successfully created, the following should be displayed.

Now using project "foo" on server "https://ocp.dev.thrivent.com:8443".

You can add applications to this project with the 'new-app' command. For example, try:

    oc new-app centos/ruby-25-centos7~https://github.com/sclorg/ruby-ex.git

to build a new example application in Ruby.

 

If you attempt to create a project that already exists, the following will be displayed.

Error from server (AlreadyExists): project.project.openshift.io "foo" already exists

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter 002166 in the box below so that we can be sure you are a human.