Managing Multi-Tenancy

1. Creating Tenant Namespaces

kubectl create ns team-a
kubectl label ns team-a tenant=team-a env=prod

2. Setting Resource Quotas

apiVersion: v1
kind: ResourceQuota
metadata: { name: quota, namespace: team-a }
spec:
  hard:
    requests.cpu: "20"
    requests.memory: 40Gi
    limits.cpu: "40"
    limits.memory: 80Gi
    persistentvolumeclaims: "20"
    count/deployments.apps: "30"

3. Configuring Limit Ranges

See §30.6 — apply LimitRange to enforce per-container defaults and maximums.

UseBenefit
Default requestsPrevent BestEffort pods evading quota
Max sizesPrevent single huge pod

4. Implementing RBAC Isolation

kubectl create rolebinding team-a-admin \
  --clusterrole=admin --group=team-a -n team-a

5. Using Network Policies

apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata: { name: tenant-isolate, namespace: team-a }
spec:
  podSelector: {}
  policyTypes: [Ingress]
  ingress:
  - from:
    - namespaceSelector: { matchLabels: { tenant: team-a } }
    - namespaceSelector: { matchLabels: { name: kube-system } }

6. Configuring Pod Security

kubectl label ns team-a \
  pod-security.kubernetes.io/enforce=restricted \
  pod-security.kubernetes.io/enforce-version=latest

7. Using Virtual Clusters

ToolDetail
vClusterFull nested K8s API in a namespace; CRDs isolated
KamajiHosted control planes
CapsuleLighter — namespace groups + policies

8. Implementing Hierarchical Namespaces

kubectl hns create dev -n team-a
kubectl hns tree team-a
FeatureDetail
Policy inheritanceRBAC, NetworkPolicy propagate to children
HNCHierarchical Namespace Controller (SIG)

9. Monitoring Tenant Resources

kubectl get resourcequota -A
kubectl describe quota -n team-a

10. Implementing Cost Allocation

ToolDetail
OpenCostCNCF; namespace/label cost
KubecostCommercial UI + chargeback
ApproachTag workloads with cost-center label