Lab 33: Deploying Enterprise Agents to GKE Autopilot Challenge
Goalโ
In this two-part lab, you will master deploying ADK 2.0 agents to Google Kubernetes Engine (GKE) Autopilot from both the enterprise platform engineering perspective and the low-level Kubernetes perspective:
- Part 1 โ Accelerated GKE Autopilot Deployment with
agents-cli(Primary Golden Path): Scaffoldsupport-ops-gkewith--deployment-target gke, load the canonical Parts 6โ7 statefulsupport_ops_agent, inspect the generated Terraform modules (GKE Autopilot, Workload Identityapp_sa, andHorizontalPodAutoscaler), deploy withagents-cli deploy, test the live endpoint over both A2A and ADK SSE viaagents-cli run, and practice Kubernetes rollbacks. - Part 2 โ Under the Hood: Manual
Dockerfile,deployment.yaml&kubectlDeep Dive: Build a raw container image runningadk api_server /appand author KubernetesDeploymentandServicemanifests manually to understand exactly whatagents-cliorchestrates behind the scenes.
Prerequisitesโ
- A Google Cloud Project with billing enabled.
- Google Cloud CLI (
gcloud) installed and authenticated (gcloud auth loginandgcloud auth application-default login). kubectlinstalled (gcloud components install kubectl) andterraforminstalled (>= 1.5).uvandgoogle-agents-cliinstalled (uv tool install google-agents-cli).
Environment setup:
- 1-Click Launch (Browser): Open in GitHub CodespacesOpen in Google Cloud Shell
- Local machine: If you're continuing the course in sequence,
cdinto theadk-trainingproject you created in Module 2 and skip the block below -- your environment and dependencies already carry forward. If you're starting fresh at this module, create that project first:uv init adk-training --python 3.10 && cd adk-training
uv add "google-adk>=2.1.0" python-dotenv- DevContainer / Codespaces (Alternative): If you opened this repository in a DevContainer or GitHub Codespaces, Python 3.11,
uv,gcloud, and all core ADK dependencies are pre-installed in your container environment.
Prepare Your Cloud Environmentโ
Export your project ID and DEPLOY_REGION=us-central1 for regional GKE and Artifact Registry infrastructure, and enable the required Google Cloud APIs. Throughout both parts of this lab, we separate the cluster's regional location (us-central1) from the model inference endpoint (GOOGLE_CLOUD_LOCATION=global) required by gemini-3.8-flash.
export GOOGLE_CLOUD_PROJECT=YOUR_PROJECT_ID
export DEPLOY_REGION=us-central1
gcloud config set project "$GOOGLE_CLOUD_PROJECT"
gcloud services enable \
aiplatform.googleapis.com \
container.googleapis.com \
compute.googleapis.com \
artifactregistry.googleapis.com \
cloudbuild.googleapis.com \
iam.googleapis.com \
secretmanager.googleapis.com
Part 1: Accelerated GKE Autopilot Deployment with agents-cli (Recommended)โ
Step 1.1: Scaffold support-ops-gke with the Stateful support_ops_agentโ
-
Scaffold a GKE-targeted ADK project and load the canonical Part 6 agent: Run
agents-cli scaffold createwith--deployment-target gke(remember: do notmkdir support-ops-gkebeforehand โagents-clicreates the directory), download the statefulsupport_ops_agent(lookup_ticket,check_sla_policy,escalate_ticket, andApp(root_agent=root_agent, name="app")), and install dependencies:export GOOGLE_CLOUD_PROJECT=YOUR_PROJECT_ID
export DEPLOY_REGION=us-central1
agents-cli scaffold create support-ops-gke \
--agent adk \
--deployment-target gke \
--cicd-runner github_actions \
--region "$DEPLOY_REGION" \
--agent-guidance-filename GEMINI.md
curl -fsSL https://mauripsale.github.io/doc-adk-training/samples/part6/agent.py -o support-ops-gke/app/agent.py
cd support-ops-gke
agents-cli install(Tip: If you already have an existing
support-ops-agentprototype directory from an earlier Part 6 module and want to add GKE support in place, runagents-cli scaffold enhance . --deployment-target gke --cicd-runner github_actionsfrom inside that project directory.) -
Verify
app/agent.pyAlignment withagents-cli-manifest.yaml: Openapp/agent.pyand confirm three essential contracts:MODEL = "gemini-3.8-flash"root_agent = Agent(name="support_ops_agent", ...)app = App(root_agent=root_agent, name="app")matchingagent_directory: "app"inagents-cli-manifest.yaml.
Step 1.2: Inspect the Generated GKE Autopilot Terraform & Workload Identityโ
Before deploying, inspect the infrastructure-as-code files that agents-cli generated under deployment/terraform/:
ls -la deployment/terraform/single-project/
Examine two key files in deployment/terraform/single-project/:
iam.tf(Workload Identity): Inspect howapp_sa(the runtime GCP Service Account) is granted Vertex AI / telemetry permissions and bound to the Kubernetes ServiceAccount viaroles/iam.workloadIdentityUser. Pods authenticate asapp_sawith zero exported JSON keys.service.tf(Cluster, Pod Sizing, HPA & Internal LB): Locate the private VPC/Cloud NAT resources, GKE Autopilot cluster,kubernetes_deployment_v1,kubernetes_horizontal_pod_autoscaler_v2(2โ10 replicas at 70% CPU),kubernetes_pod_disruption_budget_v1(minAvailable: 1), andkubernetes_service_v1(annotated as an internal LoadBalancer on port8080).
Why GKE Rejects CLI Sizing Flags: Try checking
agents-cli deploy --help. Passing--cpu,--memory, or--concurrencytoagents-cli deployon a GKE project fails intentionally โ pod resource requests/limits and HorizontalPodAutoscaler rules are managed declaratively indeployment/terraform/single-project/service.tf(anddeployment/terraform/cicd/service.tf) so imperative CLI deploys never conflict with HPA or Terraform state.
Step 1.3: Deploy to GKE Autopilot via agents-cliโ
Preview the deployment plan first with --dry-run, then run agents-cli deploy (note that provisioning a new GKE Autopilot cluster on the first run takes roughly 8โ12 minutes):
# Preview what agents-cli will build and apply
agents-cli deploy \
--project "$GOOGLE_CLOUD_PROJECT" \
--region "$DEPLOY_REGION" \
--env-vars "GOOGLE_GENAI_USE_ENTERPRISE=1,GOOGLE_CLOUD_LOCATION=global" \
--no-confirm-project \
--dry-run
# Execute the build, push, and GKE Autopilot deployment
agents-cli deploy \
--project "$GOOGLE_CLOUD_PROJECT" \
--region "$DEPLOY_REGION" \
--env-vars "GOOGLE_GENAI_USE_ENTERPRISE=1,GOOGLE_CLOUD_LOCATION=global" \
--no-confirm-project
Step 1.4: Test the Live GKE Endpoint Over A2A and ADK SSEโ
By default, agents-cli configures the GKE Service as an Internal LoadBalancer inside your private VPC so pod-to-pod A2A traffic is never exposed to the public internet. Forward port 8080 from the GKE service to your laptop (or point GKE_SERVICE_URL at your ingress endpoint), then verify both protocols with agents-cli run:
# Fetch cluster credentials if not already configured in kubeconfig, then port-forward
kubectl get svc -A
kubectl port-forward svc/support-ops-gke 8080:8080 -n support-ops-gke &
PF_PID=$!
sleep 2
export GKE_SERVICE_URL="http://127.0.0.1:8080"
# 1. Test over the built-in Agent-to-Agent (A2A) JSON-RPC protocol
agents-cli run "Investigate ticket TCK-1042 and escalate if P1." --url "$GKE_SERVICE_URL" --mode a2a
# 2. Test over the native ADK SSE streaming surface (/run_sse)
agents-cli run "Check SLA for enterprise tier." --url "$GKE_SERVICE_URL" --mode adk --app-name app
# Stop the background port-forward when finished
kill "$PF_PID"
Observe how the same GKE pod seamlessly serves A2A requests (discovering the agent card automatically and executing lookup_ticket โ check_sla_policy โ escalate_ticket for P1 ticket TCK-1042) as well as native ADK /run_sse sessions!
Step 1.5: Operational Inspection & Rollback Commandsโ
In production, platform engineers inspect active deployments with agents-cli and recover instantaneously from faulty container releases using Kubernetes' native ReplicaSet history:
# List deployments discovered in the project/region
agents-cli deploy --list --project "$GOOGLE_CLOUD_PROJECT" --region "$DEPLOY_REGION"
# Inspect pod status and Deployment revision history
kubectl get pods -n support-ops-gke
kubectl rollout history deployment/support-ops-gke -n support-ops-gke
# Roll back immediately to the previous healthy ReplicaSet revision (and monitor completion)
kubectl rollout undo deployment/support-ops-gke -n support-ops-gke
kubectl rollout status deployment/support-ops-gke -n support-ops-gke
Return to your parent workspace directory before starting Part 2:
cd ..
Part 2: Under the Hood โ Manual Dockerfile, deployment.yaml & kubectl Deep Diveโ
Now that you have experienced the automated agents-cli golden path, let's peel back the curtain and manually assemble a raw Dockerfile (adk api_server) and deployment.yaml (Deployment + Service) for the multi-agent Customer Support router from Module 32.
Step 2.1: Create the Multi-Agent Customer Support Packageโ
-
Create the
gke_support_agent/support_agentdirectory structure: Placing the Python package insidesupport_agent/ensures that whenadk api_server /appstarts in the container, it discovers thesupport_agentfolder name and mounts routes at/apps/support_agent/...:mkdir -p gke_support_agent/support_agent
cd gke_support_agent -
Create
support_agent/__init__.py:from . import agent -
Complete the Challenge Skeleton in
support_agent/agent.py: Fill in the three# TODOblocks below usinggemini-3.8-flashto definebilling_agent,tech_support_agent, and the delegatingroot_agent:from google.adk.agents import Agent
# TODO: 1. Define `billing_agent` (name="billing_agent", model="gemini-3.8-flash")
# to politely handle questions about billing, invoices, and payments.
billing_agent = None
# TODO: 2. Define `tech_support_agent` (name="tech_support_agent", model="gemini-3.8-flash")
# to troubleshoot technical issues and provide clear solutions.
tech_support_agent = None
# TODO: 3. Define `root_agent` (name="router_agent", model="gemini-3.8-flash")
# that delegates billing questions to `billing_agent` and technical problems
# to `tech_support_agent` via `sub_agents=[billing_agent, tech_support_agent]`.
root_agent = None
Step 2.2: Containerize the Agent Manuallyโ
-
Create
requirements.txt:echo "google-adk" > requirements.txt -
Create
Dockerfileingke_support_agent/: Notice howsupport_agent/is copied into/app/support_agent/while/appis passed asAGENTS_DIRtoadk api_server. Copying files flat into/appwould mount routes at/apps/app/...instead of/apps/support_agent/...!FROM python:3.11-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY support_agent/ /app/support_agent/
EXPOSE 8080
CMD ["adk", "api_server", "/app", "--host", "0.0.0.0", "--port", "8080"]
Step 2.3: Build and Push the Image to Artifact Registryโ
gcloud artifacts repositories create adk-images \
--repository-format=docker \
--location="$DEPLOY_REGION"
gcloud builds submit \
--tag "${DEPLOY_REGION}-docker.pkg.dev/${GOOGLE_CLOUD_PROJECT}/adk-images/support-agent:v1"
Step 2.4: Create deployment.yaml and Apply with kubectlโ
-
Create or connect to a GKE Autopilot cluster: (If your Autopilot cluster from Part 1 is still active, you can deploy into a separate namespace on it, or create a standalone
adk-clusteras shown below.)gcloud container clusters create-auto adk-cluster \
--location="$DEPLOY_REGION"
gcloud container clusters get-credentials adk-cluster \
--location="$DEPLOY_REGION" -
Author
deployment.yaml: Notice howGOOGLE_GENAI_USE_ENTERPRISE="1"andGOOGLE_CLOUD_LOCATION="global"routegemini-3.8-flashcalls to the global Vertex AI endpoint, and Kubernetesmetadata.namevalues use hyphens (support-agent-deployment) to satisfy RFC 1123 naming rules:apiVersion: apps/v1
kind: Deployment
metadata:
name: support-agent-deployment
spec:
replicas: 1
selector:
matchLabels:
app: support-agent
template:
metadata:
labels:
app: support-agent
spec:
containers:
- name: support-agent
image: ${DEPLOY_REGION}-docker.pkg.dev/${GOOGLE_CLOUD_PROJECT}/adk-images/support-agent:v1
ports:
- containerPort: 8080
env:
- name: GOOGLE_GENAI_USE_ENTERPRISE
value: "1"
- name: GOOGLE_CLOUD_PROJECT
value: "${GOOGLE_CLOUD_PROJECT}"
- name: GOOGLE_CLOUD_LOCATION
value: "global"
---
apiVersion: v1
kind: Service
metadata:
name: support-agent-service
spec:
type: LoadBalancer
selector:
app: support-agent
ports:
- protocol: TCP
port: 80
targetPort: 8080 -
Substitute environment variables and apply to the cluster:
envsubst < deployment.yaml | kubectl apply -f -
Step 2.5: Verify Your Raw Kubernetes Deploymentโ
-
Wait for the LoadBalancer
EXTERNAL-IP:kubectl get service support-agent-service --watchOnce assigned, press
Ctrl+Cand store the IP:export EXTERNAL_IP=$(kubectl get service support-agent-service -o jsonpath='{.status.loadBalancer.ingress[0].ip}') -
Test Session Creation & SSE Routing via
curl:# 1. Create session s1 for user u1 on support_agent
curl -X POST "http://${EXTERNAL_IP}/apps/support_agent/users/u1/sessions/s1" \
-H "Content-Type: application/json" \
-d '{}'
# 2. Send a billing inquiry via SSE streaming (delegates to billing_agent)
curl -X POST "http://${EXTERNAL_IP}/run_sse" \
-H "Content-Type: application/json" \
-d '{
"app_name": "support_agent",
"user_id": "u1",
"session_id": "s1",
"new_message": {
"role": "user",
"parts": [{"text": "I have a question about my invoice."}]
}
}'Send a follow-up request with
"My app keeps crashing."to confirm delegation totech_support_agent.
Cleanup (Important!)โ
GKE Autopilot clusters and LoadBalancers incur ongoing charges if left running. Tear down both environments when finished:
# 1. Tear down Part 1 Terraform-managed GKE infrastructure (if deployed)
cd ../support-ops-gke/deployment/terraform/single-project
terraform destroy -auto-approve
cd ../../../..
# 2. Delete Part 2 manual GKE cluster and Artifact Registry repository
gcloud container clusters delete adk-cluster \
--location="$DEPLOY_REGION" \
--async
gcloud artifacts repositories delete adk-images \
--location="$DEPLOY_REGION" \
--async
# 3. Remove local lab directories
rm -rf support-ops-gke gke_support_agent
Self-Reflection Questionsโ
- Why does
agents-cli deployreject--cpu,--memory, and--concurrencyflags when--deployment-target gkeis configured, whereas Cloud Run and Agent Runtime accept them? - How does GKE Workload Identity (
app_sainiam.tf) eliminate the security risks of static service account JSON keys? - In Part 2's
deployment.yaml, what is the distinct role of theDeploymentobject versus theServiceobject, and why isadk api_serverused in theDockerfileinstead ofadk web?
๐ Reference Solution Vaultโ
Official Solution Vault โ Module 33
Locked Challenge โ Active Pedagogical Socratic Gate