The Cloud Verse

Subscribe
cloud

Going Serverless with Google Cloud Run

Updated On Mar 12, 2023

Leverage the power of Serverless through google cloud run. Learn its features and how it differentiates from App Engine, Cloud Functions and Kubernetes Engine.


What is Cloud Run?


Cloud Run is a fully managed, serverless computing service allowing developers to run containerized applications without considering infrastructure management.


It provides a simple, flexible way to deploy and scale containerized applications quickly.


Features of Cloud Run


Fully managed


Cloud Run is a fully managed platform, which means that Google takes care of infrastructure management, scaling, and availability, allowing developers to focus on writing code.


Serverless


Cloud Run is a serverless service, meaning there are no servers or clusters to manage. GCP automatically scales container instances up or down in response to traffic, ensuring optimal performance and cost efficiency.


Container-based


Developers can use any container image, runtime, or programming language to build and deploy their applications.


Flexible deployment options


Cloud Run offers flexible deployment options, including fully managed Cloud Run, Cloud Run for Anthos (on-premises or multi-cloud), and Cloud Run on GKE (Kubernetes).


Traffic Splitting


Cloud Run provides traffic-splitting functionality that allows you to split incoming traffic between different revisions or instances of your service. This can be useful for rolling out new versions of your service gradually or testing new features before making them generally available.


Custom Domains


Cloud Run allows you to map a custom domain name to the services so that users can access the services using a domain name instead of the default service URL


Cloud Run vs Cloud Functions


Both Cloud Run and Cloud Functions are serverless services that can be utilized to build scalable applications, but they have some differences.


ParameterCloud RunCloud Functions
Request TimeoutThe request timeout is 5 minutes by default and can be increased to 60 minutes.For gen1 functions, the maximum timeout is 9 minutes. For gen2 functions, the maximum timeout is 60 minutes for HTTP Functions and 9 minutes for event-driven functions.
Supported RuntimesCloud Run supports deploying docker images directly.Cloud functions only support predefined runtimes in languages like NodeJS, Python, Go, Java, PHP, and .NET
TriggersSupports HTTP and Event arc triggers.Cloud Functions support HTTP triggers and Event triggers. Gen2 cloud functions support Eventarc triggers, while Gen1 supports calling from multiple services.
Custom DomainsIt is possible to configure the custom domain on the serviceCloud Functions do not support custom domains.
Web socket supportSupports web socket connections.Cloud Functions does not support WebSocket connections.
ConcurrencyCloud run supports a maximum concurrency of 80. I.e., The same container instance can handle up to 80 requests simultaneouslyEach instance of the cloud function handles only one request at a time. The concurrency of cloud function is 1. If a function instance processes a request, the second request cannot be routed to the same instance.

Cloud Run vs App Engine


App Engine is a Platform as a Service (PaaS) in Google cloud for developing and deploying web applications.


There are two variants of App Engine


App Engine Standard - App Engine Standard supports deploying apps in supported programming languages such as Java, Python, NodeJS, or Go. It does not support websockets.


App Engine Flex - App Engine Flex supports deploying docker images similar to Cloud Run. The major difference is that app engine flex leverages Compute engine VMs under the hood, so there is always a minimum of 1 instance running, which is not the case with Cloud Run. It does support WebSockets.


Overall, cloud run is much more versatile than App Engine.


Cloud Run vs Google Kubernetes Engine


Cloud Run and Google Kubernetes Engine (GKE) are container-based platforms offered by Google Cloud, but they have some key differences.


Google Kubernetes Engine (GKE) is managed Kubernetes service provided by GCP so that we don't have to manage the underlying infrastructure.


GKE can be used for deploying a wide range of applications involving databases, web apps, batch jobs, data pipelines, etc. Anything can be deployed on GKE.


While both Cloud Run and GKE are container-based platforms offered by GCP, Cloud Run is a more simplified service designed for running stateless containers. At the same time, GKE is a more flexible and customizable service for deploying highly scalable workloads using Kubernetes.


Depending on your specific use case and requirements, either platform can be a good choice for deploying and running containerized applications on Google Cloud.


How to Deploy sample application to Google Cloud Run


Deploying applications on cloud run is very easy. You can get your service running in a couple of clicks.


  • Go to the Google Cloud console and select the right Google Cloud project.


  • Make sure that the Cloud Run API is enabled.


  • On the Cloud Run page, Click on Create Service.


  • Select the container image URL. Ensure that the docker image is available in the google container registry.


  • Provide the appropriate service name.


  • Set the ingress to allow all.


  • With allow unauthenticated invocations, the cloud run invoker role is added to the **allUsers **members so that anyone can request the service.


  • Leave other settings as default and Click on Create.



Alternatively, google cloud SDK can deploy the service using the command line. You can use the following commands


#!/bin/bash gcloud config set project <project_id> gcloud run deploy hellosvc --image=<image_url>

Where project_id is the GCP Project ID, and image_url is the image URL present in the google container registry.


Cloud Run Integrations


Cloud Build


GCP under the hood utilizes cloud build service for deploying applications to Cloud Run. Alternatively, you can configure a CI/CD pipeline with cloud build.


You can configure the cloud build to build, test, and push the image to the container registry. Then deploy that image as a new revision.


Cloud Scheduler


Cloud Scheduler is managed service for configuring cron-based schedules. This can be used with cloud run when the APIs need to be called on a scheduled basis.


The cloud scheduler service account needs to have cloud run invoker role to send requests to the service.


Cloud SQL


You can configure a cloud SQL connection while deploying the cloud run service. With this, GCP deploys a cloud sql auth proxy container, which proxies request to the cloud SQL.


Secret Manager


Most applications need to store credentials such as database passwords, API keys, etc. You can configure a secret manager while deploying the cloud run service. The secret value can be mounted as an environment variable which then can be accessed inside the application. You can also specify the port environment variable.


Dhairyasheel Sutar

I am an Experienced Engineer with a strong IT background and a passion for technology exploration. My journey started in college, where I went into web development, AI/ML, and more. I've worked with GCP and AWS, holding certifications in both and being proficient in Kubernetes, Docker, and Terraform. This blog is where I write about my technical expertise.

© 2023 The Cloud Verse. All rights reserved

LinkedInGithub

Links

AboutPortfolio

Stay up to date