Skip to main content

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): Scaffold support-ops-gke with --deployment-target gke, load the canonical Parts 6โ€“7 stateful support_ops_agent, inspect the generated Terraform modules (GKE Autopilot, Workload Identity app_sa, and HorizontalPodAutoscaler), deploy with agents-cli deploy, test the live endpoint over both A2A and ADK SSE via agents-cli run, and practice Kubernetes rollbacks.
  • Part 2 โ€” Under the Hood: Manual Dockerfile, deployment.yaml & kubectl Deep Dive: Build a raw container image running adk api_server /app and author Kubernetes Deployment and Service manifests manually to understand exactly what agents-cli orchestrates behind the scenes.

Prerequisitesโ€‹

  • A Google Cloud Project with billing enabled.
  • Google Cloud CLI (gcloud) installed and authenticated (gcloud auth login and gcloud auth application-default login).
  • kubectl installed (gcloud components install kubectl) and terraform installed (>= 1.5).
  • uv and google-agents-cli installed (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, cd into the adk-training project 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

Step 1.1: Scaffold support-ops-gke with the Stateful support_ops_agentโ€‹

  1. Scaffold a GKE-targeted ADK project and load the canonical Part 6 agent: Run agents-cli scaffold create with --deployment-target gke (remember: do not mkdir support-ops-gke beforehand โ€” agents-cli creates the directory), download the stateful support_ops_agent (lookup_ticket, check_sla_policy, escalate_ticket, and App(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-agent prototype directory from an earlier Part 6 module and want to add GKE support in place, run agents-cli scaffold enhance . --deployment-target gke --cicd-runner github_actions from inside that project directory.)

  2. Verify app/agent.py Alignment with agents-cli-manifest.yaml: Open app/agent.py and confirm three essential contracts:

    • MODEL = "gemini-3.8-flash"
    • root_agent = Agent(name="support_ops_agent", ...)
    • app = App(root_agent=root_agent, name="app") matching agent_directory: "app" in agents-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 how app_sa (the runtime GCP Service Account) is granted Vertex AI / telemetry permissions and bound to the Kubernetes ServiceAccount via roles/iam.workloadIdentityUser. Pods authenticate as app_sa with 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), and kubernetes_service_v1 (annotated as an internal LoadBalancer on port 8080).

Why GKE Rejects CLI Sizing Flags: Try checking agents-cli deploy --help. Passing --cpu, --memory, or --concurrency to agents-cli deploy on a GKE project fails intentionally โ€” pod resource requests/limits and HorizontalPodAutoscaler rules are managed declaratively in deployment/terraform/single-project/service.tf (and deployment/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โ€‹

  1. Create the gke_support_agent/support_agent directory structure: Placing the Python package inside support_agent/ ensures that when adk api_server /app starts in the container, it discovers the support_agent folder name and mounts routes at /apps/support_agent/...:

    mkdir -p gke_support_agent/support_agent
    cd gke_support_agent
  2. Create support_agent/__init__.py:

    from . import agent
  3. Complete the Challenge Skeleton in support_agent/agent.py: Fill in the three # TODO blocks below using gemini-3.8-flash to define billing_agent, tech_support_agent, and the delegating root_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โ€‹

  1. Create requirements.txt:

    echo "google-adk" > requirements.txt
  2. Create Dockerfile in gke_support_agent/: Notice how support_agent/ is copied into /app/support_agent/ while /app is passed as AGENTS_DIR to adk api_server. Copying files flat into /app would 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โ€‹

  1. 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-cluster as shown below.)

    gcloud container clusters create-auto adk-cluster \
    --location="$DEPLOY_REGION"

    gcloud container clusters get-credentials adk-cluster \
    --location="$DEPLOY_REGION"
  2. Author deployment.yaml: Notice how GOOGLE_GENAI_USE_ENTERPRISE="1" and GOOGLE_CLOUD_LOCATION="global" route gemini-3.8-flash calls to the global Vertex AI endpoint, and Kubernetes metadata.name values 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
  3. Substitute environment variables and apply to the cluster:

    envsubst < deployment.yaml | kubectl apply -f -

Step 2.5: Verify Your Raw Kubernetes Deploymentโ€‹

  1. Wait for the LoadBalancer EXTERNAL-IP:

    kubectl get service support-agent-service --watch

    Once assigned, press Ctrl+C and store the IP:

    export EXTERNAL_IP=$(kubectl get service support-agent-service -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
  2. 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 to tech_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 deploy reject --cpu, --memory, and --concurrency flags when --deployment-target gke is configured, whereas Cloud Run and Agent Runtime accept them?
  • How does GKE Workload Identity (app_sa in iam.tf) eliminate the security risks of static service account JSON keys?
  • In Part 2's deployment.yaml, what is the distinct role of the Deployment object versus the Service object, and why is adk api_server used in the Dockerfile instead of adk web?

๐Ÿ” Reference Solution Vaultโ€‹

๐Ÿงช

33: Deploying to GKE Autopilot(Challenge Lab)

Part 7: Cloud Runtimes & Enterprise โ€ข Module 33