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.
| Use | Benefit |
| Default requests | Prevent BestEffort pods evading quota |
| Max sizes | Prevent 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
| Tool | Detail |
| vCluster | Full nested K8s API in a namespace; CRDs isolated |
| Kamaji | Hosted control planes |
| Capsule | Lighter — namespace groups + policies |
8. Implementing Hierarchical Namespaces
kubectl hns create dev -n team-a
kubectl hns tree team-a
| Feature | Detail |
| Policy inheritance | RBAC, NetworkPolicy propagate to children |
| HNC | Hierarchical Namespace Controller (SIG) |
9. Monitoring Tenant Resources
kubectl get resourcequota -A
kubectl describe quota -n team-a
10. Implementing Cost Allocation
| Tool | Detail |
| OpenCost | CNCF; namespace/label cost |
| Kubecost | Commercial UI + chargeback |
| Approach | Tag workloads with cost-center label |