Tenants: isolation and onboarding · wrap-up
Cheat sheet & self-check
Every command from this section on one page.
The three models
Silo | Dedicated resources per tenant: strongest isolation, highest cost, N copies to run |
Pool | Shared resources, rows and requests carry a tenant ID: cheapest, isolation is logical |
Bridge | Pool for most layers or tenants, silo where it matters: the usual real answer |
Decide per layer
Edge / gateway | Almost always pooled, with per-tenant limits |
Compute | Pooled per cell; dedicated node pool or cell for heavy tenants |
Data | Shared tables + row-level security, schema per tenant, or database per tenant |
Encryption keys | Often per tenant even when data is pooled |
Whole stack | Dedicated cell for regulated or very large tenants |
PostgreSQL row-level security
ALTER TABLE t ENABLE ROW LEVEL SECURITY | Turn RLS on: without a policy, non-owners see nothing |
CREATE POLICY p ON t USING (...) WITH CHECK (...) | USING filters rows you can see/change; WITH CHECK validates rows you write |
current_setting('app.tenant_id', true) | Read the tenant set for this transaction; true = return NULL if unset |
SET LOCAL app.tenant_id = 'acme' | Set the tenant for this transaction only (safe with connection pools) |
ALTER TABLE t FORCE ROW LEVEL SECURITY | Apply policies to the table owner too |
rolsuper / rolbypassrls | These roles skip RLS: never let the application use them |
Isolation options for data
Shared tables + tenant_id + RLS | Cheapest, scales to many tenants; isolation enforced in the database |
Schema per tenant | Clear separation; migrations run per schema; fine up to thousands |
Database per tenant | Strongest short of a dedicated cell; per-tenant backup/restore; costly at scale |
Per-tenant key | Encrypt tenant data with its own key; delete the key to make data unreadable |
Verify a tenant
kubectl auth can-i create deployments -n team-a --as=jane@example.com --as-group=team-a-devs | Test what a group member may do (needs impersonation rights) |
kubectl auth can-i delete networkpolicies -n team-a --as=jane@example.com --as-group=team-a-devs | Must be no: the team can't remove its own isolation |
kubectl describe quota -n team-a | Used vs hard limits |
kubectl get events -n team-a --field-selector reason=FailedCreate | Pods blocked by quota or Pod Security |
kubectl get ns team-a --show-labels | Pod Security level and tenant labels |
kubectl label --dry-run=server --overwrite ns team-a pod-security.kubernetes.io/enforce=restricted | What would break before you enforce Pod Security |
The pieces
Namespace + pod-security.kubernetes.io/enforce=restricted | Boundary; no root, no privileged pods, no host access |
RoleBinding: Group → ClusterRole tenant-developer / view | Who can do what, managed in the identity provider; not the built-in edit role |
ResourceQuota | Total CPU, memory, pods, storage, LoadBalancers for the namespace |
LimitRange | Default requests/limits and a per-container maximum |
NetworkPolicy default deny + allow DNS | Other namespaces can't reach the team's pods |
Dedicated nodes (hard isolation)
kubectl taint node N1 N2 platform.example.com/tenant=team-a:NoExecute | Repel and evict every pod without the toleration |
kubectl label node N1 N2 platform.example.com/tenant=team-a | Let the team's pods select these nodes |
MutatingAdmissionPolicy (GA in 1.36) | Writes nodeSelector and toleration into the team's pods |
ValidatingAdmissionPolicy (GA in 1.30) | Rejects other tenants' tolerations, wildcard tolerations and spec.nodeName |
kubectl tenants describe team-a | Access, quota left and blocked workloads for one tenant (tenant-insights) |
Levels of automation
1. Tenant chart | One platform-owned Helm chart; a tenant = small values file; quotas from tiers |
2. GitOps | ApplicationSet: one Argo CD Application per tenant file; delete the file to offboard |
3. Self-service | Portal form or PR → CI validation → auto-merge for small tiers, approval for large |
4. Guardrails | Policy engine generates and protects defaults in every tenant namespace |
Commands
helm lint charts/tenant -f tenants/team-b.yaml | Check the chart with one tenant's values |
helm template team-b charts/tenant -f tenants/team-b.yaml | Render what Argo CD would apply |
kubectl get applications -n argocd -l platform.example.com/kind=tenant | Tenant applications and their sync status |
Onboarding steps
1. Record | Tenant ID, plan, home region, status provisioning |
2. Placement | A cell in the home region with capacity, or a new dedicated cell |
3. Data and keys | Rows or schema in the cell's database; per-tenant key |
4. Identity | Organization in the platform IdP; SSO with the customer's IdP; first admin; optional SCIM |
5. Limits | Plan limits loaded: API rate, users, storage, jobs |
6. Routing | Tenant → cell entry; per-tenant hostname if used |
7. Metering | Usage events and billing start |
8. Verify | Smoke test as the tenant, then status active |
Workflow rules
Idempotent steps | Create-if-missing; safe to run twice |
Compensation | Undo finished steps in reverse order if the workflow can't complete |
Visible status | provisioning → active / failed (with reason) → suspended → offboarded |