Skip to main content

Cloud Run Deployment

Deploy Genkit applications to Google Cloud Run with automatic scaling, containerization, and support for all languages (JavaScript, Go, Python).

Overview

Cloud Run provides:
  • Fully managed - Serverless container platform
  • Any language - JavaScript, Go, Python, or any container
  • Automatic scaling - Scale to zero when not in use
  • Pay per use - Only pay for actual request time
  • Custom domains - Map to your own domain

Prerequisites

Node.js Deployment

1. Create Express Server

src/index.ts

2. Create Dockerfile

Dockerfile

3. Create .dockerignore

.dockerignore

4. Deploy to Cloud Run

Go Deployment

1. Create Go Server

main.go

2. Create Dockerfile for Go

Dockerfile

3. Deploy Go App

Python Deployment

1. Create FastAPI Server

main.py

2. Create requirements.txt

requirements.txt

3. Create Dockerfile for Python

Dockerfile

4. Deploy Python App

Configuration

Environment Variables

Memory and CPU

Concurrency and Autoscaling

Custom Domain

Authentication

Require Authentication

Service Account

Monitoring

View Logs

Enable Tracing

Testing

Test Deployed Service

Load Testing

Multi-Region Deployment

Deploy to multiple regions for lower latency:

Cost Optimization

Scale to Zero

CPU Allocation

Troubleshooting

Container Fails to Start

Problem: Service deployment fails. Solution: Check logs:

Timeout Errors

Problem: Requests timeout. Solution: Increase timeout:

Out of Memory

Problem: Container crashes with OOM. Solution: Increase memory:

Best Practices

  1. Use health checks - Cloud Run uses / by default, add a dedicated endpoint
  2. Set appropriate timeouts - AI operations need longer timeouts than default
  3. Enable tracing - Use Cloud Trace for debugging
  4. Use secrets - Store API keys in Secret Manager, not environment variables
  5. Implement graceful shutdown - Handle SIGTERM signals
  6. Monitor costs - Set up billing alerts

Next Steps

Express Plugin

Learn about Express.js integration

Monitoring

Set up Cloud Trace and monitoring