0
0
GCPcloud~30 mins

Cloud Run service concept in GCP - Mini Project: Build & Apply

Choose your learning style9 modes available
Deploy a Simple Cloud Run Service
📖 Scenario: You are working as a cloud engineer for a small company. They want to deploy a simple web service that responds to HTTP requests. You will use Google Cloud Run, a service that runs containers without managing servers.
🎯 Goal: Build a Cloud Run service by creating a container image, configuring the service, deploying it, and setting the service to allow public access.
📋 What You'll Learn
Create a Dockerfile with a simple web server
Set a service name variable for deployment
Deploy the container image to Cloud Run using the service name
Configure the Cloud Run service to allow unauthenticated (public) access
💡 Why This Matters
🌍 Real World
Cloud Run is used to deploy containerized applications quickly without managing servers, ideal for scalable web services.
💼 Career
Cloud engineers and developers use Cloud Run to deploy and manage serverless container services in production environments.
Progress0 / 4 steps
1
Create a Dockerfile with a simple web server
Create a file named Dockerfile with these exact lines to run a simple Python web server:
FROM python:3.12-slim
RUN pip install flask
COPY app.py /app.py
CMD ["python", "/app.py"]
Also create app.py with this exact content:
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello():
return 'Hello from Cloud Run!'
if __name__ == '__main__':
app.run(host='0.0.0.0', port=8080)
GCP
Need a hint?

Use the official Python 3.12 slim image. Install Flask. Copy your app.py file. Use CMD to run the app.

2
Set a service name variable for deployment
In your terminal or deployment script, create a variable called SERVICE_NAME and set it to hello-cloud-run exactly. This will be the name of your Cloud Run service.
GCP
Need a hint?

Use the exact variable name SERVICE_NAME and assign the string hello-cloud-run.

3
Deploy the container image to Cloud Run using the service name
Write the exact gcloud command to deploy your container image to Cloud Run using the variable SERVICE_NAME. Use the image gcr.io/YOUR_PROJECT_ID/hello-cloud-run (replace YOUR_PROJECT_ID with your project ID). Deploy to region us-central1 and allow unauthenticated access. The command must include gcloud run deploy $SERVICE_NAME with the correct flags.
GCP
Need a hint?

Use the gcloud run deploy command with the service name variable and the correct image path. Include region and allow unauthenticated flags.

4
Configure the Cloud Run service to allow unauthenticated (public) access
Add the IAM policy binding command to allow all users to invoke the Cloud Run service named $SERVICE_NAME in region us-central1. Use the exact command starting with gcloud run services add-iam-policy-binding $SERVICE_NAME and include --member="allUsers" and --role="roles/run.invoker".
GCP
Need a hint?

This command makes your Cloud Run service public by allowing anyone to invoke it.