Multi-tenant SaaS Platforms — Cells, Rings & Progressive Delivery›13 · Teams on a shared Kubernetes cluster

Lesson 13 of 16 · Tenants: isolation and onboarding

Teams on a shared Kubernetes cluster

Give a team its own safe space on a shared Kubernetes cluster, step by step: a namespace with Pod Security, sign-in through identity-provider groups and a tenant role that cannot remove its own guardrails (with the EKS and AKS specifics), ResourceQuota and LimitRange, default-deny NetworkPolicy that keeps DNS working, and verification of every step with real output. Then hard isolation: dedicated nodes that the API server enforces with built-in admission policies, one view per tenant, and when to move further to vCluster or a separate cluster.

Advanced
Key wordsKubernetes multi-tenancynamespace per teamRBACRoleBindingIdP groupsOIDCEKS access entriesAKS Entra IDkubectl auth can-iimpersonationResourceQuotaLimitRangeexceeded quotaPod Security AdmissionrestrictedNetworkPolicydefault denyallow DNSworkload identityvClusterCapsuletenant-developer rolebuilt-in edit roleForbidden vs Unauthorizedprivileged poddedicated nodestaintsNoExecutenodeSelectorMutatingAdmissionPolicyValidatingAdmissionPolicysoft vs hard isolationtenant-insights

The goal

A new team, team-a, needs space on a shared cluster. Afterwards:

  • the team's people can deploy in their namespace and nowhere else, and can't change their own limits;
  • the team can't use more than its share of CPU, memory, pods and storage;
  • its pods run with safe settings, and other namespaces can't reach them.

Every step below was run on a test cluster, and the outputs are real: steps 1 to 7 on kind with Kubernetes 1.31, steps 8 and 9 on kind with Kubernetes 1.36.1. For the whole picture of shared vs dedicated clusters, see lesson 11.

A hands-on companion, where every guardrail is shown failing first and then working, is at github.com/infra-ops-lab/multi-tenancy.

A shared office building gives each company a floor. The badge (identity) opens only your floor, the lease (quota) says how many desks you get, the building rules (Pod Security) say no candles and no extension cords, and the floor doors (network policy) stay locked between companies.

How sign-in works

