Kubernetes Multi-Tenancy, Quotas, and Autoscaling
Multi-tenancy in Kubernetes vs. OpenStack
Unlike OpenStack, which natively models domains, projects, roles, and isolated tenant networks out of the box, Kubernetes does not ship with strict multi-tenancy by default. Instead, cluster administrators combine four composable primitives inside Namespaces:
- RBAC Permissions: Restricts which API verbs and resources an authenticated identity may access.
- NetworkPolicy (
netpol): Controls L3/L4 network traffic between Pods. - ResourceQuota (
quota): Caps aggregate resources consumed across an entire Namespace. - LimitRange (
limits): Sets default and per-Pod/per-Container CPU and memory bounds.
NetworkPolicy: Pod firewalling
- Filters allowed flows by L3/L4 parameters, Pod labels, and Namespace selectors.
- Allow-all default: Following Kubernetes’s pluggable philosophy, if no CNI plugin implementing
NetworkPolicyis installed (or no policy selects a Pod), all traffic is allowed between all Pods.
ResourceQuota vs. LimitRange
Learners often mix up ResourceQuota and LimitRange because both govern CPU and memory inside a Namespace—and on Kubernetes diagrams the LimitRange icon carries the short label limits. Keep their scope distinct:
| Object | Scope | What it controls | Key details from the source |
|---|---|---|---|
ResourceQuota (quota) | Entire Namespace (aggregate total) | Total Requests, Limits, GPUs (e.g., requests.nvidia.com/gpu), and object counts | Requests = normal CPU/RAM reserved by kube-scheduler; Limits = hard maximum a Pod may consume. Note: no built-in network bandwidth limit |
LimitRange (limits) | Single Pod or Container (type: Pod or type: Container) | Per-unit min, max, default (default limit), and defaultRequest for CPU & memory | Enforces bounds per container/pod and automatically fills in defaultRequest / default when a Pod manifest omits them |
Concrete example (from source YAML)
Suppose a Namespace has a ResourceQuota capping total limits.cpu: "2" and limits.memory: 2Gi, alongside a LimitRange (type: Container) with min (100m CPU, 99Mi RAM), max (800m CPU, 1Gi RAM), defaultRequest (110m CPU, 111Mi RAM), and default limit (700m CPU, 900Mi RAM):
- If a developer submits a Pod with no CPU/memory specified, Kubernetes injects
110m/111Mias its request and700m/900Mias its limit. - If a developer submits a single container asking for
1.5Gimemory,LimitRangerejects it immediately for exceedingmax: 1Gi—even though the Namespace’s2GiResourceQuotastill had room.
Horizontal Pod Autoscaler (HPA)
Deployment and StatefulSet maintain a static replicas count by default, which wastes capacity during troughs or overloads during spikes. The Horizontal Pod Autoscaler (hpa) automates replica scaling:
scaleTargetRef: Points to the target controller (e.g.,Deploymentphp-apache).- Boundaries:
minReplicasandmaxReplicas(e.g.,1to10). - Metrics & target: Adjusts replicas toward a target value (e.g., CPU
averageUtilization: 50), reading CPU/memory fromkubelet/cAdvisor or custom application metrics from Prometheus. - Prerequisite caveat: A metrics provider must be installed and configured—HPA does not work out of the box without one.
Retrieval
- A Pod spec omits
resources.requestsandresources.limits, yet after creation it runs with a110mCPU request and700mCPU limit. Which object supplied those values, and how does its role differ fromResourceQuota?
LimitRangesupplieddefaultRequest(110m) anddefaultlimit (700m) for the individual container/pod.ResourceQuota, by contrast, caps the combined total of requests, limits, GPUs, or objects across all pods in the entire Namespace. - You create an HPA targeting
averageUtilization: 50on a Deployment, but replicas never scale during a CPU spike. Name one cluster prerequisite from the lecture that may be missing.
A metrics provider (for example,kubelet/cAdvisor metrics pipeline or Prometheus for custom metrics) is not configured by default and must be deployed for HPA to read utilization.
Source: Lecture 11 - Kubernetes, PDF pages 38–42 (printed slides 44–48).