Skip to main content
Redhat Developers  Logo
  • Products

    Platforms

    • Red Hat Enterprise Linux
      Red Hat Enterprise Linux Icon
    • Red Hat AI
      Red Hat AI
    • Red Hat OpenShift
      Openshift icon
    • Red Hat Ansible Automation Platform
      Ansible icon
    • View All Red Hat Products

    Featured

    • Red Hat build of OpenJDK
    • Red Hat Developer Hub
    • Red Hat JBoss Enterprise Application Platform
    • Red Hat OpenShift Dev Spaces
    • Red Hat OpenShift Local
    • Red Hat Developer Sandbox

      Try Red Hat products and technologies without setup or configuration fees for 30 days with this shared Openshift and Kubernetes cluster.
    • Try at no cost
  • Technologies

    Featured

    • AI/ML
      AI/ML Icon
    • Linux
      Linux Icon
    • Kubernetes
      Cloud icon
    • Automation
      Automation Icon showing arrows moving in a circle around a gear
    • View All Technologies
    • Programming Languages & Frameworks

      • Java
      • Python
      • JavaScript
    • System Design & Architecture

      • Red Hat architecture and design patterns
      • Microservices
      • Event-Driven Architecture
      • Databases
    • Developer Productivity

      • Developer productivity
      • Developer Tools
      • GitOps
    • Automated Data Processing

      • AI/ML
      • Data Science
      • Apache Kafka on Kubernetes
    • Platform Engineering

      • DevOps
      • DevSecOps
      • Ansible automation for applications and services
    • Secure Development & Architectures

      • Security
      • Secure coding
  • Learn

    Featured

    • Kubernetes & Cloud Native
      Openshift icon
    • Linux
      Rhel icon
    • Automation
      Ansible cloud icon
    • AI/ML
      AI/ML Icon
    • View All Learning Resources

    E-Books

    • GitOps Cookbook
    • Podman in Action
    • Kubernetes Operators
    • The Path to GitOps
    • View All E-books

    Cheat Sheets

    • Linux Commands
    • Bash Commands
    • Git
    • systemd Commands
    • View All Cheat Sheets

    Documentation

    • Product Documentation
    • API Catalog
    • Legacy Documentation
  • Developer Sandbox

    Developer Sandbox

    • Access Red Hat’s products and technologies without setup or configuration, and start developing quicker than ever before with our new, no-cost sandbox environments.
    • Explore Developer Sandbox

    Featured Developer Sandbox activities

    • Get started with your Developer Sandbox
    • OpenShift virtualization and application modernization using the Developer Sandbox
    • Explore all Developer Sandbox activities

    Ready to start developing apps?

    • Try at no cost
  • Blog
  • Events
  • Videos

Customizing OpenShift project creation

February 5, 2020
Rarm Nagalingam
Related topics:
ContainersDevOps
Related products:
Red Hat OpenShift