Person ──SSO──► identity provider (Okta, Entra ID, ...) ──token──► Kubernetes API server
                  groups: [team-a-devs]                     │ authentication: who are you? (user + groups)
                                                            ▼
                         RoleBinding in team-a: group team-a-devs → ClusterRole tenant-developer
                                                            │ authorisation (RBAC): may you do this, here?
                                                            ▼
                         admission: Pod Security, ResourceQuota, LimitRange, policy engine
                                                              may this object be created, at this size?
  • Kubernetes has no user database. It trusts an identity provider and reads the user name and groups from the token (or from the cloud's sign-in).
  • EKS: people sign in to AWS (usually through IAM Identity Center) and get an IAM role. An access entry maps that role into the cluster, either with a Kubernetes group for your own RoleBindings or with an AWS access policy scoped to a namespace. Access entries replace the older aws-auth ConfigMap.
  • AKS: with Microsoft Entra ID integration, the RoleBinding subject is the Entra group's object ID; alternatively Azure RBAC for Kubernetes assigns roles in Azure.
  • GKE: Google Groups can be used as RBAC subjects.
  • Pods authenticate to the cloud separately, with workload identity (IRSA or EKS Pod Identity, Entra Workload ID, GKE Workload Identity).

Authentication and authorisation are separate stages, and the error tells you which one said no:

Error Stage Meaning
401 Unauthorized authentication the API server did not accept who you are: bad, expired or unknown credentials
403 Forbidden authorisation the API server knows who you are, and RBAC has no rule that allows this

A new team member who gets Forbidden has signed in correctly; they are missing a RoleBinding. One who gets Unauthorized has a sign-in problem. RBAC denies by default, so a correct login with no bindings is Forbidden everywhere.

Step 1: namespace with labels and Pod Security

apiVersion: v1
kind: Namespace
metadata:
  name: team-a
  labels:
    platform.example.com/tenant: team-a
    platform.example.com/tier: standard
    pod-security.kubernetes.io/enforce: restricted
    pod-security.kubernetes.io/enforce-version: latest

The tenant and tier labels drive automation, cost reports and policies later (lesson 14).

Step 2: access for the team's groups

Don't bind teams to the built-in edit role. It looks safe (no RBAC, no quota changes), but it lets the team create and delete NetworkPolicies, so a team could delete the network isolation you add in step 4:

$ kubectl describe clusterrole edit | grep networkpolicies.networking
  networkpolicies.networking.k8s.io   []   []   [create delete deletecollection patch update get list watch]

Instead, the platform creates one role for all tenant developers, once per cluster. It lets the team run and debug workloads, and only read the guardrails the platform owns:

# Installed once by the platform team. A ClusterRole grants nothing until it is bound.
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: tenant-developer
rules:
- apiGroups: [""]
  resources: [pods, services, configmaps, secrets, persistentvolumeclaims, serviceaccounts]
  verbs: [get, list, watch, create, update, patch, delete]
- apiGroups: [""]
  resources: [pods/log, pods/exec, pods/portforward]
  verbs: [get, create]
- apiGroups: [apps]
  resources: [deployments, statefulsets, deployments/scale, statefulsets/scale]
  verbs: [get, list, watch, create, update, patch, delete]
- apiGroups: [apps]
  resources: [replicasets]
  verbs: [get, list, watch]
- apiGroups: [batch]
  resources: [jobs, cronjobs]
  verbs: [get, list, watch, create, update, patch, delete]
# See, but not change, what the platform owns.
- apiGroups: [""]
  resources: [resourcequotas, limitranges, events, endpoints]
  verbs: [get, list, watch]
- apiGroups: [networking.k8s.io]
  resources: [networkpolicies]
  verbs: [get, list, watch]

Then bind it, per namespace, to the team's groups:

# Developers in the IdP group "team-a-devs" can run workloads in team-a only
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: team-a-devs
  namespace: team-a
subjects:
- kind: Group
  name: team-a-devs            # EKS: group from the access entry; AKS: Entra group object ID
  apiGroup: rbac.authorization.k8s.io
roleRef:
  kind: ClusterRole
  name: tenant-developer       # a RoleBinding scopes the ClusterRole to this namespace only
  apiGroup: rbac.authorization.k8s.io
---
# Read-only for the support group
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: team-a-viewers
  namespace: team-a
subjects:
- kind: Group
  name: team-a-viewers
  apiGroup: rbac.authorization.k8s.io
roleRef:
  kind: ClusterRole
  name: view
  apiGroup: rbac.authorization.k8s.io

The binding sets the scope, not the role: a RoleBinding grants the ClusterRole's rules inside one namespace, and only a ClusterRoleBinding would grant them everywhere. One role, one binding per tenant namespace, and a change to the role reaches every team at once.

On EKS, map the team's role into the cluster with that group:

aws eks create-access-entry --cluster-name shared-1 \
  --principal-arn arn:aws:iam::111122223333:role/team-a-developers \
  --kubernetes-groups team-a-devs

Step 3: quota and defaults

apiVersion: v1
kind: ResourceQuota
metadata:
  name: team-a-quota
  namespace: team-a
spec:
  hard:
    requests.cpu: "4"
    requests.memory: 8Gi
    limits.cpu: "8"
    limits.memory: 16Gi
    pods: "20"
    services.loadbalancers: "0"     # no public load balancers: use the shared gateway
    persistentvolumeclaims: "5"
    requests.storage: 50Gi
---
apiVersion: v1
kind: LimitRange
metadata:
  name: team-a-defaults
  namespace: team-a
spec:
  limits:
  - type: Container
    defaultRequest: { cpu: 100m, memory: 128Mi }   # used when a pod sets no requests
    default:        { cpu: 500m, memory: 512Mi }   # used when a pod sets no limits
    max:            { cpu: "2",  memory: 4Gi }     # no single container bigger than this

Once a quota covers requests.cpu, every pod must declare CPU requests or it's rejected: the quota checks used + requested ≤ hard, and a pod without requests gives it no number to add. The LimitRange fills in defaults first, so a pod that forgot them still starts.

The two objects guard different things:

ResourceQuota LimitRange
Applies to the whole namespace each container (or pod, or PVC)
Stops the team using more than its share of the cluster one container taking the team's whole budget, or asking for more than a node has
Depends on what else runs yes: used + requested ≤ hard no: the same answer in an empty namespace
Also counts objects (pods, PVCs, load balancers) fills in default requests and limits

Both are checked only when a pod is created. Running pods are never changed or evicted by a new quota or LimitRange.

Step 4: network isolation

# 1) Deny all traffic in and out of every pod in the namespace
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: default-deny
  namespace: team-a
spec:
  podSelector: {}
  policyTypes: [Ingress, Egress]
---
# 2) Allow traffic inside the namespace, and DNS to CoreDNS
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: allow-dns-and-same-namespace
  namespace: team-a
spec:
  podSelector: {}
  policyTypes: [Ingress, Egress]
  ingress:
  - from:
    - podSelector: {}
  egress:
  - to:
    - podSelector: {}
  - to:
    - namespaceSelector:
        matchLabels:
          kubernetes.io/metadata.name: kube-system
      podSelector:
        matchLabels:
          k8s-app: kube-dns
    ports:
    - { protocol: UDP, port: 53 }
    - { protocol: TCP, port: 53 }

NetworkPolicies are allow-lists that add up: a pod that no policy selects allows everything; once a policy selects it for a direction, only what some policy allows gets through. There is no "deny" rule. default-deny denies by selecting every pod and allowing nothing.

Default-deny on egress also blocks DNS. Without the second policy, every call by name fails with a timeout, before any connection is attempted, which is the most common surprise when teams roll this out.

Later, add rules for traffic from the gateway's namespace and egress to approved services. NetworkPolicy needs a CNI that enforces it (Calico, Cilium, and others). On a CNI that doesn't, the policies are accepted and silently ignored, so always run the check in step 7.

Step 5: verify access

An administrator can test as someone else with impersonation (--as, --as-group):

$ kubectl auth can-i create deployments -n team-a  --as=jane@example.com --as-group=team-a-devs
yes
$ kubectl auth can-i create deployments -n default --as=jane@example.com --as-group=team-a-devs
no
$ kubectl auth can-i delete resourcequotas -n team-a --as=jane@example.com --as-group=team-a-devs
no                                   # the team can't remove its own quota
$ kubectl auth can-i create rolebindings -n team-a --as=jane@example.com --as-group=team-a-devs
no                                   # or give itself more rights
$ kubectl auth can-i delete networkpolicies -n team-a --as=jane@example.com --as-group=team-a-devs
no                                   # or remove its network isolation (yes with the built-in edit role)
$ kubectl auth can-i get secrets -n team-a --as=sam@example.com --as-group=team-a-viewers
no                                   # the built-in view role can't read Secrets
$ kubectl get pods -n kube-system --as=jane@example.com --as-group=team-a-devs
Error from server (Forbidden): pods is forbidden: User "jane@example.com" cannot list resource "pods"
in API group "" in the namespace "kube-system"

Step 6: verify quota, defaults and Pod Security

First, why Pod Security is not optional. All pods on a node share one Linux kernel. Here is a namespace without Pod Security, with RBAC, quota and NetworkPolicy all in place. A developer creates a pod with privileged: true and the node's root filesystem mounted at /host, then lists the node's pod logs:

$ kubectl -n team-a exec node-reader -- ls /host/var/log/pods
kube-system_kindnet-4krlm_f0965a40-2ce5-467c-af36-2f723a7e2224
kube-system_kube-proxy-r6wj6_8f59b2b4-c7d4-4280-be9f-c89b1ea91061
team-a_node-reader_8f6c3398-0b2d-4d69-8e3c-8eee84359ced
team-b_web-f68db8c4b-pmwt4_50bbc9ad-7d7f-4b9d-9675-67a585207f01

The last line is another team's pod that happened to share the node; its logs are one cat away. RBAC never saw a request for the other team's resources, and no network traffic was involved. One privileged pod defeats every other layer, which is why enforce: restricted is on the namespace from step 1. Before switching it on for an existing namespace, a server-side dry run lists what would break: kubectl label --dry-run=server --overwrite ns team-a pod-security.kubernetes.io/enforce=restricted.

With the namespace from step 1:

# A Deployment with no resources: the LimitRange filled them in
web-84584b7946-hzfz9  req={"cpu":"100m","memory":"128Mi"}  lim={"cpu":"500m","memory":"512Mi"}

$ kubectl describe quota team-a-quota -n team-a
Resource                Used   Hard
--------                ----   ----
limits.cpu              1      8
limits.memory           1Gi    16Gi
persistentvolumeclaims  0      5
pods                    2      20
requests.cpu            200m   4
requests.memory         256Mi  8Gi
requests.storage        0      50Gi
services.loadbalancers  0      0

# One container asking for 3 CPUs (the LimitRange maximum is 2)
Error from server (Forbidden): pods "too-big" is forbidden: maximum cpu usage per Container is 2, but limit is 3

# Two pods of 1800m are fine; a third would take the namespace past 4 CPUs
Error from server (Forbidden): pods "big-3" is forbidden: exceeded quota: team-a-quota,
requested: requests.cpu=1800m, used: requests.cpu=3800m, limited: requests.cpu=4

# A public load balancer
error: failed to create LoadBalancer service: services "web-lb" is forbidden: exceeded quota: team-a-quota,
requested: services.loadbalancers=1, used: services.loadbalancers=0, limited: services.loadbalancers=0

# A container that runs as root with default settings
Error from server (Forbidden): pods "root-pod" is forbidden: violates PodSecurity "restricted:latest":
allowPrivilegeEscalation != false (...), unrestricted capabilities (...), runAsNonRoot != true (...),
seccompProfile (...)

Quota, Pod Security and Deployments

When a Deployment would exceed the quota or break the Pod Security level, kubectl apply still succeeds: the Deployment object is fine. For Pod Security, kubectl prints a Warning: would violate PodSecurity line and moves on. The ReplicaSet then fails to create pods, and the reason appears only in the namespace events (FailedCreate). Teach teams to look there, and alert on it (step 9 shows a tool that does this per tenant).

Step 7: verify network isolation

curl from a pod in team-a  → http://web.team-a.svc  : 200
curl from a pod in default → http://web.team-a.svc  : no answer (blocked, timed out)

Step 8: dedicated nodes for one team (hard isolation)

Steps 1 to 7 are soft isolation: teams share nodes, the kernel and the control plane, and policy keeps them apart. For a team with heavy, sensitive or regulated workloads, the next step is hard isolation on its own nodes. Two node features do this, and each does only half the job:

Does Does not
Taint on the node: platform.example.com/tenant=team-a:NoExecute repels every pod that doesn't tolerate it; NoExecute also evicts pods already there attract anything: the team's own pods are repelled too
Label on the node + nodeSelector on the pod attracts pods that ask for it keep anyone else out

Use NoExecute, not NoSchedule: with NoSchedule, pods of other teams that were already running on those nodes stay there. Bare pods without a controller are deleted for good when they are evicted.

$ kubectl label node hub-test-worker hub-test-worker2 platform.example.com/tenant=team-a
$ kubectl taint node hub-test-worker hub-test-worker2 platform.example.com/tenant=team-a:NoExecute
node/hub-test-worker tainted
node/hub-test-worker2 tainted

The test cluster has three workers: hub-test-worker and hub-test-worker2 become team-a's, hub-test-worker3 stays shared.

Both the toleration and the nodeSelector are written in the pod spec, by the team. RBAC and Pod Security don't look at them. Before any policy, the team's own pods avoid their nodes, and another team can walk in:

$ kubectl get pods -n team-a -l app=web -o custom-columns=POD:.metadata.name,NODE:.spec.nodeName
POD                    NODE
web-6b464bdf7c-l7dlr   hub-test-worker3
web-6b464bdf7c-lg9kn   hub-test-worker3
web-6b464bdf7c-m6rbr   hub-test-worker3

# team-b creates a pod that selects team-a's nodes and tolerates their taint
$ kubectl get pod sneaky -n team-b -o custom-columns=POD:.metadata.name,NODE:.spec.nodeName
POD      NODE
sneaky   hub-test-worker2

So the platform writes the placement in and checks it, at admission. Since Kubernetes 1.36, both halves are built into the API server: MutatingAdmissionPolicy (GA in 1.36) changes a request on its way in, and ValidatingAdmissionPolicy (GA since 1.30) accepts or rejects it. Both are written in CEL; there is no webhook to run.

# ATTRACT: every pod created in team-a gets team-a's nodeSelector and toleration on its way in.
apiVersion: admissionregistration.k8s.io/v1
kind: MutatingAdmissionPolicy
metadata:
  name: team-a-placement
spec:
  failurePolicy: Fail
  reinvocationPolicy: Never
  matchConstraints:
    resourceRules:
    - { apiGroups: [""], apiVersions: [v1], operations: [CREATE], resources: [pods] }
  mutations:
  - patchType: JSONPatch
    jsonPatch:
      expression: >
        [
          JSONPatch{op: "add", path: "/spec/nodeSelector", value: {"platform.example.com/tenant": "team-a"}},
          has(object.spec.tolerations)
            ? JSONPatch{op: "add", path: "/spec/tolerations/-", value: Object.spec.tolerations{
                key: "platform.example.com/tenant", operator: "Equal", value: "team-a", effect: "NoExecute"}}
            : JSONPatch{op: "add", path: "/spec/tolerations", value: [Object.spec.tolerations{
                key: "platform.example.com/tenant", operator: "Equal", value: "team-a", effect: "NoExecute"}]}
        ]
---
apiVersion: admissionregistration.k8s.io/v1
kind: MutatingAdmissionPolicyBinding
metadata:
  name: team-a-placement
spec:
  policyName: team-a-placement
  matchResources:
    namespaceSelector:
      matchLabels: { platform.example.com/tenant: team-a }
---
# KEEP OUT: in every tenant namespace, a pod may not reach for another tenant's nodes.
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicy
metadata:
  name: tenant-node-boundaries
spec:
  failurePolicy: Fail
  matchConstraints:
    resourceRules:
    - { apiGroups: [""], apiVersions: [v1], operations: [CREATE], resources: [pods] }
  variables:
  - name: tenant
    expression: "namespaceObject.metadata.labels['platform.example.com/tenant']"
  - name: tolerations
    expression: "has(object.spec.tolerations) ? object.spec.tolerations : []"
  validations:
  - expression: >
      variables.tolerations.all(t, !has(t.key) || t.key != 'platform.example.com/tenant' ||
        (has(t.value) && t.value == variables.tenant))
    messageExpression: "'pods may only tolerate their own tenant taint (tenant=' + variables.tenant + ')'"
  - expression: "variables.tolerations.all(t, has(t.key) && t.key != '')"
    message: "a toleration without a key tolerates every taint, including other tenants' nodes"
  - expression: "!has(object.spec.nodeName) || object.spec.nodeName == ''"
    message: "spec.nodeName bypasses the scheduler and taints; let the scheduler place pods"
---
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicyBinding
metadata:
  name: tenant-node-boundaries
spec:
  policyName: tenant-node-boundaries
  validationActions: [Deny]
  matchResources:
    namespaceSelector:
      matchExpressions: [{ key: platform.example.com/tenant, operator: Exists }]

The validating policy closes the three ways onto someone else's nodes: their taint by name, a wildcard toleration (operator: Exists with no key tolerates every taint), and spec.nodeName, which skips the scheduler and so the taint check. Policies apply to pods created afterwards, so restart the team's Deployment:

$ kubectl get pods -n team-a -l app=web -o custom-columns=POD:.metadata.name,NODE:.spec.nodeName,SELECTOR:.spec.nodeSelector
POD                    NODE               SELECTOR
web-84695699f9-782dk   hub-test-worker    map[platform.example.com/tenant:team-a]
web-84695699f9-bwj25   hub-test-worker2   map[platform.example.com/tenant:team-a]
web-84695699f9-ff4mp   hub-test-worker2   map[platform.example.com/tenant:team-a]

$ kubectl -n team-b apply -f sneaky-pod.yaml
The pods "sneaky" is invalid: : ValidatingAdmissionPolicy 'tenant-node-boundaries' with binding 'tenant-node-boundaries' denied request: pods may only tolerate their own tenant taint (tenant=team-b)
$ kubectl -n team-b apply -f wildcard-pod.yaml
The pods "wildcard" is invalid: : ValidatingAdmissionPolicy 'tenant-node-boundaries' with binding 'tenant-node-boundaries' denied request: a toleration without a key tolerates every taint, including other tenants' nodes
$ kubectl -n team-b apply -f nodename-pod.yaml
The pods "direct" is invalid: : ValidatingAdmissionPolicy 'tenant-node-boundaries' with binding 'tenant-node-boundaries' denied request: spec.nodeName bypasses the scheduler and taints; let the scheduler place pods

The team's Deployment never mentions nodes; the platform decided where it runs.

Older clusters

MutatingAdmissionPolicy is generally available from Kubernetes 1.36; on older clusters it is alpha or beta and usually not enabled. Use a policy engine such as Kyverno or OPA Gatekeeper for the same two rules: mutate the placement in, reject anything that reaches for another tenant's nodes. The admission policies are now part of your security boundary: both use failurePolicy: Fail, and only the platform team may change them.

Step 9: see each tenant at a glance

Every guardrail above says "no" somewhere a team rarely looks. Platform teams also need to answer "who has access to this tenant, how much quota is left, and what is stuck right now?" across many namespaces. tenant-insights is a small, read-only operator that keeps one report per tenant. It groups namespaces by the same tenant label as step 1:

$ git clone https://github.com/infra-ops-lab/k8s-operator-lab
$ cd k8s-operator-lab/tenant-insights
$ TENANT_LABEL=platform.example.com/tenant ./scripts/install.sh
$ export PATH="$PWD/plugin:$PATH"          # the kubectl tenants plugin

A team applies an old Deployment that doesn't meet restricted. kubectl prints a warning, the Deployment shows 0/10, and the report explains why:

$ kubectl tenants
TENANT  NAMESPACES  OWNERS  CPU USED/HARD  CPU LEFT  MEM LEFT  BLOCKED  STATUS
team-a  1           1       100m / 4       3.9       7.9Gi     1        Blocked
team-b  1           0       100m / 4       3.9       7.9Gi     0        OK

$ kubectl tenants describe team-a
Tenant:      team-a
Namespaces:  team-a
Status:      Blocked

Access (namespace RoleBindings only):
  team-a           ClusterRole/tenant-developer ← Group team-a-devs

Quota:
  NAMESPACE  RESOURCE                USED   HARD    LEFT    USED%
  team-a     limits.cpu              500m   8       7.5     █░░░░░░░░░   6.2%
  team-a     limits.memory           512Mi  16.0Gi  15.5Gi  ░░░░░░░░░░   3.1%
  team-a     persistentvolumeclaims  0      5       5       ░░░░░░░░░░   0.0%
  team-a     pods                    1      20      19      ░░░░░░░░░░   5.0%
  team-a     requests.cpu            100m   4       3.9     ░░░░░░░░░░   2.5%
  team-a     requests.memory         128Mi  8.0Gi   7.9Gi   ░░░░░░░░░░   1.6%
  team-a     requests.storage        0      50.0Gi  50.0Gi  ░░░░░░░░░░   0.0%
  team-a     services.loadbalancers  0      0       0       ░░░░░░░░░░   0.0%
  Total CPU 100m / 4 (left 3.9) · memory 128Mi / 8.0Gi (left 7.9Gi)

Blocked workloads:
  team-a Deployment/hog  (PodSecurity, 13 attempts)
    Reason: pods "hog-85d48cb456-frsw8" is forbidden: violates PodSecurity "restricted:latest": allowPrivilegeEscalation != false (...), unrestricted capabilities (...), runAsNonRoot != true (...), seccompProfile (...)
    Fix:    the pod breaks the namespace's Pod Security level: fix its securityContext

OWNERS 0 for team-b: in this run only team-a had a RoleBinding, and the report shows it. The tool reports access, quota and blocked workloads; it does not judge security posture, so a namespace with no Pod Security label still reports OK.

The limits of namespaces

Namespaces give soft isolation, and dedicated nodes (step 8) add the first step of hard isolation. Tenants still share:

  • the control plane: API server, etcd, admission webhooks;
  • cluster-scoped objects: CRDs, ClusterRoles, StorageClasses, IngressClasses;
  • the nodes and kernel, unless you add dedicated nodes (step 8) or sandboxed runtimes (gVisor, Kata Containers);
  • the Kubernetes version.
Need Option
Internal teams, trusted code Namespaces with the steps above
Heavy or sensitive workloads Dedicated nodes, enforced by admission policy (step 8)
Untrusted code on shared nodes A sandboxed runtime (gVisor, Kata Containers) through a RuntimeClass
A team needs its own CRDs or operators vCluster: a virtual control plane inside a namespace; pods still run on the shared nodes
Group several namespaces under one tenant with shared quotas Capsule (a Tenant custom resource)
Untrusted code, regulation, a different Kubernetes version A separate cluster or a dedicated cell (lesson 8)

Try it

  1. Apply the four manifests to a test cluster (kind is fine) and repeat the checks in steps 5 to 7.
  2. Scale the Deployment to 25 replicas. How many pods start? Find the reason with kubectl get events -n team-a.
  3. Delete the allow-dns-and-same-namespace policy and try nslookup kubernetes.default from a pod in team-a. Then put it back.
  4. Give team-a-viewers read access to Secrets with your own Role, and decide whether that's a good idea.
  5. Bind a test group to the built-in edit role instead of tenant-developer, then delete the default-deny policy as that group. Switch back.
  6. In a namespace without Pod Security, create a privileged pod with hostPath: / and list /host/var/log/pods. Then label the namespace restricted and try again.
  7. On a cluster with three workers, follow step 8: check where the team's pods land with only the taint, then try each of the three bypasses before and after the policies.
  8. The multi-tenancy repository walks through all of this as a lab, with expected output for every check.

Going deeper

  • Platform-owned objects (quota, LimitRange, RoleBindings, NetworkPolicies, admission policies) should be managed by GitOps, so a manual change is reverted. The tenant role keeps teams from changing them; GitOps keeps admins from drifting them.
  • API Priority and Fairness protects the API server from one tenant's controllers flooding it.
  • Watch quota usage with kube-state-metrics: kube_resourcequota{type="used"} / ignoring(type) kube_resourcequota{type="hard"}.

Recap

  • A tenant on a shared cluster = namespace with Pod Security, RoleBindings from IdP groups to a tenant role (not edit), ResourceQuota plus LimitRange, and default-deny NetworkPolicy with DNS allowed.
  • Forbidden means signed in but not allowed; Unauthorized means not signed in.
  • Verify with impersonation (kubectl auth can-i --as --as-group), quota descriptions and real rejections.
  • Deployments that break quota or Pod Security are accepted but create no pods: look at events, or a per-tenant report.
  • One privileged pod defeats every other layer; Pod Security restricted is not optional.
  • Dedicated nodes need a taint (NoExecute), a label, and admission policy that writes placement in and rejects tolerations, wildcards and nodeName that reach for other tenants' nodes. Since 1.36 that is built in.
  • Beyond that: sandboxed runtimes, vCluster, Capsule or separate clusters when the need is stronger.

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