Why static GPU allocation (even with MPS/MIG) falls short

Modern AI workloads rely heavily on GPUs—for example, slide 32’s inference chart across llama3.2:1b, llama3.2:3b, llama3.1:8b, and llama3.1:70b shows Cloud GPU throughput vastly outpacing Cloud CPU and Edge—meaning GPU efficiency directly governs operational costs, energy consumption, scalability, and resource availability (PDF p. 30 / printed slide 32).

However, Kubernetes allocates extended resources like nvidia.com/gpu: 1 at container scheduling time for the entire lifetime of the Pod without overcommitment (PDF p. 31 / printed slide 33). Even when a GPU is split using MPS or MIG, real AI workloads (inference, robotics, simulation, analytics) arrive in bursts separated by idle gaps (PDF pp. 32–33 / printed slides 35–36):

  • When Application Stream 1 and Application Stream 2 each bind to a static Pod-owned GPU slice, Stream 1’s slice sits idle during Stream 1’s gaps even while Stream 2 has bursts waiting.
  • Maximizing throughput requires interleaving short-lived bursts dynamically onto GPU capacity rather than reserving slices for long-running Pods.

Function-as-a-Service (FaaS) for GPU workloads

FaaS shifts execution from long-lived Pods to event-driven, short-lived function instances with rapid scaling, high resource multiplexing, and elasticity (PDF p. 34 / printed slide 37):

  • Benefits for GPUs: Higher GPU utilization, fewer idle Pod allocations, faster workload consolidation, more efficient accelerator sharing, and quick responsiveness to traffic bursts.
  • Kubernetes FaaS ecosystem (PDF p. 35 / printed slide 38):
    • General-purpose platforms: OpenFaaS (Kubernetes-focused FaaS), Knative (serverless Kubernetes platform initiated by Google), and Fission (fast Kubernetes serverless framework).
    • AI-specific platforms: KServe (serverless AI model serving) and KubeRay (distributed Python/AI orchestration on Kubernetes).

Ray Core: Pythonic distributed compute

Ray is an open-source distributed framework built to parallelize Python applications across clusters and accelerators with minimal code changes (PDF p. 36 / printed slide 39):

  • Decorating a Python function with @ray.remote turns it into a Task—a stateless function that Ray schedules automatically across remote workers, retries on failure, and returns results to the driver program:
import ray
 
@ray.remote
def retrieve_task(item):
    return retrieve(item)
  • Decorating a Python class with @ray.remote turns it into a stateful Actor distributed across the cluster (distinct from stateless Tasks).

KubeRay and the RayCluster Custom Resource

KubeRay is the official Kubernetes Operator for running Ray natively on Kubernetes, implementing Ray nodes as standard Kubernetes Pods with continuous reconciliation and fault tolerance (PDF pp. 37–41 / printed slides 40–44; see Kubernetes Extensibility CRDs Operators Webhooks and Drivers).

Long-running Ray clusters are defined declaratively with the RayCluster CRD (apiVersion: ray.io/v1, kind: RayCluster), splitting cluster management into two main sections (PDF pp. 39–41 / printed slides 42–44):

RayCluster Spec SectionRoleKey YAML & Architecture Details
headGroupSpec (PDF pp. 39–40)Runs 1 Ray Head Pod (cluster coordinator)Hosts Ray GCS (port 6379, Global Control Store for worker communication and task assignment), Ray Dashboard (8265), and Ray Client (10001), exposed via a ClusterIP Service (see Kubernetes Services Ingress and Reverse Proxy)
workerGroupSpecs (PDF pp. 39, 41)Runs N Ray Worker Pods (compute execution)Configures starting replicas (e.g., 2) and Ray Autoscaler bounds (minReplicas: 1, maxReplicas: 5), plus container image (e.g., rayproject/ray:2.9.0) and CPU/memory requests/limits

KubeRay continuously reconciles the Head and Worker Pods so that if a worker node fails, pods are recreated automatically to preserve cluster availability.

Common confusions

  • MPS/MIG vs. FaaS/dynamic multiplexing: MIG/MPS split a GPU spatially or logically, yet a Pod still locks its slice for the Pod’s lifetime; FaaS attacks temporal waste across bursty streams by spinning up short-lived event-driven executions only when requests arrive.
  • Ray Tasks vs. Ray Actors: @ray.remote on a function produces a stateless Task; @ray.remote on a class produces a stateful Actor.
  • headGroupSpec vs. workerGroupSpecs: headGroupSpec defines the single coordinator Pod (GCS/Dashboard/Client), whereas workerGroupSpecs defines scalable worker pools bounded by minReplicas and maxReplicas.

Retrieval

  1. If a cluster already uses MIG to split GPUs among long-running inference Pods, why can expensive GPU compute still sit wasted during real user traffic, and how does FaaS fix this?
    Kubernetes reserves extended GPU resources for the entire lifetime of each Pod, so during quiet intervals in a bursty application stream, that Pod’s MIG slice sits idle even if another stream is spiking. FaaS runs event-driven, short-lived function instances that allocate accelerators only during active bursts and scale down immediately afterward, tightly interleaving streams.
  2. In Ray Core, what does @ray.remote do to a Python function, and how do KubeRay and RayCluster map Ray onto Kubernetes?
    @ray.remote turns a Python function into a stateless distributed Task (or a class into a stateful Actor) scheduled across workers with automatic failure handling. KubeRay is a Kubernetes Operator that watches RayCluster CRDs and runs Ray head and worker nodes as standard Kubernetes Pods, continuously reconciling failures and autoscaling worker replicas.
  3. In a RayCluster manifest, distinguish headGroupSpec from workerGroupSpecs and explain how workers receive tasks.
    headGroupSpec defines the single Ray Head Pod running Ray GCS (6379), Dashboard (8265), and Client (10001) behind a ClusterIP Service, while workerGroupSpecs defines the pool of Ray Worker Pods (with starting replicas and minReplicas/maxReplicas autoscaler bounds) that connect to the head’s GCS for task assignment.

Source: Lecture 17 - AI in Kubernetes, PDF pages 28–41 (printed slides 30–44).