Skip to main content
Redhat Developers  Logo
  • AI

    Get started with AI

    • Red Hat AI
      Accelerate the development and deployment of enterprise AI solutions.
    • AI learning hub
      Explore learning materials and tools, organized by task.
    • AI interactive demos
      Click through scenarios with Red Hat AI, including training LLMs and more.
    • AI/ML learning paths
      Expand your OpenShift AI knowledge using these learning resources.
    • AI quickstarts
      Focused AI use cases designed for fast deployment on Red Hat AI platforms.
    • No-cost AI training
      Foundational Red Hat AI training.

    Featured resources

    • OpenShift AI learning
    • Open source AI for developers
    • AI product application development
    • Open source-powered AI/ML for hybrid cloud
    • AI and Node.js cheat sheet

    Red Hat AI Factory with NVIDIA

    • Red Hat AI Factory with NVIDIA is a co-engineered, enterprise-grade AI solution for building, deploying, and managing AI at scale across hybrid cloud environments.
    • Explore the solution
  • Learn

    Self-guided

    • Documentation
      Find answers, get step-by-step guidance, and learn how to use Red Hat products.
    • Learning paths
      Explore curated walkthroughs for common development tasks.
    • Guided learning
      Receive custom learning paths powered by our AI assistant.
    • See all learning

    Hands-on

    • Developer Sandbox
      Spin up Red Hat's products and technologies without setup or configuration.
    • Interactive labs
      Learn by doing in these hands-on, browser-based experiences.
    • Interactive demos
      Click through product features in these guided tours.

    Browse by topic

    • AI/ML
    • Automation
    • Java
    • Kubernetes
    • Linux
    • See all topics

    Training & certifications

    • Courses and exams
    • Certifications
    • Skills assessments
    • Red Hat Academy
    • Learning subscription
    • Explore training
  • Build

    Get started

    • Red Hat build of Podman Desktop
      A downloadable, local development hub to experiment with our products and builds.
    • Developer Sandbox
      Spin up Red Hat's products and technologies without setup or configuration.

    Download products

    • Access product downloads to start building and testing right away.
    • Red Hat Enterprise Linux
    • Red Hat AI
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform
    • See all products

    Featured

    • Red Hat build of OpenJDK
    • Red Hat JBoss Enterprise Application Platform
    • Red Hat OpenShift Dev Spaces
    • Red Hat Developer Toolset

    References

    • E-books
    • Documentation
    • Cheat sheets
    • Architecture center
  • Community

    Get involved

    • Events
    • Live AI events
    • Red Hat Summit
    • Red Hat Accelerators
    • Community discussions

    Follow along

    • Articles & blogs
    • Developer newsletter
    • Videos
    • Github

    Get help

    • Customer service
    • Customer support
    • Regional contacts
    • Find a partner

    Join the Red Hat Developer program

    • Download Red Hat products and project builds, access support documentation, learning content, and more.
    • Explore the benefits

Understanding Templates in Stakater's Multi Tenancy Operator

