Google Cloud Run
Introduction
I intend to document and share my Google Cloud Run learning experiences, which form a crucial part of my certification preparation journey.
Google Cloud Run is a fully managed serverless container platform and is built on top of the Knative platform. Cloud Run automatically manages the infrastructure, scaling, and load balancing for containerized applications. It scales up or down in response to incoming requests, ensuring efficient resource utilization. Cloud Run is designed for stateless and event-driven applications. It is suitable for web applications, APIs, microservices, and any stateless service that can be packaged as a Docker container. It's not is not suitable for long-running tasks or background processing.
Knative is an open-source platform for building, deploying, and managing serverless container-based applications
Equivalent services in AWS -AWS Fargate ,AWS Lambda as per documentation https://cloud.google.com/docs/get-started/aws-azure-gcp-service-comparison
As part of the demo we are going to perform below tasks
- Enable the Cloud Run API
- Create a simple application that can be deployed as a serverless, stateless container.
- Containerize the application and upload to Container/Artifact Registry
- Deploy a containerized application on Cloud Run
Enable the Cloud Run API
open cloud shell and use gcloud command to enable cloud run API
gcloud services enable run.googleapis.com
When executing above command ,if requested to authorize the use of your credentials, please proceed. If you are not logged in, Google will redirect you to an OAuth 2.0 authorization endpoint URL, such as https://accounts.google.com/o/oauth2/auth/XXXX. When a user clicks on this URL, they are taken to Google’s authentication and consent page. If the user grants access, an authorization code is generated and sent back to the specified redirect URI (in this case, the Google Cloud SDK URL). This code can subsequently be exchanged for an access token and a refresh token, enabling access to the requested Google services on the user’s behalf.
Create simple application
its a simple node js application with below docker file
Dockerfile

Package.json

app.js

Containerize the application using cloud build and upload to Container/Artifact Registry
Build mage using gcloud builds — which builds image using given docker file and uploads to Arificate registry
gcloud builds submit — tag gcr.io/$GOOGLE_CLOUD_PROJECT/nodsjsexample

gcloud container images list
NAME: gcr.io/silicon-pointer-399208/nodsjsexample
Deploy to Cloud Run
gcloud run deploy — image gcr.io/$GOOGLE_CLOUD_PROJECT/nodejsexample — allow-unauthenticated — region=$LOCATION
Service name (nodejsexample):
When prompted confirm the service name by pressing Enter.

Wait a few moments until the deployment is complete
then verify the app endpoints
https://nodejsexample-2f2k62nwgq-uc.a.run.app



Generated Yaml file for the above service



