Skip to content

Validate regional Hyperdisk quota before Google Kubernetes Engine scale-out

Google Kubernetes Engine (GKE) custom ComputeClasses that use fourth-generation (Gen 4) machine series, such as n4 and c4, provision Hyperdisk Balanced boot disks and volumes, because these series support only Hyperdisk. The regional Hyperdisk Balanced capacity quota varies by project and region. Observed starting values range from 500 gigabytes (GB) to 80 tebibytes (TiB), or 81,920 GB, because quota GB use the binary unit of the disk sizeGb field, so 1 GB equals 1 gibibyte (GiB). When a scale-out exhausts this quota, node provisioning times out and resembles a compute stockout.

This project provides an Agent Skill with a deterministic Python command-line interface (CLI) that sizes the worst-case Hyperdisk Balanced demand of a scale-out plan, compares it with live or offline quota, and prepares human-confirmed quota increase requests (QIRs). It also includes test scenarios and a Terraform testbed that runs no nodes.

Architecture

flowchart TB
    subgraph Inputs ["Inputs"]
        Plan["Scale-out plan, written by the operator or taken from a scenario"]
        Manifests["ComputeClass, StorageClass, VolumeAttributesClass, StatefulSet, and PersistentVolumeClaim manifests"]
        Quota["Live quota: regions describe, Cloud Quotas regional and zonal limits, and disks list usage, or an offline snapshot"]
    end

    subgraph Testbed ["Terraform testbed (terraform/)"]
        Cluster["Zonal GKE Standard cluster without node pools"]
        Scenarios["Scenario bundles and offline quota snapshot"]
    end

    subgraph Skill ["Agent Skill (.agents/skills/gke-hyperdisk-quota-preflight)"]
        Discover["Step 1: read-only discovery"]
        Run["Step 2: run hyperdisk_preflight.py"]
        Present["Step 3: present the report and QIRs for approval"]
    end

    subgraph CLI ["Pre-flight CLI (hyperdisk_preflight.py)"]
        Size["Worst-case demand sizing"]
        Ceiling["Validator registry: check_regional_hyperdisk_80tib_ceiling"]
        Writer["Report writer"]
    end

    subgraph Outputs ["Outputs"]
        Reports["JSON and Markdown assessment reports"]
        Script["Human-confirmed QIR script"]
        Payload["Multi-project QIR CSV payload"]
        Snapshot["quota_snapshot.json from live runs"]
    end

    Cluster --> Discover
    Discover --> Manifests
    Scenarios --> Plan
    Plan --> Run
    Manifests --> Run
    Run --> Size
    Quota -->|"--live or --quota-snapshot-json"| Size
    Size --> Ceiling
    Ceiling --> Writer
    Writer --> Reports
    Writer --> Script
    Writer --> Payload
    Writer --> Snapshot
    Reports --> Present
    Script --> Present

Components

  • Agent Skill (.agents/skills/gke-hyperdisk-quota-preflight/): Guides an artificial intelligence (AI) coding agent through read-only discovery, worst-case demand calculation, and an assessment report with QIRs that an operator approves and submits.
  • Pre-flight CLI (scripts/hyperdisk_preflight.py in the skill): Reads Kubernetes manifests and a JavaScript Object Notation (JSON) or YAML scale-out plan, reads quota with gcloud or from an offline snapshot, and runs the validators in scripts/preflight/validators/. The built-in validator compares the projected capacity, input/output operations per second (IOPS), and throughput with the regional limits, warns when the demand of a region exceeds a zonal limit in one zone, and generates QIRs. Its report writer saves the reports, the QIR script, the comma-separated values (CSV) payload, and, in --live mode, quota_snapshot.json for offline replay.
  • Scenarios (terraform/scenarios/): YAML bundles with a scale-out plan and its manifests, plus an offline quota snapshot that models an 80 TiB (81,920 GB) limit with 4,096 GB in use in us-central1, 61,440 GB in use in us-east4, and no usage in europe-west4:

    Scenario Plan Expected verdict
    pass-small-scaleout.yaml 3 Gen 4 nodes and 3 Hyperdisk-backed replicas PASS
    fail-80tib-breach.yaml 300 Gen 4 nodes and 20 replicas with 1 TiB volumes FAIL with a QIR for 101,376 GB
    fail-multi-project-breach.yaml Gen 4 scale-outs in three projects and regions FAIL with QIRs for 92,160 GB in us-east4 and 108,544 GB in europe-west4
  • Terraform testbed (terraform/): A zonal GKE Standard cluster without node pools that gives the skill a real cluster and live quota to evaluate. It needs Terraform 1.5 or later, the hashicorp/google provider ~> 8.0, and the hashicorp/random provider ~> 3.6, which .terraform.lock.hcl locks at 8.12.0 and 3.9.1.

The CLI calculates worst-case demand as targetNodes x largest Hyperdisk boot disk + replicas x volume size, and adds the current usage and a safety headroom that defaults to 20 percent. Hyperdisk Balanced High Availability volumes count twice their size against the capacity quota. Only the IOPS and throughput above the free per-volume baseline count against the performance quotas, including the Compute Engine default performance of boot disks and volumes that don't set IOPS or throughput. The CLI validates project IDs, regions, Kubernetes names, plan names, contact emails, and numeric ranges, and shell-quotes every value that it writes to the generated QIR script.

