Multi-tenant SaaS Platforms — Cells, Rings & Progressive Delivery›14 · Automating tenant onboarding

Lesson 14 of 16 · Tenants: isolation and onboarding

Automating tenant onboarding

Turn the manual tenant steps into a self-service product: a platform-owned Helm chart where a tenant is a five-line values file and quota comes from a tier (tested, including a bad-tier failure), GitOps with an Argo CD ApplicationSet that creates one application per tenant file, a portal or pull-request flow with CI checks and approvals, policy guardrails that hold even when someone bypasses the chart, the cloud side with Terraform or Crossplane, and day-2 operations: quota changes, alerts and offboarding.

Advanced
Key wordstenant onboardingself-servicetenant Helm charttiersvalues file per tenantHelm requiredGitOpsArgo CD ApplicationSetgit files generatorBackstage templatepull requestCI validationKyverno generatepolicy guardrailsCapsuleTerraformCrossplanequota alertsoffboarding

From steps to a product

Lesson 13 gave a team its space by hand: four manifests and seven checks. By hand it takes an hour, varies by who does it, and leaves no record. Automated, it takes minutes, with no tickets, it's identical every time, and Git becomes the record of who owns what.

Request portal form or a PR Pull request tenants/team-b.yaml CI checks schema, tier, groups, owner Argo CD ApplicationSet Every cluster ns · RBAC · quota LimitRange · netpol bad input → PR fails minutes, no tickets Cloud side: Terraform or Crossplane IdP groups · access entry · workload identity · secrets
A request becomes a small file in Git; CI validates it; Argo CD applies the platform's tenant chart to every shared cluster; Terraform or Crossplane creates the cloud side.

Instead of the caretaker building each new classroom by hand, the school has a kit: choose small, medium or large, write the class name on the form, and the kit arrives with the same desks, locks and fire rules every time.

Level 1: a tenant Helm chart

The platform team owns one chart. A tenant is a values file. Quota numbers come from tiers, so teams choose a size instead of inventing numbers.

tenants-repo/
├── charts/tenant/
│   ├── Chart.yaml
│   ├── values.yaml            # tiers and defaults (platform-owned)
│   └── templates/tenant.yaml  # Namespace, RoleBindings, ResourceQuota, LimitRange, NetworkPolicies
└── tenants/
    ├── team-a.yaml
    └── team-b.yaml            # one file per tenant
# tenants/team-b.yaml: the whole request
name: team-b
tier: small
groups:
  edit: team-b-devs
  view: team-b-viewers
# charts/tenant/values.yaml (platform-owned)
name: ""                 # tenant / namespace name (required)
tier: standard           # small | standard | large
groups:
  edit: ""               # IdP group with edit rights (required)
  view: ""               # IdP group with read-only rights (optional)
tiers:
  small:    { cpu: "2",  memory: 4Gi,  pods: "10", pvcs: "2",  storage: 20Gi }
  standard: { cpu: "4",  memory: 8Gi,  pods: "20", pvcs: "5",  storage: 50Gi }
  large:    { cpu: "16", memory: 32Gi, pods: "80", pvcs: "20", storage: 500Gi }

The template starts by validating its input, then renders the same objects as the manual steps:

