Generation-aware storage provisioning for GKE ComputeClass¶
Fourth-generation (Gen4) Compute Engine machine series, such as c4 and n4,
require Google Cloud Hyperdisk storage volumes such as hyperdisk-balanced and
cannot attach legacy Persistent Disks. In contrast, second-generation (Gen2)
machine series, such as n2 and c2, default to Persistent Disk such as
pd-balanced, and Google Kubernetes Engine (GKE) supply admission webhooks
reject Hyperdisk boot disks on Gen2 nodes. When a cluster falls back across
hardware generations during regional capacity stockouts, stateful workloads
stall in ContainerCreating unless compute selection and storage provisioning
coordinate across generations.
This project provides a reference architecture, a Terraform testbed, an Agent Skill for generating and validating generation-aware GKE manifests, and a replicated Apache Kafka demo workload with live performance tuning and Day-2 cross-generation storage rebalancing.
Architecture¶
The solution coordinates compute priority ladders, late-binding dynamic storage, declarative volume tuning, and Container Storage Interface (CSI) snapshot rebalancing across GKE Autopilot and GKE Standard clusters with Node Auto-Provisioning (NAP) enabled.
flowchart TB
subgraph AgentSkill ["Agent Skill (.agents/skills/generation-aware-storage-ccc)"]
Discovery["Cluster and Compute Engine catalog discovery"]
Validator["Catalog sizing check and server-side dry-run"]
end
subgraph ControlPlane ["GKE scheduling and storage policy"]
CCC["ComputeClass (c4 -> n4 -> n2 with Gen4 reservation affinity)"]
SC["Dynamic StorageClass (WaitForFirstConsumer + topology)"]
VAC["VolumeAttributesClass (live Hyperdisk IOPS and throughput)"]
end
subgraph PrimaryTier ["Preferred Gen4 tier (reserved C4 capacity)"]
C4Node["c4-standard-4 node (hyperdisk-balanced boot disk)"]
Broker0["kafka-cluster-0"]
HD0["hyperdisk-balanced PVC (tuned to 6000 IOPS)"]
end
subgraph FallbackTier ["Fallback Gen2 tier (on-demand N2 during stockout)"]
N2Node["n2-standard-4 node (pd-balanced boot disk)"]
Broker1["kafka-cluster-1"]
PD1["pd-balanced PVC"]
end
subgraph Day2 ["Day-2 capacity recovery"]
Watcher["rebalance_capacity_watcher.sh"]
Snap["CSI VolumeSnapshot -> new hyperdisk-balanced PVC on C4"]
end
Discovery --> Validator
Validator --> CCC
Validator --> SC
Validator --> VAC
CCC --> C4Node
CCC --> N2Node
SC --> HD0
SC --> PD1
VAC --> HD0
Broker0 --> C4Node
Broker0 --> HD0
Broker1 --> N2Node
Broker1 --> PD1
PD1 --> Watcher
Watcher --> Snap
Snap --> C4Node
Components¶
- Terraform testbed (
terraform/): Provisions an isolated Virtual Private Cloud (VPC) network and subnetwork with Private Google Access enabled, a Cloud Router and Cloud Network Address Translation (NAT) gateway for private-node outbound egress, a GKE Autopilot cluster with private nodes in theREGULARrelease channel, and a single-instancec4-standard-4Compute Engine reservation (specific_reservation_required = false) to trigger a deterministic capacity stockout when scaling beyond one broker. - Agent Skill (
.agents/skills/generation-aware-storage-ccc/): Discovers the active GKE cluster operating mode and live Compute Engine machine-type and reservation catalogs, interviews you for workload requirements, synthesizes a customComputeClass, late-bindingStorageClass, andVolumeAttributesClass(VAC), verifies catalog sizing and reservation parity, runs server-side dry-runs, and applies the manifests after approval. - Stateful demo workload and Day-2 automation (
demo/): Includes a replicated Apache Kafka KRaftStatefulSet(kafka-cluster.yaml), an In-Sync Replicas (ISR) and sequence-gap verification helper (kafka_data_continuity.sh), and a Day-2 CSIVolumeSnapshotrebalancer (rebalance_capacity_watcher.sh) that promotes stranded Gen2 brokers back to Gen4 Hyperdisk volumes when C4 capacity returns.
Requirements¶
To deploy the testbed, run the Agent Skill, and execute the Kafka walkthrough, you need:
- A Google Cloud project with billing enabled and regional virtual CPU (vCPU)
quota for
C4,N4, andN2machine families in a target region that supports all three families, such asus-central1. - An account granted the following Identity and Access Management (IAM) roles on
the project:
- Service Usage Admin (
roles/serviceusage.serviceUsageAdmin) - Kubernetes Engine Admin (
roles/container.admin) - Compute Network Admin (
roles/compute.networkAdmin) - Compute Instance Admin (v1) (
roles/compute.instanceAdmin.v1) - Compute Storage Admin (
roles/compute.storageAdmin) - Service Account User (
roles/iam.serviceAccountUser)
- Service Usage Admin (
- The
Google Cloud command-line interface (CLI)
(
gcloud480.0.0 or later),kubectl(1.30 or later), GKEkubectlauth plugin (gke-gcloud-auth-plugin),jq, and Terraform installed. - An AI coding agent CLI that supports the Agent Skills specification, such as Gemini CLI or Antigravity CLI.
Prepare the environment¶
-
Set your project and region environment variables and authenticate the
gcloudCLI: -
Clone the repository using sparse checkout and change to the project directory:
Deploy the testbed with Terraform¶
If you already have a GKE cluster and want to generate manifests for it, skip to Generate, validate, and apply manifests with the Agent Skill.
To provision the GKE Autopilot cluster and single-instance c4-standard-4
reservation:
-
Initialize and apply the Terraform configuration from the project root. By default, Terraform places the C4 reservation in the first
UPzone of${REGION}(pass-var="reservation_zone=<ZONE>"to select another zone in the same region): -
Capture the provisioned cluster name, reservation name, and reservation zone, authenticate
kubectl, and verify that the cluster is clean and the C4 reservation showsIN_USE_COUNT=0out ofCOUNT=1:export CLUSTER_NAME=$(terraform -chdir=terraform output -raw cluster_name) export RES_NAME=$(terraform -chdir=terraform output -raw c4_reservation_name) export ZONE=$(terraform -chdir=terraform output -raw reservation_zone) gcloud container clusters get-credentials "${CLUSTER_NAME}" \ --region="${REGION}" \ --project="${PROJECT_ID}" kubectl config current-context gcloud compute reservations list \ --project="${PROJECT_ID}" \ --filter="name=${RES_NAME}"
Generate, validate, and apply manifests with the Agent Skill¶
Start your agent CLI from the projects/gke-crossgen-storage-aware-ccc
directory so it discovers the generation-aware-storage-ccc skill under
.agents/skills/. The skill writes generated manifests outside the repository
under /tmp/gke-crossgen-manifests/${CLUSTER_NAME}/.
-
Trigger read-only cluster discovery and the design interview:
Help design GKE infrastructure for my workloads with flexibility, efficiency, and capacity stockouts in mind.Verify that the skill detects
clusterMode: autopilotandsampleZone: us-central1-a, caches Compute Enginemachine-types.jsonandreservations.jsonunder/tmp/gke-crossgen-manifests/<cluster-name>/, and surfaces thec4-standard-4reservation (4 vCPU, 15 GiB,specificReservationRequired: false). -
Provide your answers to the Step 2 design interview:
1. Workload profile and fallback ladder: Option A (General Purpose / Balanced: c4 -> n4 -> n2), targeting 4-vCPU standard-tier nodes. Name the ComputeClass `general-crossgen-cc`. 2. Reservations: Option C (`AnyThenFail`) on the Gen4 priorities (`c4` and `n4`) only, leaving the Gen2 (`n2`) fallback priority on-demand (no reservation affinity) so it can scale up when the C4 reservation is exhausted. 3. Default status: No, do not set it as cluster or namespace default. 4. Storage performance (VolumeAttributesClass): Yes, create `hyperdisk-performance-vac` with `iops: "6000"` and `throughput: "250Mi"`, alongside `dynamic-sc`. 5. CMEK encryption: No. 6. Output directory: Accept the default (`/tmp/gke-crossgen-manifests/<cluster-name>/`).Verify that the skill queries
machine-types.json, setsminMemoryGb: 15onc4and16onn4andn2, omitsstorage.bootDiskTypeon Gen4 priorities for GKE Autopilot admission compliance, confirms resolved shapes (c4-standard-4,n4-standard-4, andn2-standard-4) and reservation parity against the live catalog, and passes server-side dry-run on all three manifests. -
Approve deployment of the validated manifests:
-
Confirm that the three cluster resources are active:
Run the Kafka failover, live IOPS tuning, and Day-2 rebalance walkthrough¶
Run all commands in this section from the demo/ directory:
Deploy Kafka on Gen4 compute and Hyperdisk¶
-
Apply the single-replica Kafka KRaft
StatefulSetand wait untilkafka-cluster-0reaches1/1 Running: -
Stop the watch (
Ctrl+C) and inspect the provisioned node, data disk, and reservation utilization:kubectl get nodes \ -L node.kubernetes.io/instance-type,cloud.google.com/machine-family,cloud.google.com/gke-boot-disk,topology.kubernetes.io/zone PV0=$(kubectl get pvc kafka-data-kafka-cluster-0 -o jsonpath='{.spec.volumeName}') gcloud compute disks describe "${PV0}" \ --zone="${ZONE}" \ --project="${PROJECT_ID}" \ --format="table(name,type.basename(),sizeGb,provisionedIops,provisionedThroughput)" gcloud compute reservations list \ --project="${PROJECT_ID}" \ --filter="name=${RES_NAME}"Confirm that
kafka-cluster-0runs onc4-standard-4with ahyperdisk-balancedboot disk,PV0is a 50 GiBhyperdisk-balanceddata disk, and the C4 reservation reportsIN_USE_COUNT=1out ofCOUNT=1.
Tune Hyperdisk IOPS without pod restarts¶
-
Patch
kafka-data-kafka-cluster-0to bindhyperdisk-performance-vac: -
Wait approximately 15 to 30 seconds and verify that Input/Output Operations Per Second (IOPS) and throughput update in place with zero pod restarts:
kubectl get pvc kafka-data-kafka-cluster-0 \ -o jsonpath='{.spec.volumeAttributesClassName} -> {.status.currentVolumeAttributesClassName}{"\n"}' kubectl get pod kafka-cluster-0 \ -o jsonpath='restarts={.status.containerStatuses[0].restartCount}{"\n"}' PV0=$(kubectl get pvc kafka-data-kafka-cluster-0 -o jsonpath='{.spec.volumeName}') gcloud compute disks describe "${PV0}" \ --zone="${ZONE}" \ --project="${PROJECT_ID}" \ --format="table(name,type.basename(),sizeGb,provisionedIops,provisionedThroughput)"Confirm
hyperdisk-performance-vac -> hyperdisk-performance-vac,restarts=0,provisionedIops=6000, andprovisionedThroughput=250.
Simulate a C4 stockout and verify fallback to N2¶
-
Scale the Kafka
StatefulSetto 2 replicas and watchkafka-cluster-1schedule. Becausekafka-cluster-0consumes the only C4 reservation slot and Gen4 tiers enforcereservations.affinity: AnyThenFail, GKE falls back to the on-demand Gen2n2tier: -
Once
kafka-cluster-1is1/1 Running, stop the watch (Ctrl+C), inspect the new node and PersistentVolume (PV), and seed a replicated topic (crossgen-orders,replication-factor=2,min.insync.replicas=1) with 10 baseline messages:kubectl get nodes \ -L node.kubernetes.io/instance-type,cloud.google.com/machine-family,cloud.google.com/gke-boot-disk,topology.kubernetes.io/zone PV1=$(kubectl get pvc kafka-data-kafka-cluster-1 -o jsonpath='{.spec.volumeName}') PV1_ZONE=$(kubectl get pv "${PV1}" -o jsonpath='{.spec.csi.volumeHandle}' | cut -d/ -f4) gcloud compute disks describe "${PV1}" \ --zone="${PV1_ZONE}" \ --project="${PROJECT_ID}" \ --format="table(name,type.basename(),sizeGb)" bash ./kafka_data_continuity.sh initConfirm that
kafka-cluster-1runs onn2-standard-4with apd-balancedboot disk and 50 GiBpd-balanceddata disk, and thatcrossgen-ordersreportsReplicas: 0,1andIsr: 0,1across both generations.
Recover C4 capacity and run the Day-2 rebalancer¶
-
In a second terminal positioned in
demo/, start streaming liveacks=allmessages while leaving it running throughout the rebalance: -
In the first terminal, run a dry-run check to confirm the watcher detects
kafka-cluster-1onn2and defers while zero free C4 slots exist: -
Expand the C4 reservation from 1 to 2 instances so preferred C4 capacity becomes available in
${ZONE}: -
Run the automated Day-2 CSI
VolumeSnapshotrebalancer to snapshot the N2 disk, drain the idle N2 node, and promotekafka-cluster-1onto a C4 node withhyperdisk-balanced: -
Stop the producer in the second terminal (
Ctrl+C), then verify full ISR recovery, zero sequence gaps, and promoted C4 and Hyperdisk state in the first terminal:bash ./kafka_data_continuity.sh verify kubectl get nodes \ -L node.kubernetes.io/instance-type,cloud.google.com/machine-family,cloud.google.com/gke-boot-disk PV1_NEW=$(kubectl get pvc kafka-data-kafka-cluster-1 -o jsonpath='{.spec.volumeName}') gcloud compute disks describe "${PV1_NEW}" \ --zone="${ZONE}" \ --project="${PROJECT_ID}" \ --format="table(name,type.basename(),sizeGb,provisionedIops,provisionedThroughput)" gcloud compute reservations list \ --project="${PROJECT_ID}" \ --filter="name=${RES_NAME}"Confirm
0 gaps, 0 lost messages, twoc4-standard-4nodes backed byhyperdisk-balancedboot and data disks, zeron2nodes, andIN_USE_COUNT=2out ofCOUNT=2.
Clean up the environment¶
To avoid ongoing charges, return to the project root, delete the Kubernetes demo resources, and destroy the Terraform testbed:
cd ..
kubectl delete -f demo/kafka-cluster.yaml --ignore-not-found
kubectl delete pvc -l app=kafka --ignore-not-found
kubectl delete volumesnapshot kafka-data-kafka-cluster-1-rebalance-snap --ignore-not-found
kubectl delete volumesnapshotclass gke-pd-snapshot-class --ignore-not-found
kubectl delete volumeattributesclass hyperdisk-performance-vac --ignore-not-found
kubectl delete computeclass general-crossgen-cc --ignore-not-found
kubectl delete sc dynamic-sc --ignore-not-found
terraform -chdir=terraform destroy \
-var="project_id=${PROJECT_ID}" \
-var="region=${REGION}"