Deploying a Spring Boot Application to Google Cloud Run
Fast recall
Quick revision
Core answer
gcloud run deploy. Cloud Run handles scaling, HTTPS, and traffic management automatically, requiring zero Kubernetes knowledge for stateless workloads.Practical DevOps fluency — whether the candidate understands containerization, GCP's container registry, and the Cloud Run deployment model.
Forgetting to set `--allow-unauthenticated` vs. using IAM-authenticated invocations, or not configuring the server port to match the `PORT` environment variable Cloud Run injects.
Mention Jib for building images without a local Docker daemon, discuss revision traffic splitting for canary deployments, and explain how to wire in Secret Manager for 12-factor configuration.
Interview-ready guide
Interview answer
Deploying a Spring Boot application to Cloud Run follows three steps: build a container image, push it to Artifact Registry, and deploy with a single gcloud command. Cloud Run handles the rest — load balancing, TLS, and scaling.
Build the container image
- Option 1: standard Dockerfile with
docker build; use a multi-stage build with a JDK build stage and JRE runtime stage to minimize the final image size - Option 2: Jib (Google's Java container builder) creates an optimized Docker image without a Dockerfile —
mvn compile jib:buildpushes directly to Artifact Registry with layered image caching, which means subsequent builds push only changed layers; no Docker daemon required in CI
Push to Artifact Registry
gcloud auth configure-docker REGION-docker.pkg.devconfigures Docker to authenticate to Artifact Registry; images are stored in the same region as Cloud Run, eliminating cross-region transfer- Tag the image with the Git commit SHA:
REGION-docker.pkg.dev/PROJECT/REPO/service:SHA— every deployed version is traceable to a commit
Deploy to Cloud Run
gcloud run deploy my-service --image REGION-docker.pkg.dev/PROJECT/REPO/service:SHA --region us-central1 --platform manageddeploys the image; Cloud Run exposes a HTTPS endpoint automatically with a managed TLS certificate- Configure minimum instances with
--min-instances 1to avoid cold starts for latency-sensitive services;--max-instances Ncaps scaling;--concurrencysets how many requests one instance handles simultaneously (default 80 for Spring Boot)
Environment and secrets
- Pass environment variables with
--set-env-vars; for secrets:--set-secrets DB_PASSWORD=my-secret:latestmounts a Secret Manager secret as an environment variable — which means the password is never in the deployment command or source code - Cloud Run uses the service's service account to access Secret Manager; assign the
Secret Manager Secret Accessorrole to the service account
Deploying a Spring Boot Application to Google Cloud Run
Direct Answer
Containerize the Spring Boot app with a Dockerfile or Jib, push the image to Artifact Registry, then deploy with gcloud run deploy. Cloud Run handles scaling, HTTPS, and traffic management automatically, requiring zero Kubernetes knowledge for stateless workloads.
Common Mistakes & Pitfalls
Forgetting to set --allow-unauthenticated vs. using IAM-authenticated invocations, or not configuring the server port to match the PORT environment variable Cloud Run injects.
Check your understanding
Answer these without looking back at the article.
- How do you configure a Cloud Run service to connect to a private Cloud SQL instance?
- What are the cold-start implications for Spring Boot on Cloud Run and how do you mitigate them?
- How does Cloud Run handle concurrent requests compared to a traditional servlet container?
Related interview prep categories
1Looking for a structured roadmap?
Every module on this page is also part of the full Java backend interview track.