{{- $n := required "name is required" .Values.name -}}
{{- $q := required "unknown tier" (get .Values.tiers .Values.tier) -}}
apiVersion: v1
kind: Namespace
metadata:
  name: {{ $n }}
  labels:
    platform.example.com/tenant: {{ $n }}
    platform.example.com/tier: {{ .Values.tier }}
    pod-security.kubernetes.io/enforce: restricted
    pod-security.kubernetes.io/enforce-version: latest
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata: { name: {{ $n }}-edit, namespace: {{ $n }} }
subjects:
- { kind: Group, name: {{ required "groups.edit is required" .Values.groups.edit | quote }}, apiGroup: rbac.authorization.k8s.io }
roleRef: { kind: ClusterRole, name: tenant-developer, apiGroup: rbac.authorization.k8s.io }   # lesson 13; not the built-in edit
{{- with .Values.groups.view }}
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata: { name: {{ $n }}-view, namespace: {{ $n }} }
subjects:
- { kind: Group, name: {{ . | quote }}, apiGroup: rbac.authorization.k8s.io }
roleRef: { kind: ClusterRole, name: view, apiGroup: rbac.authorization.k8s.io }
{{- end }}
---
apiVersion: v1
kind: ResourceQuota
metadata: { name: {{ $n }}-quota, namespace: {{ $n }} }
spec:
  hard:
    requests.cpu: {{ $q.cpu | quote }}
    requests.memory: {{ $q.memory }}
    limits.cpu: {{ mul (int $q.cpu) 2 | quote }}
    pods: {{ $q.pods | quote }}
    services.loadbalancers: "0"
    persistentvolumeclaims: {{ $q.pvcs | quote }}
    requests.storage: {{ $q.storage }}
# ... LimitRange, default-deny and allow-DNS NetworkPolicies exactly as in lesson 13

Tested on a kind cluster (real output):

$ helm lint charts/tenant -f tenants/team-b.yaml
1 chart(s) linted, 0 chart(s) failed

$ helm template team-b charts/tenant -f tenants/team-b.yaml | kubectl apply -f -
namespace/team-b created
networkpolicy.networking.k8s.io/default-deny created
networkpolicy.networking.k8s.io/allow-dns-and-same-namespace created
resourcequota/team-b-quota created
limitrange/team-b-defaults created
rolebinding.rbac.authorization.k8s.io/team-b-edit created
rolebinding.rbac.authorization.k8s.io/team-b-view created

$ kubectl describe quota team-b-quota -n team-b      # tier small
limits.cpu              0     4
persistentvolumeclaims  0     2
pods                    0     10
requests.cpu            0     2
requests.memory         0     4Gi
requests.storage        0     20Gi
services.loadbalancers  0     0

$ kubectl auth can-i create deployments -n team-b --as=x --as-group=team-b-devs
yes
$ kubectl auth can-i create deployments -n team-a --as=x --as-group=team-b-devs
no

# A typo in the tier fails before anything reaches a cluster
$ cat tenants/team-c.yaml
name: team-c
tier: huge
groups:
  edit: team-c-devs
$ helm template t charts/tenant -f tenants/team-c.yaml
Error: execution error at (tenant/templates/tenant.yaml:2:10): unknown tier

Level 2: GitOps, one file per tenant

An Argo CD ApplicationSet turns every file in tenants/ into an Argo CD Application that renders the tenant chart with that file:

apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
  name: tenants
  namespace: argocd
spec:
  goTemplate: true
  generators:
  - git:
      repoURL: https://git.example.com/platform/tenants.git
      revision: main
      files:
      - path: "tenants/*.yaml"            # one Application per tenant file
  template:
    metadata:
      name: "tenant-{{.name}}"            # .name comes from the tenant file
      labels:
        platform.example.com/kind: tenant
    spec:
      project: platform
      source:
        repoURL: https://git.example.com/platform/tenants.git
        targetRevision: main
        path: charts/tenant
        helm:
          valueFiles:
          - "../../{{.path.path}}/{{.path.filename}}"
      destination:
        name: shared-1                    # for many clusters: combine with a clusters generator
      syncPolicy:
        automated:
          prune: true                     # file deleted → tenant removed
          selfHeal: true                  # manual changes reverted
  • Add a tenant: merge a file. Change a tier: edit one line. Offboard: delete the file.
  • Many clusters: a matrix of the git generator and a clusters generator (by labels such as pool: shared or region: eu) puts every tenant on every matching cluster. Watch for parameter names that both generators produce.
  • Git history is the audit trail: who requested what, who approved it, when.

Level 3: self-service with checks

1. Request     portal form (for example a Backstage software template) or a hand-written PR
2. PR          adds tenants/team-x.yaml
3. CI checks   schema valid · tier exists · name unique and DNS-safe · groups exist in the IdP ·
               owner and cost centre set · helm template renders · policy tests pass
