Skip to content

Tenancy structure

A tenant is an organizational structure that allows multiple teams to share the same Kubernetes cluster. Each tenant is:

  • Allowed to create a certain number of namespaces in the cluster
  • Limited by resource quota
  • Configured with a secret store backed by Vault
  • Provided with an OpenTelemetry instrumentation
  • Optionally provided with an OpenTelemetry - Splunk instrumentation

We deploy Kyverno policies to manage the tenants. We will provide a short description below of each of the policies.

Create tenant-upgrade-user ServiceAccount and ClusterRoles

Section titled “Create tenant-upgrade-user ServiceAccount and ClusterRoles”

At first, the following resources are created:

Tenants deployment phase 1

On top, you can see that our admin ServiceAccount is created:

  • The ‘tenant-upgrade-user’ ServiceAccount
  • The ‘flow:tenants:upgrader’ ClusterRole which grants permissions to perform CRUD operations for Kyverno ClusterPolicies
  • The ‘tenants-upgrade-user’ ClusterRoleBinding which binds the ‘tenant-upgrade-user’ ServiceAccount to the ‘flow:tenants:upgrader’ ClusterRole

Next to the ServiceAccount with corresponding ClusterRole, we create five other ClusterRoles:

ClusterRoleKubernetes resourcePermissions
flow:tenants:postgres:userservicebindings
serviceinstance
servicemonitors
get, patch, create, delete
flow:tenants:namespace-creatornamespacescreate, list, watch
flow:tenants:namespace-removernamespacesget, delete
flow:tenants:argocdapplications
applicationsets
get, list, create, patch
flow:tenants:traefikmiddlewares
ingressroutes
*

The second phase consists of the jobs that delete the existing ClusterPolicies:

Tenants deployment phase 2

These ClusterPolicies are deleted by the ‘tenants-upgrade-user’ ServiceAccount created in the first phase.

Create tenant RBAC, Gitlab variables and ClusterPolicies

Section titled “Create tenant RBAC, Gitlab variables and ClusterPolicies”

The final phase consists of creating everything for the tenant:

Tenants deployment phase 3

A service account is created for the tenant. Based on this service account, a secret is generated containing a token for that service account. By using a ClusterRoleBinding, the service account receives the permissions to create namespaces.

The following ClusterPolicies are created:

  • Allow the tenant ServiceAccount to create namespaces with a specific prefix (e.g. tenant1-*)
  • Only allow that tenant/service account (and cluster admins) to delete namespaces that they created
  • Only allow a certain configurable number of such namespaces to be created per tenant
  • Add a (configurable) ResourceQuota to each such namespace
  • Add a label to each such namespace to identify the tenant that created it
  • Deploy generic OpenTelemetry Instrumentation policies
  • Deploy Splunk OpenTelemetry Collector policies
  • Deploy Splunk OpenTelemetry Instrumentation policies
  • Deploy the allowed storage class policy, limiting access to storageClass objects in the cluster