Design for capacity flexibility and efficiency on GKE with Gemini

This document explains how to design resilient Google Kubernetes Engine (GKE) clusters and workload scheduling strategies that help you obtain resources, such as GPUs, TPUs, and high-performance CPUs. By leveraging Gemini in Google Cloud and Compute Advisor (Preview), you can prevent pending Pods and improve reliable scheduling for AI workloads.

This document is intended for Cloud architects and Platform admins and operators who manage GKE infrastructure and want to optimize capacity planning and scheduling.

Overview of flexibility, efficiency, and availability of compute capacity on GKE

Kubernetes scheduling relies on declared resource requests. When scheduling large-scale accelerators, like GPUs or TPUs, strict resource requests can lead to clusters failing to scale up if specific hardware is unavailable. You can optimize capacity availability on GKE by using the following features:

  • Node pool auto-creation: dynamic, multi-family node pool creation.
  • Workload-level fallbacks: tolerations and node selectors configured to accept alternative hardware.
  • Geographic and regional scheduling: GKE multi-zonal and multi-regional capabilities.
  • Reservation management: consuming pre-purchased capacity before requesting on-demand resources.
If you want AI-powered assistance to apply the best practices in this document to your clusters and workloads, then run the following prompt in Compute Advisor (Preview):

Compute Advisor Compute Advisor is an AI-powered assistant that you can prompt to get customized recommendations for your infrastructure based on information such as your quota limits, existing reservations, and resource location constraints.

This prompt evaluates your project's quotas and reservations, recommends hardware fallbacks and scheduling strategies to improve capacity availability, and generates ComputeClass and Pod manifests.

Act as a GKE capacity planning architect. Help me design GKE clusters and workload scheduling strategies that improve my chances of obtaining scarce GPU, TPU, and high-performance CPU capacity, based on my project's quotas, active reservations, and available regions and zones.

Provide the following:

1. Project capacity check: Inspect my project's GPU, TPU, and CPU quotas and active reservations across regions to identify where I can obtain capacity and which reservations my workloads should consume before they scale into on-demand capacity.

2. Hardware flexibility and fallbacks: Recommend primary machine series and fallback alternatives for my workloads (for example, A4 or A3 GPUs with G2 fallbacks, Ironwood (TPU7x) with TPU v6e or v5p fallbacks, and N4 with N4D, C4, or C4D fallbacks), and define a ComputeClass with prioritized rules, the `whenUnsatisfiable` field, and active migration settings.

3. Scheduling and provisioning strategy: Recommend node pool auto-creation settings, multi-zonal or multi-region scheduling (for example, with Kueue), Spot VMs, flex-start with queued provisioning, capacity buffers, and the `ANY` location policy for the cluster autoscaler.

Format the recommendations as a Markdown table that lists each workload, primary hardware, fallback hardware, provisioning model, and target zones, provide ready-to-apply ComputeClass and Pod YAML manifests, and end with 2-3 questions about my workload type, accelerator flexibility, and fault tolerance to refine the plan.

Best practices for flexibility, efficiency, and availability of compute capacity on GKE

This section provides recommendations to increase your capacity availability when scheduling workloads on GKE. These best practices cover strategies such as designing flexible hardware requirements, configuring node pool auto-creation, and leveraging geographic distribution to adapt to resource constraints. Node pool auto-creation automatically manages node pools based on Pod specifications. Rather than pre-defining node pools, specify resource requirements in your Pod manifests, and let GKE dynamically create nodes.

Options for increasing the availability of compute capacity

To optimize capacity availability, you can instruct GKE to avoid binding workloads to a single static machine family or accelerator type. The following are examples of how you can configure flexible node pools and Pod affinity rules for different workload classes. The specific alternatives you choose depend on your application's resource demands:

  • General-purpose CPU node pools:

    • Primary example: N4 (Intel-based general-purpose).
    • Sample alternatives: N4D (AMD EPYC general-purpose), C4 or C3 (Intel general-purpose), or C4D or C3D (AMD EPYC general-purpose).
    • Implementation pattern: configure Pod specs with a custom ComputeClass or node affinity rules that permit scheduling across multiple machine family labels, for example, cloud.google.com/machine-family in ["n4", "n4d", "c4", "c4d"]. This configuration lets GKE provision whichever pool has available capacity.
  • GPU node pools:

    • Primary example: A3 Series (NVIDIA H100 GPUs) or A4 Series (NVIDIA B200 GPUs).
    • Sample alternatives: G2 Series (NVIDIA L4 GPUs) or alternative accelerator tiers.
    • Implementation pattern: configure separate node pools or ComputeClasses for different GPU tiers. For inference or serving workloads that can run across accelerator generations, allow Pods to fall back to G2 (L4) or alternative GPU pools if primary accelerator provisioning is constrained.
  • TPU node pools:

    • Primary example: Ironwood (TPU7x).
    • Sample alternatives: TPU v6 (Trillium) or TPU v5 (v5e or v5p).
    • Implementation pattern: TPU slice provisioning can be highly constrained. Design training workloads with framework-level flexibility (for example, JAX or PyTorch configurations supporting variable slice topologies) to deploy on v6 or v5 slices when Ironwood (TPU7x) capacity is unavailable.

