Welcome to the final lab in the "Accelerate with AI" series! In this lab, you'll complete the prototype-to-production journey by taking a working ADK agent and deploying it as a scalable, robust application on Google Cloud Run with GPU support.
By the end of this lab, you will:
- Understand how to containerize ADK agents using Docker
- Deploy containerized agents to Cloud Run with GPU acceleration
- Manage production configurations and environment variables
- Test and monitor live applications in production
- Apply load testing to validate performance and scalability
You'll deploy a Production Gemma Agent with conversational capabilities:
Gemma Agent (GPU-Accelerated):
- General conversations and Q&A
- Educational explanations
- Creative writing assistance
- GPU-accelerated inference for fast responses
- Production-ready deployment on Cloud Run
- Google Cloud Project with billing enabled
- Google Cloud SDK installed and configured
- Docker installed (optional, for local testing)
- Basic understanding of containers and cloud deployment
Let's first explore the agent we'll be deploying:
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β User Request β -> β ADK Agent β -> β Gemma Backend β
β β β (Cloud Run) β β (Cloud Run+GPU) β
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β
v
βββββββββββββββββββ
β FastAPI Server β
β Health Checks β
β Load Testing β
βββββββββββββββββββ
Ollama Backend (separate deployment):
ollama-backend/Dockerfile: Container configuration for Gemma model backend
ADK Agent (separate deployment):
adk-agent/production_agent/agent.py: Production Gemma agent with conversational capabilitiesadk-agent/server.py: FastAPI server with health checks and feedback endpointsadk-agent/Dockerfile: Container configuration for Cloud Run deploymentadk-agent/elasticity_test.py: Locust-based load testing script
Before deploying to production, let's test the agent locally:
# Navigate to the lab directory
cd accelerate-ai-lab3-complete/adk-agent
# Create and configure environment file
cat > .env << EOF
GOOGLE_CLOUD_PROJECT=your-project-id
GOOGLE_CLOUD_LOCATION=europe-west1
GEMMA_MODEL_NAME=gemma3:4b
OLLAMA_API_BASE=https://ollama-gemma-795845071313.europe-west1.run.app
EOF
# Install dependencies
uv sync# Start the development server
uv run python server.pyThe agent will be available at http://localhost:8080. You can:
- Visit the web interface at
http://localhost:8080 - View API documentation at
http://localhost:8080/docs - Test the health endpoint at
http://localhost:8080/health
Try these sample interactions:
With Gemma Agent (Conversational):
- "Tell me about artificial intelligence"
- "What are some creative writing tips?"
- "Explain how photosynthesis works"
- "Can you help me brainstorm ideas for a blog post?"
- "What's the difference between machine learning and deep learning?"
Understanding the Dockerfile is crucial for production deployment:
# Use Python 3.13 slim base image for efficiency
FROM python:3.13-slim
# Add uv package manager for fast dependency resolution
COPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uv
# Install system dependencies
RUN apt-get update && apt-get install -y curl && rm -rf /var/lib/apt/lists/*
# Set working directory and copy files
WORKDIR /app
COPY . .
# Install Python dependencies using uv
RUN uv sync --frozen
# Expose port and start the application
EXPOSE 8080
CMD ["uv", "run", "uvicorn", "server:app", "--host", "0.0.0.0", "--port", "8080"]Key Production Considerations:
- Slim base image: Reduces attack surface and image size
- Package manager:
uvprovides faster dependency resolution - Frozen dependencies: Ensures reproducible builds
- Health checks: Built-in endpoints for monitoring
Now let's deploy your agent to Cloud Run with GPU acceleration:
# Set your project ID
export PROJECT_ID="your-project-id"
gcloud config set project $PROJECT_ID
# Set the region (choose one with GPU availability)
export REGION="europe-west1"
gcloud config set run/region $REGION
# Enable required APIs
gcloud services enable run.googleapis.com \
cloudbuild.googleapis.com \
aiplatform.googleapis.com# Deploy with GPU support
gcloud run deploy production-adk-agent \
--source . \
--region $REGION \
--allow-unauthenticated \
--memory 4Gi \
--cpu 2 \
--gpu 1 \
--gpu-type nvidia-l4 \
--max-instances 3 \
--min-instances 1 \
--concurrency 10 \
--timeout 300 \
--set-env-vars GOOGLE_CLOUD_PROJECT=$PROJECT_ID \
--set-env-vars GOOGLE_CLOUD_LOCATION=$REGION \
--set-env-vars GEMMA_MODEL_NAME=gemma3:4b \
--set-env-vars OLLAMA_API_BASE=https://ollama-gemma-795845071313.europe-west1.run.app \
--no-cpu-throttlingDeployment Configuration Explained:
- GPU: NVIDIA L4 GPU for AI model acceleration
- Memory/CPU: Sufficient resources for AI workloads
- Scaling: Auto-scaling between 1-3 instances
- Concurrency: Handle up to 10 concurrent requests per instance
- Environment Variables: Production configuration
# Get the deployed service URL
export SERVICE_URL=$(gcloud run services describe production-adk-agent \
--region=$REGION \
--format='value(status.url)')
echo "π Agent deployed at: $SERVICE_URL"# Test health endpoint
curl $SERVICE_URL/health
# Test the agent via proxy (for authenticated testing)
gcloud run services proxy production-adk-agent --port=8080With the proxy running, visit:
- Web interface:
http://localhost:8080 - API docs:
http://localhost:8080/docs
Try both agents' capabilities:
Gemma Agent (Conversational):
- "What's the difference between machine learning and deep learning?"
- "Can you help me brainstorm ideas for a blog post?"
- "Explain quantum computing in simple terms"
- "Tell me about renewable energy benefits"
Elasticity testing ensures your agent can handle production traffic:
# Create results directory
mkdir -p .results
# Run comprehensive elasticity test
locust -f elasticity_test.py \
-H $SERVICE_URL \
--headless \
-t 60s \
-u 20 \
-r 2 Elasticity Test Configuration:
- Duration: 60 seconds
- Users: 20 concurrent users
- Spawn Rate: 2 users per second
- Scenarios: Gemma conversations, health checks, performance validation
Key Metrics to Monitor:
- Response Time: Should be under 10 seconds for complex queries
- Throughput: Requests per second handled
- Error Rate: Should be minimal (< 1%)
- GPU Utilization: Monitor in Cloud Console
# For production deployments, use Secret Manager
gcloud secrets create production-config --data-file=.env
# Reference secrets in deployment
gcloud run deploy production-adk-agent \
--set-env-vars GOOGLE_CLOUD_PROJECT=$PROJECT_ID \
--set-secrets /app/.env=production-config:latest- Cloud Logging: Automatic logging of all agent interactions
- Cloud Monitoring: Set up alerts for error rates and latency
- Cloud Trace: Monitor request performance and bottlenecks
# Update scaling parameters
gcloud run services update production-adk-agent \
--min-instances 2 \
--max-instances 10 \
--concurrency 5- Custom Business Domain: Modify the agent to specialize in your industry
- Multi-Model Integration: Add different models for different tasks
- Caching Layer: Implement Redis for frequently requested analyses
- A/B Testing: Deploy multiple versions and compare performance
- Navigate to Cloud Run in the Google Cloud Console
- Select your
production-adk-agentservice - Monitor:
- Metrics: CPU, Memory, GPU utilization
- Logs: Agent interactions and errors
- Requests: Traffic patterns and response times
# Create alerting policy for high error rates
gcloud alpha monitoring policies create \
--policy-from-file=monitoring-policy.yaml- Containerization: Docker provides consistent deployment environments
- GPU Acceleration: NVIDIA L4 GPUs significantly improve AI model performance
- Auto-scaling: Cloud Run automatically scales based on demand
- Production Monitoring: Comprehensive observability is essential
- Load Testing: Validate performance before production traffic
- Cold Starts: Use min-instances to reduce latency
- Memory Errors: Increase memory allocation or optimize agent code
- GPU Unavailability: Check regional GPU quotas and availability
- Authentication Errors: Verify service account permissions
# Check service status
gcloud run services describe production-adk-agent --region=$REGION
# View logs
gcloud logs read "resource.type=cloud_run_revision" --limit=50
# Test locally with production environment
uv run python server.pyYou've successfully completed the prototype-to-production journey! Your ADK agent is now:
- β Containerized and production-ready
- β Deployed on Cloud Run with GPU acceleration
- β Scalable and monitored
- β Load tested and validated
Your agent can now handle real business intelligence workloads and scale automatically based on demand.
- Explore advanced ADK features and custom tools
- Implement CI/CD pipelines for automated deployments
- Add more sophisticated business intelligence capabilities
- Consider multi-region deployments for global availability
Total Lab Time: ~60 minutes
Questions? Check the troubleshooting section or review the Cloud Run documentation for additional guidance.