Module 33: Deployment to Google Kubernetes Engine (GKE)
Theoryโ
Figure: Enterprise agent container orchestration on Google Kubernetes Engine (GKE) with private VPC networking and multi-pod replica management.
When You Need Full Cluster Controlโ
In Module 32, you deployed an agent to Google Cloud Run โ a serverless container platform that scales down to zero and abstracts away cluster management. For stateless or bursty HTTP agents, Cloud Run or Vertex AI Agent Runtime are ideal starting points.
However, enterprise platform teams choose Google Kubernetes Engine (GKE) when workloads demand deeper infrastructure control:
- Custom Compute & Accelerators: Running co-located GPU/TPU inference sidecars, custom compute classes, or memory-intensive pods alongside your ADK agent.
- Private Zero-Trust Networking: Enforcing Kubernetes
NetworkPolicyrules, service meshes, internal VPC-only LoadBalancers for pod-to-pod A2A traffic, and custom Cloud NAT egress gateways. - Sidecar Architectures: Pairing agent containers with dedicated proxy sidecars (such as the Cloud SQL Auth Proxy for persistent session state or OpenTelemetry collectors).
- Unified Platform Standardization: Operating agents inside an organization's existing Kubernetes GitOps, Prometheus, and fleet governance ecosystem.
Cloud Run vs. GKE Autopilot: Architectural Trade-Offsโ
Google Kubernetes Engine (GKE) Autopilot manages the Kubernetes control plane, node provisioning, and security hardening while preserving the full Kubernetes API (Deployment, Service, HorizontalPodAutoscaler, PodDisruptionBudget, and Workload Identity).
| Criteria | Google Cloud Run | GKE Autopilot (--deployment-target gke) |
|---|---|---|
| Abstraction Level | High (Serverless container revisions) | Medium (Managed Kubernetes cluster & pods) |
| Scaling Mechanism | Revision concurrency + instance auto-scaling (including scale-to-zero) | Declarative HorizontalPodAutoscaler (HPA), VPA, and node auto-provisioning |
| Sizing Configuration | Imperative agents-cli deploy flags (--cpu, --memory, --concurrency) or Terraform | Declarative Terraform only (deployment/terraform/); CLI sizing flags are rejected |
| Networking | Public HTTPS URL with IAM auth (--no-allow-unauthenticated) or VPC egress | Private VPC + Cloud NAT + Internal LoadBalancer by default (kubectl port-forward for dev) |
| Persistent Sessions | Cloud SQL via Unix socket volume mount or Agent Platform Sessions | Cloud SQL via Auth Proxy sidecar container in the pod or Agent Platform Sessions |
| Rollback Mechanism | Cloud Run revision traffic shifting (gcloud run services update-traffic) | Kubernetes rollout history (kubectl rollout undo deployment/...) or GitOps |
Part 1: The Enterprise Golden Path โ GKE Autopilot with agents-cliโ
Figure: Multi-tier GKE cluster topology showing load balancer ingress, replica Agent Pods governed by HPA and PDB, private VPC services, and Workload Identity.
Hand-writing VPC subnets, Cloud NAT routers, Artifact Registry repositories, IAM bindings, and multi-object Kubernetes manifests from scratch is error-prone. agents-cli (google-agents-cli) codifies Google Cloud's production GKE Autopilot golden path into a repeatable scaffold-and-deploy workflow.
Whether you create a new GKE project or upgrade an existing prototype (support-ops-agent) in place, agents-cli generates the complete container and Terraform stack automatically:
export GOOGLE_CLOUD_PROJECT="your-project-id"
export DEPLOY_REGION="us-central1"
# Option A: Create a new GKE-targeted ADK project with GitHub Actions CI/CD
agents-cli scaffold create support-ops-gke \
--agent adk \
--deployment-target gke \
--cicd-runner github_actions \
--region "$DEPLOY_REGION" \
--agent-guidance-filename GEMINI.md
# Option B: Upgrade an existing prototype directory in place
# agents-cli scaffold enhance . --deployment-target gke --cicd-runner github_actions
What agents-cli Automates Under deployment/terraform/โ
When you select --deployment-target gke, agents-cli generates two Terraform layouts โ deployment/terraform/single-project/ (for single-project environments and agents-cli deploy) and deployment/terraform/cicd/ (for staging/production CI/CD pipelines):
- GKE Autopilot & Private Networking (
service.tf): Provisions a dedicated VPC, subnet, Cloud Router + Cloud NAT (so private Autopilot nodes can reach Vertex AI endpoints without public node IPs), Artifact Registry, and a GKE Autopilot cluster. - Keyless Workload Identity (
iam.tf&kubernetes_service_account_v1): Creates a least-privilege GCP runtime service account (app_sa) and binds it to the Kubernetes ServiceAccount viaroles/iam.workloadIdentityUser. Pods authenticate to Vertex AI, Cloud Trace, and Secret Manager automatically โ zero service account JSON keys are ever created or mounted. - Declarative Kubernetes Workloads & Autoscaling (
service.tf):kubernetes_deployment_v1: Runs your single-stageuv-builtDockerfile(uvicorn app.fast_api_app:appon port8080, exposing both/run_sseand/a2a/app), configured with startup, readiness, and liveness probes, resource requests/limits, and an optional Cloud SQL Auth Proxy sidecar when--session-type cloud_sqlis used.kubernetes_horizontal_pod_autoscaler_v2(HPA): Automatically scales pod replicas (default2to10replicas at70%CPU utilization).kubernetes_pod_disruption_budget_v1(PDB): EnforcesminAvailable: 1so GKE node maintenance never takes all agent pods offline simultaneously.kubernetes_service_v1: Exposes port8080via an Internal LoadBalancer (cloud.google.com/load-balancer-type: "Internal") by default for private intra-VPC and A2A traffic. During development, you tunnel from your laptop withkubectl port-forwardand test directly viaagents-cli run --url ... --mode a2aor--mode adk.
Critical
agents-cliRule for GKE Sizing: Unlike Cloud Run and Agent Runtime โ where you can pass--cpu,--memory,--concurrency,--min-instances,--max-instances, or--service-namedirectly onagents-cli deployโ those sizing and naming flags are rejected on GKE. Why? Because on GKE, pod resource requests/limits, service names, andHorizontalPodAutoscalerbounds are owned declaratively indeployment/terraform/single-project/service.tf(andcicd/service.tf). Rejecting imperative CLI sizing flags prevents ad-hoc deployments from drifting out of sync with Terraform and HPA rules.
When deploying gemini-3.8-flash to a regional GKE cluster (such as DEPLOY_REGION=us-central1), pass GOOGLE_GENAI_USE_ENTERPRISE=1 and GOOGLE_CLOUD_LOCATION=global via --env-vars so the container routes model inference to the global Vertex AI endpoint:
agents-cli deploy \
--project "$GOOGLE_CLOUD_PROJECT" \
--region "$DEPLOY_REGION" \
--env-vars "GOOGLE_GENAI_USE_ENTERPRISE=1,GOOGLE_CLOUD_LOCATION=global" \
--no-confirm-project
Part 2: Under the Hood โ Raw Kubernetes Primitives (Dockerfile, deployment.yaml & kubectl)โ
While agents-cli automates cluster creation, Terraform state, and FastAPI/A2A packaging, understanding the raw Kubernetes primitives underneath makes you far more effective when debugging pod rollouts or customizing cluster topologies.
When deploying an ADK agent manually without agents-cli, five core steps occur beneath the surface:
- Containerize with Headless
adk api_server: Package your agent subdirectory inside/app/<agent_name>/(containing__init__.pyandagent.py) and runadk api_server /app --host 0.0.0.0 --port 8080โ neveradk web, which exposes debug traces and UI overhead in production. - Build & Push to Artifact Registry: Submit the container build via Cloud Build (
gcloud builds submit) to a regional Docker repository (${DEPLOY_REGION}-docker.pkg.dev/...). - Provision GKE Autopilot: Create a cluster (
gcloud container clusters create-auto) and fetchkubeconfigcredentials (get-credentials). - Author Kubernetes Manifests (
deployment.yaml):- A
Deploymentdefines execution: which container image to pull, how many pod replicas to run, and container environment variables (GOOGLE_GENAI_USE_ENTERPRISE="1",GOOGLE_CLOUD_LOCATION="global"). - A
Servicedefines network access: a stable IP address and load balancer routing traffic to ephemeral pod IPs selected by label (app: support-agent).
- A
- Apply & Operate with
kubectl: Apply manifests viakubectl apply -f, inspect logs viakubectl logs, and recover from bad image pushes instantaneously viakubectl rollout undo deployment/<name>.
When containerizing an ADK agent named 'support_agent' for GKE using 'adk api_server /app --port 8080', how must the agent files be structured inside '/app' so that HTTP requests to '/apps/support_agent/...' succeed instead of returning 404 Not Found?
Key Takeawaysโ
agents-cliGolden Path (--deployment-target gke):agents-cli scaffold create/enhanceautomates private VPC + Cloud NAT networking, GKE Autopilot cluster provisioning, Artifact Registry, keyless Workload Identity (app_sa), HorizontalPodAutoscaler (HPA), and PodDisruptionBudget (PDB) viadeployment/terraform/.- Declarative GKE Sizing Rule: Runtime sizing flags (
--cpu,--memory,--concurrency,--min-instances,--max-instances) onagents-cli deployare rejected for GKE because pod resource requests/limits and HPA scaling live declaratively indeployment/terraform/. - Dual-Protocol Verification: Every
agents-cliPython container servesuvicorn app.fast_api_app:appon port8080, allowing you to test live GKE pods over both A2A (--mode a2a) and ADK SSE (--mode adk --app-name app) viaagents-cli run --url. Deploymentvs.ServiceObjects: Under the hood, a KubernetesDeploymentmanages pod execution, replicas, and rolling updates (kubectl rollout undo), while aServiceprovides a stable network endpoint routing traffic across ephemeral pod IPs.adk api_servervs.adk webin Production: Always serve headless API containers (uvicorn app.fast_api_app:appinagents-clioradk api_serverin raw Dockerfiles) rather thanadk web, which exposes internal instructions, tool schemas, and reasoning traces.