Share:

    I recently attended an excellent training run by Red Hat’s Global Partner Enablement Team on advanced Red Hat OpenShift management. One of the most interesting elements of the training was how to customize default project creation. This article explains how to use OpenShift's projectRequestTemplate to add default controls for the resources that a project is allowed to consume.

    First, a little bit of background. OpenShift projects are synonymous with Kubernetes namespaces and are used to isolate objects between projects. By default, users who are authenticated can create projects and consume resources up to the global ClusterResource limits. As a cluster administrator, you might want to add new default limits around the number of resources that can be consumed by a project. OpenShift provides a mechanism to achieve this setting by creating a template that is referenced by the projectRequestTemplate parameter in OpenShift’s project configuration resource.

    Note: You can read more about this feature in the official documentation in configuring-project-creation. However, the default documentation can be lacking if you haven’t created or modified templates before.

    This example outlines how to obtain a project creation template schema, and how to configure it to set default project limits and default container limits. For our example, the project limits for our example look like this:

    • Use a maximum of 10 pods.
    • Limit each project to six CPUs.
    • Limit each project to 16GiB of RAM.
    • Set a request for a project to four CPUs.
    • Set a request for a project to 8GiB of RAM.
    • Set a request for 20GB of persistent storage.

    The container limits for our example look like this:

    • Limit each container to one CPU.
    • Limit each container to 1GiB of RAM.
    • Set a default request for 500 milliCPU.
    • Set a default request for 500MiB of RAM.

    Note: To understand more about limits and quotas, read quotas-setting-per-project.

    Before we can customize the template we need to obtain a schema. Run the following command as a user with cluster-admin permissions:

    $ oc adm create-bootstrap-project-template -o yaml > template.yaml

    Customize the template

    Looking at the default template, you can see that it is bare-bones and only contains particular settings, such as NAME, DISPLAYNAME, DESCRIPTION, ADMIN_USER, and REQUESTING_USER, along with establishing sane role-based access controls (RBACs):

    apiVersion: template.openshift.io/v1
    kind: Template
    metadata:
      creationTimestamp: null
      name: project-request
    objects:
    - apiVersion: project.openshift.io/v1
      kind: Project
      metadata:
        annotations:
          openshift.io/description: ${PROJECT_DESCRIPTION}
          openshift.io/display-name: ${PROJECT_DISPLAYNAME}
          openshift.io/requester: ${PROJECT_REQUESTING_USER}
        creationTimestamp: null
        name: ${PROJECT_NAME}
      spec: {}
      status: {}
    - apiVersion: rbac.authorization.k8s.io/v1
      kind: RoleBinding
      metadata:
        creationTimestamp: null
        name: admin
        namespace: ${PROJECT_NAME}
      roleRef:
        apiGroup: rbac.authorization.k8s.io
        kind: ClusterRole
        name: admin
      subjects:
      - apiGroup: rbac.authorization.k8s.io
        kind: User
        name: ${PROJECT_ADMIN_USER}
    parameters:
    - name: PROJECT_NAME
    - name: PROJECT_DISPLAYNAME
    - name: PROJECT_DESCRIPTION
    - name: PROJECT_ADMIN_USER
    - name: PROJECT_REQUESTING_USER
    

    The important part when customizing this template is adding objects such as ResourceQuota and LimitRange under the objects stanza. First, craft the ResourceQuota and LimitRange as you would normally:

    - apiVersion: v1
      kind: "LimitRange"
      metadata:
        name: project-limits
      spec:
        limits:
          - type: "Container"
            default:
              cpu: "1" 
              memory: "1Gi" 
            defaultRequest:
              cpu: "500m" 
              memory: "500Mi"
    - apiVersion: v1
      kind: ResourceQuota
      metadata:
        name: project-quota
      spec:
        hard:
          pods: "10" 
          requests.cpu: "4" 
          requests.memory: 8Gi 
          limits.cpu: "6" 
          limits.memory: 16Gi
          requests.storage: "20G"
    

    Now, add ResourceQuota and LimitRange objects under the objects section of the template. In this example, I have modified the name for each object by dynamically include the project name:

    apiVersion: template.openshift.io/v1
    kind: Template
    metadata:
      creationTimestamp: null
      name: project-request
    objects:
    - apiVersion: project.openshift.io/v1
      kind: Project
      metadata:
        annotations:
          openshift.io/description: ${PROJECT_DESCRIPTION}
          openshift.io/display-name: ${PROJECT_DISPLAYNAME}
          openshift.io/requester: ${PROJECT_REQUESTING_USER}
        creationTimestamp: null
        name: ${PROJECT_NAME}
      spec: {}
      status: {}
    - apiVersion: rbac.authorization.k8s.io/v1
      kind: RoleBinding
      metadata:
        creationTimestamp: null
        name: admin
        namespace: ${PROJECT_NAME}
      roleRef:
        apiGroup: rbac.authorization.k8s.io
        kind: ClusterRole
        name: admin
      subjects:
      - apiGroup: rbac.authorization.k8s.io
        kind: User
        name: ${PROJECT_ADMIN_USER}
    - apiVersion: v1
      kind: "LimitRange"
      metadata:
        name: ${PROJECT_NAME}-limits
      spec:
        limits:
          - type: "Container"
            default:
              cpu: "1" 
              memory: "1Gi" 
            defaultRequest:
              cpu: "500m" 
              memory: "500Mi"
    - apiVersion: v1
      kind: ResourceQuota
      metadata:
        name: ${PROJECT_NAME}-quota
      spec:
        hard:
          pods: "10" 
          requests.cpu: "4" 
          requests.memory: 8Gi 
          limits.cpu: "6" 
          limits.memory: 16Gi
          requests.storage: "20G"
    parameters:
    - name: PROJECT_NAME
    - name: PROJECT_DISPLAYNAME
    - name: PROJECT_DESCRIPTION
    - name: PROJECT_ADMIN_USER
    - name: PROJECT_REQUESTING_USER
    

    The next step is installing the config into the openshift-config project:

    $ oc create -f template.yaml -n openshift-config

    After this, associate the template with projectRequestTemplate in the project resource of the config.openshift.io/v1. Run the following command to edit the config:

    $ oc edit project.config.openshift.io/cluster

    Within the text editor, set the config spec to include the name for your template under projectRequestTemplate. The name of our template itself was project-request. Therefore, under the spec section, we would add:

    apiVersion: config.openshift.io/v1
    kind: Project
    metadata:
      ...
    spec:
      projectRequestTemplate:
        name: project-request
    

    Confirm that the template works

    The last step is to test your configuration. Keep in mind that the project creation template only applies to projects created after the template was installed and associated with the projectRequestTemplate. Previously created projects will not be modified:

    $ oc new-project test
    ...
    $ oc describe project test
    Name:		test
    Created:	40 seconds ago
    ...
    Quota:
    	Name:			test-quota
    	Resource		Used	Hard
    	--------		----	----
    	limits.cpu		0	6
    	limits.memory		0	16Gi
    	pods			0	10
    	requests.cpu		0	4
    	requests.memory		0	8Gi
    	requests.storage	0	20G
    Resource limits:
    	Name:		test-limits
    	Type		Resource	Min	Max	Default Request	Default Limit	Max Limit/Request Ratio
    	----		--------	---	---	---------------	-------------	-----------------------
    	Container	cpu		-	-	500m		1		-
    	Container	memory		-	-	500Mi		1Gi		-
    

    The output above confirms that the quota and resource limits have automatically been applied to the project.

    Last updated: March 28, 2023

    Recent Posts

    • Run Qwen3-Next on vLLM with Red Hat AI: A step-by-step guide

    • How to implement observability with Python and Llama Stack

    • Deploy a lightweight AI model with AI Inference Server containerization

    • vLLM Semantic Router: Improving efficiency in AI reasoning

    • Declaratively assigning DNS records to virtual machines

    Red Hat Developers logo LinkedIn YouTube Twitter Facebook

    Products

    • Red Hat Enterprise Linux
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform

    Build

    • Developer Sandbox
    • Developer Tools
    • Interactive Tutorials
    • API Catalog

    Quicklinks

    • Learning Resources
    • E-books
    • Cheat Sheets
    • Blog
    • Events
    • Newsletter

    Communicate

    • About us
    • Contact sales
    • Find a partner
    • Report a website issue
    • Site Status Dashboard
    • Report a security problem

    RED HAT DEVELOPER

    Build here. Go anywhere.

    We serve the builders. The problem solvers who create careers with code.

    Join us if you’re a developer, software engineer, web designer, front-end designer, UX designer, computer scientist, architect, tester, product manager, project manager or team lead.

    Sign me up

    Red Hat legal and privacy links

    • About Red Hat
    • Jobs
    • Events
    • Locations
    • Contact Red Hat
    • Red Hat Blog
    • Inclusion at Red Hat
    • Cool Stuff Store
    • Red Hat Summit
    © 2025 Red Hat

    Red Hat legal and privacy links

    • Privacy statement
    • Terms of use
    • All policies and guidelines
    • Digital accessibility

    Report a website issue