> ## Documentation Index
> Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Deploying to Cloud Run

> Guidelines for packaging and deploying ADK agents to Google Cloud Run, including API endpoints, containerization, Cloud Trace, authentication, and production operational best practices.

Your agent now exposes a small API surface for session management and running the agent:

* `POST /apps/{app_name}/users/{user_id}/sessions/{session_id}` — create a session
* `POST /run` — run the agent and receive the full response as JSON
* `POST /run_sse` — stream agent events via Server-Sent Events (SSE)

A typical session object looks like:

```text theme={null}
Session
app_name    support_agent
user_id     u_42
id          s_1001
```

You can run the same server locally during development and then deploy the identical runtime to Google Cloud so production behavior matches your local testing.

Cloud deployment choices

* Cloud Run — fully managed container platform with automatic scaling. Ideal for single agents and low-ops teams.
* Google Kubernetes Engine (GKE) — managed Kubernetes when you need more control and have a platform team.
* Agent Runtime on Agent Platform — a Google-managed runtime built specifically for agents, minimizing ops.

![A comparison diagram showing three cloud deployment options—Cloud Run (checked), GKE, and Agent Runtime—each depicted in a cloud with icons and short descriptions (Managed platform, Your cluster, Managed runtime). The graphic includes container/agent illustrations and small metrics like agent counts and operational notes.](https://mintcdn.com/kodekloud-c4ac6d9a/heceQKBf52UJgxP-/images/Google-ADK-20/Advanced-Tools/Deploying-to-Cloud-Run/cloud-run-gke-agent-runtime-comparison.jpg?fit=max\&auto=format\&n=heceQKBf52UJgxP-\&q=85\&s=a7869d65b7f200e52950dca9cc1a8b2d)

When to choose each

| Deployment Option | Best for | Recommendation |
| - | - | - |
| Cloud Run | Single agent, \~tens of requests/day, minimal ops | Use Cloud Run for the simplest managed deployment. See [Cloud Run docs](https://cloud.google.com/run). |
| GKE | Many agents or custom networking, platform teams | Use GKE if you need cluster-level control and custom orchestration. See [GKE docs](https://cloud.google.com/kubernetes-engine). |
| Agent Runtime | Large fleets, minimal ops, specialized agent features | Use when you want Google to manage runtime scaling and operational concerns. |

If you have one agent, \~50 requests/day, and limited ops experience, Cloud Run is typically the best fit. If you operate dozens of agents and have a platform team, consider GKE.

## Deploying with ADK to Cloud Run

ADK includes a deploy command for Python agents that builds and deploys a Cloud Run service from your agent directory. Provide the Google Cloud project, region, and service name. Use `--trace_to_cloud` to enable Cloud Trace so you can inspect production requests end-to-end.

Example ADK deployment:

```bash theme={null}
adk deploy cloud_run \
  --project=support-prod \
  --region=us-central1 \
  --service_name=support-agent \
  --trace_to_cloud \
  ./support_agent
```

Notes:

* `--service_name` sets the Cloud Run service name.
* `--trace_to_cloud` wires Cloud Trace into the deployed service for distributed tracing.
* If you need a private service (recommended for most production deployments), see the private deployment example below.

## Building your own container

If you need a custom base image, system dependencies, or plan to deploy to GKE/other platforms, build your own container. The container runs the same ADK API server used locally, ensuring consistent runtime behavior.

Minimal Dockerfile example:

```Dockerfile theme={null}
FROM python:3.11-slim

WORKDIR /app

# Install system deps (if any) and Python requirements
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

# Copy application/agent code
COPY . .

# Expose the port the ADK server will listen on (Cloud Run uses port 8080 by default)
EXPOSE 8080

# Start the ADK API server (adjust the command if your setup differs)
CMD ["adk", "server", "--host", "0.0.0.0", "--port", "8080"]
```

Recommendations:

* Keep image layers small and cache-friendly.
* Pin key package versions in `requirements.txt`.
* If you need system packages, install them before Python dependencies to leverage Docker layer caching.

## Example client interactions

After deployment you receive a service URL. Example values used below:

* app name: `support_agent`
* user id: `u_42`
* session id: `s_1001`
* Cloud Run URL stored in the `URL` environment variable

Create a session:

```bash theme={null}
URL="https://support-agent-7xq4ktzmba-uc.a.run.app"

curl -X POST \
  "$URL/apps/support_agent/users/u_42/sessions/s_1001" \
  -H "Content-Type: application/json"
```

Example JSON response (abbreviated):

```json theme={null}
{
  "id": "s_1001",
  "appName": "support_agent",
  "userId": "u_42"
}
```

Run the agent and receive a single JSON response using `/run`:

```bash theme={null}
curl "$URL/run" \
  -H "Content-Type: application/json" \
  -d '{"app_name": "support_agent", "user_id": "u_42", "session_id": "s_1001", "new_message": {"role": "user", "parts": [{"text": "Where\'s my order A1001?"}]}}'
```

Stream events in real time (useful for chat UIs) with Server-Sent Events on `/run_sse`:

```bash theme={null}
curl "$URL/run_sse" \
  -H "Content-Type: application/json" \
  -d '{"app_name": "support_agent", "user_id": "u_42", "session_id": "s_1001", "new_message": {"role": "user", "parts": [{"text": "Where\'s my order A1001?"}]}}'
```

SSE response example (each `data:` line is an event frame):

```text theme={null}
data: {"type":"tool_call","functionCall":{"name":"lookup_order","arguments":{...}}}
data: {"type":"tool_response","functionResponse":{"name":"lookup_order","result":{...}}}
data: {"type":"final","text":"Your order shipped yesterday."}
```

JSON is plain-text and language-agnostic, so most platforms can parse these responses.

If your Cloud Run service is private (recommended for many deployments), clients must authenticate using Google Cloud credentials. ADK's deploy command exposes options to control authentication and other service settings.

To make the Cloud Run service private during deployment, disable unauthenticated access:

```bash theme={null}
adk deploy cloud_run \
  --no-allow-unauthenticated \
  --project=support-prod \
  --region=us-central1 \
  --service_name=support-agent \
  ./support_agent
```

When the service is private, clients must use authenticated requests (for example, by attaching an ID token obtained from Google IAM) to call the endpoints.

## Tracing production requests

When a user reports a slow request (for example, a 6-second response), you need visibility into that single request. Enabling Cloud Trace with `--trace_to_cloud` produces distributed traces for each production request. These traces show a timeline of operations (invocations, agent runs, LLM calls, external tool calls) and their durations.

![A "Cloud Trace" dashboard showing horizontal timeline bars across a 0–6s scale. Each row represents an operation (e.g., invocation, agent\_run, call\_llm, execute\_tool lookup\_order) with colored bars and duration labels like 6.0s and 5.9s.](https://mintcdn.com/kodekloud-c4ac6d9a/heceQKBf52UJgxP-/images/Google-ADK-20/Advanced-Tools/Deploying-to-Cloud-Run/cloud-trace-timeline-operations-0-6s.jpg?fit=max\&auto=format\&n=heceQKBf52UJgxP-\&q=85\&s=a328721bfa2a5fef4123a399deab14c6)

With tracing enabled you can:

* Open the trace for the slow request and see where time was spent (for example, a `lookup_order` tool call consuming 4 of the 6 seconds).
* Correlate LLM latency with external API latency.
* Pinpoint timeouts, retries, and long-running tool calls.

ADK exposes trace settings at deploy-time and in server configuration so you can enable tracing selectively for production services. See [Cloud Trace docs](https://cloud.google.com/trace) for details on viewing and analyzing traces.

## Post-deploy considerations

Deployment is the beginning of production operations. Integrate safety, quality, and operations workflows into your pipeline:

* Run the evaluation suite (evals) before pushing changes to production.
* Keep confirmation/approval gates for tools that can cause damage.
* Lock down every connection to external services and follow least-privilege authentication.
* Monitor performance (Cloud Trace) and usage to detect regressions or cost spikes.
* Maintain an incident playbook and rollbacks for problematic releases.

![A diagram titled "Deployment Isn't the End" showing a user request flowing through Cloud Run, an API server, and agent.py to a lookup\_order service. It also shows icons for Connections, a billing.evalset.json file (12 cases), and an Approval step.](https://mintcdn.com/kodekloud-c4ac6d9a/heceQKBf52UJgxP-/images/Google-ADK-20/Advanced-Tools/Deploying-to-Cloud-Run/deployment-end-cloudrun-api-agent-lookup.jpg?fit=max\&auto=format\&n=heceQKBf52UJgxP-\&q=85\&s=3a71e72017504843de248608ffc4f229)

Summary

* Wrap your agent in the ADK API server, build a container (or use `adk deploy`), and deploy to Cloud Run for a managed, autoscaling deployment.
* Enable Cloud Trace (`--trace_to_cloud`) to get per-request visibility in production.
* Continue enforcing evals, approvals, and least-privilege connections as your agent evolves.

Links and references

* [Cloud Run documentation](https://cloud.google.com/run)
* [Google Kubernetes Engine documentation](https://cloud.google.com/kubernetes-engine)
* [Cloud Trace documentation](https://cloud.google.com/trace)
* ADK deploy commands and server configuration (refer to your ADK project docs)

> [card] [Watch Video](https://learn.kodekloud.com/user/courses/google-adk-2-0/module/73e63dcd-2829-46d7-bbaa-5ac2336079d7/lesson/ef00d40e-6934-4702-80ec-b9d563bc5680)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.