Cloud Run services

Google Cloud · Essentials · 13 min

Cloud Run is the quickest path from a container to a production URL, with no servers or clusters to manage.

Cloud Run runs stateless containers. You give it an image; it gives you an HTTPS URL, TLS, autoscaling (including to zero) and per-request or per-instance billing.

The contract for your container: listen on the port in the PORT environment variable (8080 by default), respond to HTTP, and keep no state on local disk you need later (the filesystem is in-memory and per instance).

Each deploy creates an immutable revision. Traffic can be split between revisions for canaries (gcloud run services update-traffic --to-revisions=...) and rolled back instantly.

Settings that matter:

  • Concurrency: requests per instance (default 80). Lower it for CPU-heavy work.
  • Min/max instances: --min-instances=1 removes cold starts; --max-instances caps cost and protects your database.
  • CPU and memory, request timeout (default 5 minutes, up to 60).
  • Ingress (all, internal, internal and load balancer) and authentication: by default callers need roles/run.invoker; --allow-unauthenticated makes it public.
  • Service account the code runs as (use a dedicated one).

gcloud run deploy --source . builds your code with Cloud Build (Dockerfile or buildpacks) and stores the image in Artifact Registry for you. For run-to-completion work use Cloud Run jobs instead of services.

Example

# Dockerfile next to app.py:  FROM python:3.13-slim ... CMD exec gunicorn -b :$PORT app:app
gcloud run deploy orders-api --source . --region=europe-west1 \
  --service-account=orders-api@shop-dev-4821.iam.gserviceaccount.com \
  --allow-unauthenticated --min-instances=0 --max-instances=20 --concurrency=40
# Service URL: https://orders-api-987654321098.europe-west1.run.app

# Canary: send 10% to the newest revision
gcloud run services update-traffic orders-api --region=europe-west1 \
  --to-revisions=orders-api-00007-xyz=10,orders-api-00006-abc=90

gcloud run services logs read orders-api --region=europe-west1 --limit=20

Remember

  • Listen on $PORT and keep instances stateless
  • Every deploy is a revision; split traffic for canaries
  • Tune concurrency, min and max instances
  • Services are private unless you allow unauthenticated access

Watch out for

  • Doing background work after sending the response with request-based billing, where CPU is throttled outside requests.

Check yourself

  1. Your Cloud Run service returns 403 to browsers right after deploy. Most likely cause?

Sign in to answer, see the explanations, and get this lesson back as a quick review later.

Official docs: cloud.google.com/run/docs/deploying