The CLI keeps one manifest inventory for every cluster in a plan, so a ComputeClass, StorageClass, or workload name must have the same definition in every cluster that uses it. Each Cloud Quotas preference ID combines the quota and the region, so a later plan for the same project and region updates the pending request of an earlier plan. Combine scale-outs that share a project and region into one plan.

Requirements

Grant only the roles for the tasks that you perform. The read-only pre-flight never needs the testbed roles.

Read-only pre-flight on existing clusters

  • An account with the following Identity and Access Management (IAM) roles on every project in the plan:
    • Compute Viewer (roles/compute.viewer)
    • Kubernetes Engine Viewer (roles/container.viewer)
    • Cloud Quotas Viewer (roles/cloudquotas.viewer)
  • The Cloud Quotas API enabled on every project in the plan, so that the CLI can read the limits that gcloud compute regions describe omits. An account with the serviceusage.services.enable permission, such as Service Usage Admin, enables it once:

    gcloud services enable cloudquotas.googleapis.com --project="${PROJECT_ID}"
    

Quota increase request submission

  • Cloud Quotas Admin (roles/cloudquotas.admin), the narrowest predefined role with the cloudquotas.quotas.update permission, on every project in the plan. Only the person who submits the QIRs needs it.

Optional Terraform testbed in a sandbox project

  • A Google Cloud project with billing enabled.
  • An account with the following IAM roles on the project. The Terraform configuration enables the Cloud Quotas API and the other APIs that it needs:
    • Kubernetes Engine Admin (roles/container.admin)
    • Compute Network Admin (roles/compute.networkAdmin)
    • Compute Viewer (roles/compute.viewer)
    • Service Account Admin (roles/iam.serviceAccountAdmin)
    • Service Account User (roles/iam.serviceAccountUser)
    • Project IAM Admin (roles/resourcemanager.projectIamAdmin)
    • Service Usage Admin (roles/serviceusage.serviceUsageAdmin), which also grants the Cloud Quotas permissions to read quota and submit QIRs
  • Terraform 1.5 or later.
  • A GKE release channel that offers version 1.36.4-gke.1469000 or later in your zone. The testbed uses the REGULAR channel by default.

Tools

Prepare the environment

  1. Set your project and location environment variables and configure the gcloud CLI:

    export PROJECT_ID="YOUR_PROJECT_ID"
    export REGION="us-central1"
    export ZONE="us-central1-a"
    gcloud config set project "${PROJECT_ID}"
    gcloud auth login
    gcloud auth application-default login
    
  2. Clone the repository and change the working directory:

    git clone --filter=blob:none --no-checkout https://github.com/GoogleCloudPlatform/cloud-solutions
    cd cloud-solutions
    git sparse-checkout set --cone projects/gke-hyperdisk-quota-preflight
    git checkout
    cd projects/gke-hyperdisk-quota-preflight
    
  3. Create a Python virtual environment and install the hash-locked dependencies of the pre-flight CLI:

    python3 -m venv .venv
    .venv/bin/python -m pip install --require-hashes -r .agents/skills/gke-hyperdisk-quota-preflight/scripts/requirements.txt
    export PREFLIGHT_CLI=".agents/skills/gke-hyperdisk-quota-preflight/scripts/hyperdisk_preflight.py"
    

Run the scenarios offline

The offline quota snapshot lets you evaluate the scenarios without Google Cloud credentials:

  1. Run the scenario that fits within the 80 TiB ceiling:

    .venv/bin/python "${PREFLIGHT_CLI}" \
      --plan terraform/scenarios/pass-small-scaleout.yaml \
      --quota-snapshot-json terraform/scenarios/offline-quota-snapshot.json \
      --output-dir preflight-output/pass-small-scaleout
    

    The CLI exits with code 0 and reports a projected usage of 4,456 GB.

  2. Run the scenario that breaches the 80 TiB ceiling:

    .venv/bin/python "${PREFLIGHT_CLI}" \
      --plan terraform/scenarios/fail-80tib-breach.yaml \
      --quota-snapshot-json terraform/scenarios/offline-quota-snapshot.json \
      --output-dir preflight-output/fail-80tib-breach
    

    The CLI exits with code 1. The raw demand of 80,480 GB fits under the 81,920 GB limit, but the 4,096 GB in use and the 20 percent headroom project 100,672 GB, so the CLI requests 101,376 GB.

  3. Run the scenario that scales out across three projects and regions:

    .venv/bin/python "${PREFLIGHT_CLI}" \
      --plan terraform/scenarios/fail-multi-project-breach.yaml \
      --quota-snapshot-json terraform/scenarios/offline-quota-snapshot.json \
      --output-dir preflight-output/fail-multi-project-breach
    

    The CLI exits with code 1. bulk_qir_payload.csv has one row for us-east4 and one for europe-west4. The us-central1 project fits under the ceiling.

