Bird
Raised Fist0
GCPcloud~5 mins

Cloud Run for containerized services in GCP - Commands & Configuration

Choose your learning style10 modes available
Introduction
Running apps in containers can be tricky because you need servers and setup. Cloud Run lets you run container apps easily without managing servers. It automatically handles scaling and availability for you.
When you want to run a web app without managing servers or infrastructure.
When you have a containerized app and want it to scale automatically based on traffic.
When you want to deploy a microservice quickly with minimal setup.
When you want to pay only for the time your app is handling requests.
When you want to run stateless apps that respond to HTTP requests.
Commands
This command deploys a container image to Cloud Run as a new service named 'example-service'. It uses the managed platform in the us-central1 region and allows public access.
Terminal
gcloud run deploy example-service --image gcr.io/cloudrun/hello --platform managed --region us-central1 --allow-unauthenticated
Expected OutputExpected
Deploying container to Cloud Run service [example-service] in project [your-project-id] region [us-central1] ✔ Deploying new service... Done. ✔ Creating Revision... ✔ Routing traffic... ✔ Setting IAM Policy... Service [example-service] revision [example-service-00001-abc] has been deployed and is serving 100 percent of traffic. Service URL: https://example-service-abc123uc.a.run.app
→
--image - Specifies the container image to deploy.
→
--platform - Chooses the Cloud Run platform; 'managed' means fully managed by Google.
→
--allow-unauthenticated - Allows public access to the service without login.
Lists all Cloud Run services in the specified region to verify the deployment.
Terminal
gcloud run services list --platform managed --region us-central1
Expected OutputExpected
SERVICE REGION URL example-service us-central1 https://example-service-abc123uc.a.run.app
→
--platform - Specifies the Cloud Run platform.
→
--region - Specifies the region to list services from.
Sends an HTTP request to the deployed Cloud Run service URL to check if it responds correctly.
Terminal
curl https://example-service-abc123uc.a.run.app
Expected OutputExpected
Hello World!
Key Concept

If you remember nothing else from this pattern, remember: Cloud Run lets you run container apps without managing servers, automatically scaling them based on traffic.

Common Mistakes
Not specifying the --platform managed flag during deployment.
Cloud Run supports multiple platforms; without this flag, deployment may fail or go to the wrong platform.
Always include --platform managed to deploy to the fully managed Cloud Run service.
Forgetting to add --allow-unauthenticated when you want public access.
Without this flag, the service requires authentication and won't be accessible publicly.
Add --allow-unauthenticated to allow anyone to access the service.
Using a container image that does not listen on the correct port or handle HTTP requests.
Cloud Run expects the container to respond to HTTP requests on port 8080 by default.
Ensure your container app listens on port 8080 and handles HTTP requests properly.
Summary
Deploy a container image to Cloud Run using gcloud with the deploy command.
List deployed services to verify the deployment and get the service URL.
Test the deployed service by sending an HTTP request to its URL.

Practice

(1/5)
1. What is the main benefit of using Cloud Run for your containerized applications?
easy
A. It needs you to configure load balancers yourself.
B. It automatically scales your app based on traffic without managing servers.
C. It only works with virtual machines, not containers.
D. It requires you to manage virtual machines manually.

Solution

  1. Step 1: Understand Cloud Run's serverless nature

    Cloud Run runs containers without requiring you to manage servers or infrastructure.
  2. Step 2: Recognize automatic scaling feature

    Cloud Run automatically adjusts the number of container instances based on incoming traffic.
  3. Final Answer:

    It automatically scales your app based on traffic without managing servers. -> Option B
  4. Quick Check:

    Serverless + auto-scale = D [OK]
Hint: Cloud Run = serverless + auto scaling [OK]
Common Mistakes:
  • Thinking you must manage servers manually
  • Confusing Cloud Run with VM services
  • Assuming manual load balancer setup is needed
2. Which of the following is the correct command to deploy a container image to Cloud Run?
easy
A. gcloud run deploy --image=gcr.io/my-project/my-image
B. gcloud compute instances create --image=gcr.io/my-project/my-image
C. kubectl run deploy --image=gcr.io/my-project/my-image
D. docker run deploy --image=gcr.io/my-project/my-image

