carloscastilla - Fotolia


Get started with Google Cloud Run

Google has upped its resource management game with Cloud Run. Learn the basics of the managed compute platform and follow the simple tutorial on deploying a web app with the service.

When it comes to resource management, no technology is more promising than serverless computing. IT teams use serverless to run code without provisioning or managing servers, and developers deploy functions that only consume resources as needed.

And while the first generation of serverless platforms -- such as AWS Lambda and Google Cloud Functions -- provided a starting point for developers, they only supported a handful of programming languages. Serverless needed to evolve and support more technologies as it grew in popularity.

Google Cloud Run takes the concept of serverless and merges it with containers to provide a seamless alternative for developers. Cloud Run relies on the portability of containerization to scale deployments to meet traffic demands without requiring developers to change the underlying technology to accommodate the managed compute platform.

Get started

It is important to understand what makes Google Cloud Run stand out in comparison to other serverless services: the containers. While the concept of serverless is often considered within the context of functions, Cloud Run deemphasizes the function aspect and focuses on the resource management and accessibility benefits.

Cloud Run is built on the Google-backed Knative open source project, which enables workload portability across platforms, and it supports any programming language or OS libraries. It automatically replicates across zones for added redundancy and integrates with Stackdriver, Google's cloud-native monitoring service.

Users also have two options for how to deploy Cloud Run. There is the pay-per-use, managed version for stateless containers on Google Cloud Platform. There is also Cloud Run for Anthos, which can run on Google Cloud or on premises on VMware. This version supports custom machine types and provides additional network capabilities.

Developers can use Cloud Run to deploy anything from small, function-like API endpoints to monolithic web applications -- as long as those workloads comply with a few basic rules:

  • They must listen for requests on the port defined by the PORT environment variable.
  • They must be stateless, meaning they cannot rely on a persistent local state.
  • They must not perform background activities outside the scope of request handling.

Because HTTP requests trigger Cloud Run services, the program supports any stateless web application. Users can deploy API-like endpoints and web applications with auto-scaling out of the gate. This can save users a fortune in resource costs.

Deploy a service

With the rules in mind, follow these steps to deploy a simple web application that can auto-scale using Google Cloud Run.

Google Cloud Run tutorial
Figure 1. Create a service.

First, navigate to the Cloud Run dashboard and click on the create service button.

This action opens a form that can deploy a container image hosted in Google Container Registry to Cloud Run. While there are numerous advanced settings, take note of the authentication section. It determines whether or not your service requires authentication with Google Cloud Identity and Access Management. For this demo, I allowed unauthenticated requests.

Google cloud run tutorial
Figure 2. Examine service settings.

As soon as you click on the create button, Google Cloud Run will build and deploy the indicated image and redirect you to the details page for the new service. To test the new service, click on the link in the URL section. Here, you can access the new service and see that it's up and running.

Google Cloud Run tutorial
Figure 3. Test the new service by clicking the URL.

And that's it. While this is a rudimentary example, it demonstrates what Cloud Run does at a high level and how easily it can power some impressively scalable applications.

Beyond the basics

There is more to Google Cloud Run than deploying simple web services. If you want more control over Cloud Run, you can deploy individual services directly to a Google Kubernetes Engine instance. This enables you to use custom machine types and additional networking support to fine-tune how you execute your Cloud Run services.

While Cloud Run stands up a subdomain to help access your services, it also offers custom domain support. Now you can power an entire web application within a Cloud Run service without touching any additional infrastructure.

Next Steps

Deploy an app on Google Cloud Run with Terraform

Dig Deeper on Cloud app development and management

Data Center