The following table summarizes the primary selections and hardware alternatives for different types of workloads:

Workload type Primary selection example Sample alternatives Architectural considerations
System or core workloads N4 N4D, C4, C4D, C3, C3D Spans modern Intel and AMD hardware pools for node pool auto-creation.
GPU inference and processing A3 (H100) or A4 (B200) G2 (L4) Flexibly targets lower-cost or higher-availability GPU node pools.
TPU model training Ironwood (TPU7x) TPU v6, TPU v5 (v5e or v5p) Utilizes flexible topologies for slice-based scheduling.

Implement node pool auto-creation and ComputeClasses

To optimize capacity availability, combine node pool auto-creation with ComputeClasses. The following list includes best practices:

  • Define ComputeClasses: create ComputeClass resources that specify a prioritized list of machine families, GPU types, or provisioning models. GKE attempts to provision nodes by using the highest-priority configuration available in the class. A prioritized fallback list significantly helps you obtain the resources that your workloads require. For example, to prevent GKE from falling back to general-purpose machines when a preferred specialized accelerator is unavailable, add the whenUnsatisfiable: DoNotScaleUp setting to your ComputeClass configuration. For more information, see Control autoscaled node attributes with custom ComputeClasses.

  • Enable active migration (optimizeRulePriority: true) for stateless or disruption-tolerant workloads: configure active migration in your ComputeClass so GKE automatically cordons, drains, and replaces fallback nodes with your higher-priority machine series when capacity recovers in that location.

  • Use dynamic StorageClasses for cross-generation fallback: in GKE version 1.35.3-gke.1290000 and later, when a ComputeClass spans Hyperdisk-only series (such as C4, C4D, and N4) and Persistent Disk series (such as N2 and N2D), configure stateful workloads so that GKE dynamically selects a compatible disk type. To do so, use a StorageClass with automated disk type selection (parameters.type: dynamic) and the volumeBindingMode: WaitForFirstConsumer setting.

  • Reference ComputeClasses in Pod specs: in your workload Pod specifications, use the cloud.google.com/compute-class label to target your custom ComputeClass instead of a specific machine family or GPU type. For more information, see Request a ComputeClass in a workload.

  • Define multiple tolerations: if you don't use ComputeClasses, use node affinity rules in your Pod specifications that permit a range of machine families (such as cloud.google.com/machine-family in ["n4", "n4d", "c4", "c4d"]). For more information, see Configure node pool auto-creation.

Geographic and multi-region flexibility on GKE

To increase capacity availability, deploy GKE clusters that span multiple zones, or run multi-cluster architectures:

  • Multi-zonal clusters: ensure node pools are configured to auto-scale across all available zones in a region.

  • Multi-region cluster federation: for large asynchronous jobs (such as offline batch inference or distributed training), deploy a multi-cluster orchestrator (like Kueue or Cluster Director) to queue workloads globally and dispatch them to a region with available capacity.

  • Pods running on Spot VMs: run interruptible workloads on Spot VMs by adding tolerations and instructing GKE to distribute excess capacity in different zones.

Additional best practices for flexibility, efficiency, and availability of compute capacity in GKE

Beyond hardware diversification, incorporate these GKE best practices to optimize cluster scaling success:

  • Use capacity buffers: proactively reserve spare node capacity so that high-priority AI workloads can schedule immediately without waiting for new node provisioning. You can use declarative capacity buffers with the active buffer strategy for GPU and TPU workloads so that the cluster autoscaler automatically maintains spare capacity.
  • Use Flex-start with queued provisioning: for large batch and AI model training jobs, use Flex-start with queued provisioning, which integrates with Kueue and Dynamic Workload Scheduler. Flex-start with queued provisions all-or-nothing atomic node allocation, which prevents partial cluster scale-up failures. For more information, see Run a large-scale workload with flex-start with queued provisioning.
  • Enable image streaming and container image preloading: for large AI container images (such as PyTorch or TensorFlow images exceeding 10 GB), enable GKE Image streaming or use secondary boot disks for image preloading. This configuration reduces node warm-up time, which lets newly provisioned nodes start running workloads in seconds. For more information, see Use Image streaming to pull container images and Use secondary boot disks to preload data or container images.
  • Set cluster autoscaler location policy to ANY: configure node pools (especially for Spot VMs or flex-start) with the ANY location policy. This setting instructs the cluster autoscaler to search for requested capacity across all specified zones. Cluster autoscaler finds capacity over balancing node counts. For more information, see Cluster autoscaler overview.
  • Optimize accelerator utilization with GPU sharing: for workloads that don't require a dedicated GPU, use GPU time-sharing, multi-instance GPUs (MIG), or NVIDIA MPS to allow multiple containers to share a single accelerator. This approach optimizes effective capacity across node pools. For more information, see About GPU sharing strategies in GKE.

What's next