Cloud Run Reference
Deploy a Service
# Deploy from container image
gcloud run deploy my-service \
--image=gcr.io/my-project/my-app:v1.0 \
--region=us-central1 \
--platform=managed \
--allow-unauthenticated \
--port=8080 \
--memory=512Mi \
--cpu=1
# Deploy from source (builds with Cloud Build)
gcloud run deploy my-service \
--source=. \
--region=us-central1
# Describe service
gcloud run services describe my-service --region=us-central1
# List services
gcloud run services list --region=us-central1
# Delete service
gcloud run services delete my-service --region=us-central1
Traffic Splitting
# Deploy new revision without traffic
gcloud run deploy my-service \
--image=gcr.io/my-project/my-app:v2.0 \
--region=us-central1 \
--no-traffic
# List revisions
gcloud run revisions list --service=my-service --region=us-central1
# Split traffic (canary: 10% to new revision)
gcloud run services update-traffic my-service \
--region=us-central1 \
--to-revisions=my-service-00002-abc=10,my-service-00001-xyz=90
# Route all traffic to latest
gcloud run services update-traffic my-service \
--region=us-central1 \
--to-latest
# Rollback to specific revision
gcloud run services update-traffic my-service \
--region=us-central1 \
--to-revisions=my-service-00001-xyz=100
Environment Variables & Secrets
# Set environment variables
gcloud run services update my-service \
--region=us-central1 \
--set-env-vars="DB_HOST=10.0.0.1,LOG_LEVEL=INFO"
# Update single env var
gcloud run services update my-service \
--region=us-central1 \
--update-env-vars="APP_VERSION=2.0"
# Mount Secret Manager secret as env var
gcloud run services update my-service \
--region=us-central1 \
--set-secrets="DB_PASSWORD=db-password:latest"
# Mount secret as file
gcloud run services update my-service \
--region=us-central1 \
--set-secrets="/secrets/api-key=api-key:latest"
# Clear all env vars
gcloud run services update my-service \
--region=us-central1 \
--clear-env-vars
Concurrency & Scaling
# Set concurrency (requests per container instance)
gcloud run services update my-service \
--region=us-central1 \
--concurrency=80
# Set min instances (avoid cold starts)
gcloud run services update my-service \
--region=us-central1 \
--min-instances=2
# Set max instances (cost control)
gcloud run services update my-service \
--region=us-central1 \
--max-instances=100
# Set CPU and memory
gcloud run services update my-service \
--region=us-central1 \
--memory=1Gi \
--cpu=2
# CPU always allocated (for background work between requests)
gcloud run services update my-service \
--region=us-central1 \
--cpu-always-allocated
Networking & Authentication
# Allow public access
gcloud run services add-iam-policy-binding my-service \
--region=us-central1 \
--member="allUsers" \
--role="roles/run.invoker"
# Restrict to internal traffic only
gcloud run services update my-service \
--region=us-central1 \
--ingress=internal
# Connect to VPC (for Cloud SQL, Redis, etc.)
gcloud run services update my-service \
--region=us-central1 \
--vpc-connector=my-vpc-connector \
--vpc-egress=private-ranges-only
# Create VPC connector
gcloud compute networks vpc-access connectors create my-vpc-connector \
--region=us-central1 \
--network=default \
--range=10.8.0.0/28
Cloud Run Jobs
# Create a job
gcloud run jobs create my-job \
--image=gcr.io/my-project/my-batch:latest \
--region=us-central1 \
--tasks=10 \
--max-retries=3 \
--task-timeout=3600s
# Execute job
gcloud run jobs execute my-job --region=us-central1
# Schedule job with Cloud Scheduler
gcloud scheduler jobs create http daily-job \
--schedule="0 2 * * *" \
--uri="https://us-central1-run.googleapis.com/apis/run.googleapis.com/v1/namespaces/my-project/jobs/my-job:run" \
--oauth-service-account-email=scheduler-sa@my-project.iam.gserviceaccount.com