4. Approval    small/standard: auto-merge · large: platform approval · exceptions: architecture review
5. Apply       Argo CD syncs the tenant chart to every target cluster
6. Cloud side  Terraform or Crossplane: IdP groups, EKS access entry or Entra role assignment,
               workload-identity role, secrets path, registry repository, dashboards
7. Done        the team gets a message with its namespace, kubeconfig instructions and links

The portal is only a friendly way to write the same file. Teams who prefer Git open the PR themselves; the checks are identical.

Level 4: guardrails that don't depend on the chart

A policy engine makes sure any tenant namespace has the defaults, even one created another way, and stops changes that weaken them. Example with Kyverno (a generate rule with synchronize, so a deleted default comes back):

apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
  name: tenant-defaults
spec:
  rules:
  - name: default-deny
    match:
      any:
      - resources:
          kinds: [Namespace]
          selector:
            matchExpressions:
            - { key: platform.example.com/tenant, operator: Exists }
    generate:
      apiVersion: networking.k8s.io/v1
      kind: NetworkPolicy
      name: default-deny
      namespace: "{{request.object.metadata.name}}"
      synchronize: true
      data:
        spec:
          podSelector: {}
          policyTypes: [Ingress, Egress]

Kyverno ClusterPolicy is deprecated

From Kyverno 1.19, kyverno.io/v1 ClusterPolicy prints a deprecation warning: it will be removed in a future release in favour of the CEL-based ValidatingPolicy, MutatingPolicy, GeneratingPolicy and ImageValidatingPolicy (policies.kyverno.io). The example above still works today; write new policies in the new kinds (migration guide). Kubernetes' built-in admission policies can't create objects, so generate rules like this one stay with Kyverno (GeneratingPolicy) or move into the GitOps chart.

Other guardrails worth having: tenants can't create namespaces themselves; images only from approved registries; no hostPath; required labels (owner, cost-centre) on workloads.

Alternative: Capsule models a tenant as a custom resource that owns several namespaces, with owner groups, a namespace count and quotas across all of the tenant's namespaces. Choose it when teams need to create their own namespaces within limits.

Day-2 for tenants

Task How
More quota PR changing the tier; automatic one step up, approval beyond. Show actual usage first
Warn before teams hit the wall Alert on kube_resourcequota{type="used"} / ignoring(type) kube_resourcequota{type="hard"} > 0.8
Who pays Cost per namespace label platform.example.com/tenant (OpenCost, lesson 10)
Drift Argo CD self-heal reverts manual edits; the policy engine re-creates deleted defaults
New default for everyone Change the chart once; roll it out ring by ring (lesson 5)
Offboarding Delete the file → Argo CD prunes; Terraform removes groups and roles; data and backups follow the retention policy

Try it

  1. Build the chart from this lesson (copy the LimitRange and NetworkPolicies from lesson 13 into the template) and run helm lint and helm template for two tenants.
  2. Add a check script for CI that fails if a tenant file has no groups.edit, an unknown tier, or a name that isn't a valid DNS label.
  3. Add a large tier rule: rendering must fail unless the file contains approvedBy:.
  4. If you have Argo CD on a test cluster, apply the ApplicationSet, add a third tenant file, and watch the Application appear.

Going deeper

  • Keep the tenant list as data (files or a tenant catalog API) and generate everything from it: namespaces, cloud resources, dashboards, alert routes, cost reports.
  • Version the chart and roll new chart versions through rings like any platform change.
  • The same pattern serves customer tenants in a SaaS product, with a workflow engine instead of Git (lesson 15).

Recap

  • One platform-owned chart; a tenant is a small values file; quota comes from tiers; bad input fails at render time.
  • GitOps with an ApplicationSet: add a file to onboard, delete it to offboard; Git is the audit trail.
  • Self-service = a portal or PR, CI checks, auto-merge for small tiers and approval for large ones; Terraform or Crossplane for the cloud side.
  • A policy engine keeps the defaults in place even outside the normal path.

This site is a public version of my personal engineering knowledge hub. It intentionally excludes confidential company information and internal operational details.