The CLI exit code tells automation how to proceed:

  • 0: no validator failed. WARN findings, such as HDB-ZONAL-PERFORMANCE-QUOTA, can still exist.
  • 1: at least one validator failed, so the plan needs a QIR or a smaller scale-out.
  • 2: invalid input or failed discovery, such as a malformed plan, a ComputeClass or workload that the manifests don't define, an oversized file, or a gcloud error such as PERMISSION_DENIED. Fix the input or the missing permission and rerun. The CLI writes no outputs, so any files in the output directory come from an earlier run. Never treat exit code 2 as a pass.

In a pipeline, block the scale-out on any nonzero exit code.

Each output directory contains the following artifacts:

  • preflight_report.json and preflight_report.md: assessment reports with quota checks, provisioned totals, demand per plan entry, findings, and sizing assumptions. Offline runs report the zonal check as INFO, because snapshots carry no zonal limits.
  • request_quota_increases.sh: script that lists every QIR and submits nothing until an operator types submit.
  • bulk_qir_payload.csv: CSV payload with one row per QIR across all projects.

Deploy the testbed with Terraform

The testbed runs no nodes and creates no Hyperdisk volumes, so the GKE cluster management fee is its main cost. For free tier credits, see GKE pricing.

  1. Initialize and apply the Terraform configuration:

    terraform -chdir=terraform init
    terraform -chdir=terraform apply \
      -var="project_id=${PROJECT_ID}" \
      -var="region=${REGION}" \
      -var="zone=${ZONE}"
    

    A cluster without node pools needs GKE 1.36.4-gke.1469000 or later. If the REGULAR release channel doesn't offer that version in your zone, the plan stops with a precondition error. Rerun the command with -var="release_channel=RAPID".

  2. Optionally, verify that kubectl reaches the control plane. The get_credentials_command Terraform output prints the same get-credentials command:

    gcloud container clusters get-credentials \
      "$(terraform -chdir=terraform output -raw cluster_name)" \
      --project="${PROJECT_ID}" \
      --location="${ZONE}" \
      --dns-endpoint
    kubectl get namespaces
    

Testbed security

The testbed hardens the cluster without adding nodes:

Terraform stores its state in a local terraform.tfstate file. Keep this file out of version control.

Run the pre-flight against live quota

  1. Evaluate a scenario against the live quota of your project. The CLI uses read-only gcloud commands and creates no disks:

    .venv/bin/python "${PREFLIGHT_CLI}" \
      --plan terraform/scenarios/fail-80tib-breach.yaml \
      --live \
      --project-id "${PROJECT_ID}" \
      --region "${REGION}" \
      --output-dir preflight-output/live-fail-80tib-breach
    

    The CLI reads the regional quota with gcloud compute regions describe. For metrics that the output omits, it reads the limit from the Cloud Quotas API and the usage from the Hyperdisk Balanced disk inventory. It reads the zonal limits from the Cloud Quotas API. The zonal check assumes that all the IOPS and throughput demand of the region lands in its busiest zone. The CLI saves the regional quota to quota_snapshot.json for offline replay.

  2. Start your agent CLI from the projects/gke-hyperdisk-quota-preflight directory so it discovers the skill under .agents/skills/, and give your agent the following prompt. Get the cluster name with terraform -chdir=terraform output -raw cluster_name:

    Use the gke-hyperdisk-quota-preflight skill to validate the scale-out plan
    in terraform/scenarios/fail-80tib-breach.yaml against the live Hyperdisk
    quota of project <PROJECT_ID> in region <REGION>. Include the inventory of
    cluster <CLUSTER_NAME> in zone <ZONE> in the assessment. The cluster
    exposes only its DNS-based control plane endpoint.
    

    The agent discovers the quota and the cluster inventory with read-only commands, runs the pre-flight CLI, and presents the assessment report and the QIRs for your approval.

Submit quota increase requests

The QIR script never submits a request without confirmation:

  1. Review the requests without submitting them:

    bash preflight-output/live-fail-80tib-breach/request_quota_increases.sh --dry-run
    
  2. After the quota owner approves the requests, run the script in an interactive terminal and type submit when prompted. To override the contact email of the plan, set the QIR_CONTACT_EMAIL environment variable. The contact email must belong to a Google account with the cloudquotas.quotas.update permission on every project in the plan, not an unprivileged mailing alias. Otherwise, Cloud Quotas denies any request that needs follow-up information (gcloud quotas preferences update):

    bash preflight-output/live-fail-80tib-breach/request_quota_increases.sh
    

    The script runs gcloud quotas preferences update --allow-missing once for each request with a deterministic preference ID, so the first run creates each preference and later runs update it to the newly calculated value. To have the Cloud Quotas API validate the requests without submitting them, run the script with --validate-only.

  3. For estates with many projects, share bulk_qir_payload.csv with your quota approver or account team.

Clean up the environment

To remove the testbed and avoid ongoing charges, destroy the Terraform configuration:

terraform -chdir=terraform destroy \
  -var="project_id=${PROJECT_ID}" \
  -var="region=${REGION}" \
  -var="zone=${ZONE}"

Terraform leaves the enabled Google Cloud APIs in place, and quota preferences that you submitted remain on the project.