March 12, 2024
Vivien Wang Bharath Nallapeta, Muneeb Aijaz & Tanveer Alam
Related topics:
KubernetesOperators
Related products:
Red Hat OpenShift

    As a Technology Partner within the Red Hat OpenShift ecosystem, Stakater's Multi Tenant Operator has been officially certified by Red Hat since March 2022, with the latest release certified in November 2023. With Red Hat OpenShift Certified Operators, customers can benefit from validated, verified, mature and supported Operators from Red Hat and partner ISVs in their hybrid cloud environments.

    Learn more about Red Hat OpenShift Operator certification here. To learn more about becoming a Red Hat Partner see this link.

    This is the third part in a series featuring the exploration of Multi Tenant Operator (MTO) by Stakater, an operator designed to streamline and secure multi-tenancy in OpenShift and Kubernetes environments. In our two previous blogs (1) (2), we described MTO fundamentals. In this blog, we focus on Templates, TemplateInstance (TI), and TemplateGroupInstance (TGI). Templates serve as a standardized playbook, ensuring consistent deployment and management of resources across multiple tenants. We clarify how these features contribute to operational efficiency and security, providing a comprehensive overview of their use and benefits in multi-tenant architectures.

    Templates

    Templates in the MTO act like a club's standard playbook or strategy guide in soccer. They provide a predefined set of resources or configurations that are consistently deployed across multiple namespaces or Tenants. This feature is crucial for ensuring conformity, efficiency, and simplifying the management of common resources like Network Policies, Helm charts, or secret mappings.

    Custom resource (YAML)

    A Template in MTO is defined as a Kubernetes Custom Resource (CR). The types of Templates available are as follows.

    Helm chart Template: These Templates define Helm charts for deploying applications or services. Example:

    apiVersion: tenantoperator.stakater.com/v1alpha1
    kind: Template
    metadata:
      name: redis
    resources:
      helm:
        releaseName: redis
        chart:
          repository:
            name: redis
            repoUrl: https://charts.bitnami.com/bitnami
        values: |
          redisPort: 6379

    Manifest Template: These Templates contain Kubernetes manifests for resources like Network Policies, acting like guidelines for specific team strategies. Example:

    apiVersion: tenantoperator.stakater.com/v1alpha1
    kind: Template
    metadata:
      name: networkpolicy
    parameters:
     - name: CIDR_IP
       value: 172.17.0.0/16
    resources:
     manifests:
       - apiVersion: networking.k8s.io/v1
         kind: NetworkPolicy
         metadata:
           name: deny-cross-ns-traffic
         spec:
           egress:
             - ports:
                 - port: 5978
                   protocol: TCP
               to:
                 - ipBlock:
                     cidr: 10.0.0.0/24
           ingress:
             - from:
                 - ipBlock:
                     cidr: '${{CIDR_IP}}'
                     except:
                       - 172.17.1.0/24
                 - namespaceSelector:
                     matchLabels:
                       project: myproject
                 - podSelector:
                     matchLabels:
                       role: frontend
               ports:
                 - port: 6379
                   protocol: TCP
           podSelector:
             matchLabels:
               role: db
           policyTypes:
             - Ingress
             - Egress

    Resource mapping Template: Used for mapping Secrets and ConfigMaps across namespaces, akin to sharing tactics or training methods across different club teams. Example:

    apiVersion: tenantoperator.stakater.com/v1alpha1
    kind: Template
    metadata:
     name: resource-mapping
    resources:
     resourceMappings:
       secrets:
       - name: secret-s1
         namespace: namespace-n1
       configMaps:
         - name: configmap-c1
           namespace: namespace-n2

    For more information on Templates, refer to the official MTO docs.

    Templates and their relation to TemplateInstances

    While we've explored how Templates can be directly integrated into Tenants, it is also worth understanding their relationship with TemplateInstances (TI). Templates are the blueprints–the predefined sets of resources or configurations. TemplateInstances are the mechanisms that deploy these blueprints into specific namespaces.

    Key points

    • Flexibility in Application: TemplateInstances provide flexibility, allowing for the selective application of Templates. This means that certain Templates can be applied only to specific namespaces as required, rather than across all namespaces of a Tenant.
    • Dynamic Parameter Substitution: TemplateInstances can override or provide values for parameters defined in a Template. This feature is particularly useful when the same Template needs to be applied differently depending on the context.
    • Streamlined Management: By using TemplateInstances, cluster administrators can manage how and where Templates are applied more granularly. This ensures each namespace gets only what it needs, enhancing efficiency and reducing resource clutter.

    Templates, along with TemplateInstances, offer a powerful way to standardize and manage resources across multiple namespaces in a Kubernetes environment. They provide a balance between uniformity and customization, ensuring that each part of the cluster operates both independently and cohesively within the larger organizational structure. For more information on TI, refer to the official MTO docs.

    TemplateGroupInstances

    TemplateGroupInstances (TGIs) in Multi Tenant Operator act as a mechanism to apply a specific set of configurations, defined in a Template, much like TemplateInstances but across multiple namespaces. This is analogous to a sports league uniformly implementing certain rules or training protocols across various teams.

    Custom Resource (YAML)

    TGIs are defined as cluster-scoped resources. Here is an example of a TGI to deploy a security-policy Template to all namespaces labeled with security-level: high:

    apiVersion: tenantoperator.stakater.com/v1alpha1
    kind: TemplateGroupInstance
    metadata:
     name: security-policy-tgi
    spec:
     template: security-policy
     sync: true
     selector:
       matchLabels:
         security-level: high

    Field explanation:

    • selector: The selector in a TGI identifies the namespaces where the Template will be applied. In this example, any namespace with the label security-level: high will receive the configurations from the security-policy Template.
    • sync: When true, this feature keeps the resources in the selected namespaces in synchronization with the Template. If changes are unintentionally made locally within a namespace, the TGI will revert them back to match the Template's specifications.

    Example use

    Let's take a scenario where Susan, a cluster admin, wants to enforce a standardized logging policy across several critical namespaces in the organization. She decides to use a TGI for this purpose.

    1. Template creation (logging-policy):

    Susan creates a Template named logging-policy that defines the configurations for a logging tool to be used across critical namespaces:

    apiVersion: tenantoperator.stakater.com/v1alpha1
    kind: Template
    metadata:
      name: logging-policy
    resources:
      manifests:
        # <Logging tool configuration added>

    2. TemplateGroupInstance for logging-policy:

    She then creates a TGI named logging-policy-tgi to apply the logging-policy Template to all namespaces meant for critical operations, identified via the operation: critical label:

    apiVersion: tenantoperator.stakater.com/v1alpha1
    kind: TemplateGroupInstance
    metadata:
      name: logging-policy-tgi
    spec:
      template: logging-policy
      selector:
        matchLabels:
          operation: critical
      sync: true

    3. Here is then a Tenant YAML configuration that uses the logging-policy-tgi TemplateGroupInstance:

    apiVersion: tenantoperator.stakater.com/v1beta2
    kind: Tenant
    metadata:
      name: critical-operations-tenant
    spec:
      owners:
        users:
          - susan@techcompany.com
      quota: medium
      namespaces:
        withTenantPrefix:
          - critical-app1
          - critical-app2
          - critical-app3
      commonMetadata:
        labels:
          operation: critical

    Field explanation:

    • Tenant Definition: The Tenant named critical-operations-tenant is set up specifically for critical operations within Susan's organization.
    • Namespace Creation: Under this Tenant, the namespaces critical-app1, critical-app2, and critical-app3 are created. These are intended for critical applications or operations.
    • Common Metadata: The commonMetadata field assigns the label operation: critical to all namespaces in this Tenant. This label aligns with the selector criteria defined in the logging-policy-tgi TemplateGroupInstance.
    • Integration with TemplateGroupInstance: The logging-policy-tgi TemplateGroupInstance is designed to target namespaces with the label operation: critical. As a result of using the matching labels, the logging policy defined in the Template is automatically applied to all namespaces created under the critical-operations-tenant, ensuring a consistent logging approach across these critical applications.

    In a diverse OpenShift environment, TGIs offer an efficient way to manage and enforce consistent standards, especially in large organizations with numerous namespaces. Whether it's applying security measures, operational policies, or shared configurations, TGIs simplify the process, ensuring that all relevant parts of the organization adhere to the same standards and practices. For more information on TGI, refer to the official MTO docs.

    Conclusion

    Features like Templates, TemplateInstances (TI), and TemplateGroupInstances (TGI) are key to efficiently manage multi-tenancy in OpenShift. These elements simplify the deployment and management of resources across tenants, and bolster security and operational efficiency. MTO stands as an indispensable tool for orchestrating complex environments, showcasing its vital role in the modern Kubernetes landscape in the field of multi-tenancy.

    Further reading

    • Introduction to the Multi Tenant Operator
    • Learn more about the Multi Tenant Operator
    • Get the Multi Tenant Operator for OpenShift
    • Partner Guide for Red Hat Vulnerability Scanner Certification
    • Learn how to install Stakater on Red Hat OpenShift
    • Support and contacting the team
    Last updated: March 26, 2024

    Related Posts

    • Simplify multitenancy with Stakater's Multi Tenant Operator

    • A deep dive into Stakater's Multi-Tenant Operator

    • Manage namespaces in multitenant clusters with Argo CD, Kustomize, and Helm

    • Implement multitenant SaaS on Kubernetes

    • How to program a multitenant SaaS platform in Kubernetes

    • 3 patterns for deploying Helm charts with Argo CD

    Recent Posts

    • Every layer counts: Defense in depth for AI agents with Red Hat AI

    • Fun in the RUN instruction: Why container builds with distroless images can surprise you

    • Trusted software factory: Building trust in the agentic AI era

    • Build a zero trust AI pipeline with OpenShift and RHEL CVMs

    • Red Hat Hardened Images: Top 5 benefits for software developers

    What’s up next?

    OpenShift For Developers Tile Card

    Get a hands-on introduction to daily life as a developer crafting code on OpenShift, the open source application development platform from Red Hat, with OpenShift for Developers.

    Delve deeper into OpenShift
    Red Hat Developers logo LinkedIn YouTube Twitter Facebook

    Platforms

    • Red Hat AI
    • Red Hat Enterprise Linux
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform
    • See all products

    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
    © 2026 Red Hat

    Red Hat legal and privacy links

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

    Chat Support

    Please log in with your Red Hat account to access chat support.