Solution

  1. Step 1: Identify the correct CLI tool for Cloud Run deployment

    The gcloud run deploy command is used to deploy container images to Cloud Run.
  2. Step 2: Confirm the correct syntax

    The command includes the --image flag followed by the container image URL.
  3. Final Answer:

    gcloud run deploy --image=gcr.io/my-project/my-image -> Option A
  4. Quick Check:

    Cloud Run deploy uses gcloud run deploy [OK]
Hint: Use 'gcloud run deploy' to deploy containers [OK]
Common Mistakes:
  • Using compute or kubectl commands instead of gcloud run
  • Confusing docker run with Cloud Run deployment
  • Missing the --image flag
3. Given this Cloud Run service configuration snippet, what will happen when traffic increases?
apiVersion: serving.knative.dev/v1
kind: Service
metadata:
  name: my-service
spec:
  template:
    spec:
      containers:
      - image: gcr.io/my-project/my-image
        resources:
          limits:
            cpu: 1
            memory: 512Mi
medium
A. The service will scale down to zero immediately.
B. Cloud Run will reject new requests once CPU limit is reached.
C. You must manually add more instances in the configuration.
D. Cloud Run will automatically create more container instances to handle the traffic.

Solution

  1. Step 1: Understand Cloud Run's scaling behavior

    Cloud Run automatically scales container instances based on incoming traffic demand.
  2. Step 2: Recognize resource limits do not prevent scaling

    Resource limits set max CPU/memory per instance but do not stop Cloud Run from adding instances.
  3. Final Answer:

    Cloud Run will automatically create more container instances to handle the traffic. -> Option D
  4. Quick Check:

    Auto scaling = more instances with traffic [OK]
Hint: Cloud Run auto scales instances, resource limits per instance [OK]
Common Mistakes:
  • Thinking resource limits block scaling
  • Assuming manual scaling is required
  • Confusing scale down with scale up
4. You deployed a container to Cloud Run but get an error: Container failed to start. What is a common cause to check first?
medium
A. The container image does not expose the port Cloud Run expects.
B. You forgot to create a virtual machine instance.
C. Cloud Run requires a YAML file to deploy containers.
D. The container image must be in Docker Hub only.

Solution

  1. Step 1: Understand Cloud Run port requirements

    Cloud Run expects the container to listen on port 8080 by default or the port set in the PORT environment variable.
  2. Step 2: Check container image configuration

    If the container does not expose or listen on the expected port, it will fail to start properly.
  3. Final Answer:

    The container image does not expose the port Cloud Run expects. -> Option A
  4. Quick Check:

    Port mismatch causes start failure [OK]
Hint: Check container listens on port 8080 [OK]
Common Mistakes:
  • Assuming VM instances are needed
  • Thinking YAML is mandatory for deployment
  • Believing container must be on Docker Hub
5. You want to deploy a containerized web app on Cloud Run that must handle sudden traffic spikes and also keep costs low when idle. Which setup is best?
hard
A. Deploy on Compute Engine with fixed VM instances.
B. Deploy on Cloud Run with minimum instances set to 5 to handle spikes.
C. Deploy on Cloud Run with autoscaling enabled and minimum instances set to zero.
D. Deploy on Cloud Run with manual scaling to 3 instances.

Solution

  1. Step 1: Understand Cloud Run autoscaling and cost model

    Cloud Run automatically scales instances up and down based on traffic, and setting minimum instances to zero means no cost when idle.
  2. Step 2: Compare options for cost and scalability

    Setting minimum instances above zero incurs cost even when idle; Compute Engine fixed VMs do not scale automatically; manual scaling requires more management.
  3. Final Answer:

    Deploy on Cloud Run with autoscaling enabled and minimum instances set to zero. -> Option C
  4. Quick Check:

    Auto scale + zero min instances = cost efficient [OK]
Hint: Zero min instances saves cost, autoscale handles spikes [OK]
Common Mistakes:
  • Setting minimum instances above zero increases cost
  • Using fixed VMs lacks automatic scaling
  • Manual scaling requires extra management
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard