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:

  1. RBAC Permissions: Restricts which API verbs and resources an authenticated identity may access.
  2. NetworkPolicy (netpol): Controls L3/L4 network traffic between Pods.
  3. ResourceQuota (quota): Caps aggregate resources consumed across an entire Namespace.
  4. 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 NetworkPolicy is 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:

ObjectScopeWhat it controlsKey details from the source
ResourceQuota (quota)Entire Namespace (aggregate total)Total Requests, Limits, GPUs (e.g., requests.nvidia.com/gpu), and object countsRequests = 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 & memoryEnforces 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/111Mi as its request and 700m/900Mi as its limit.
  • If a developer submits a single container asking for 1.5Gi memory, LimitRange rejects it immediately for exceeding max: 1Gi—even though the Namespace’s 2Gi ResourceQuota still 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., Deployment php-apache).
  • Boundaries: minReplicas and maxReplicas (e.g., 1 to 10).
  • Metrics & target: Adjusts replicas toward a target value (e.g., CPU averageUtilization: 50), reading CPU/memory from kubelet/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

  1. A Pod spec omits resources.requests and resources.limits, yet after creation it runs with a 110m CPU request and 700m CPU limit. Which object supplied those values, and how does its role differ from ResourceQuota?
    LimitRange supplied defaultRequest (110m) and default limit (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.
  2. You create an HPA targeting averageUtilization: 50 on 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).