Google Cloud Run brings containers and serverless together
Share on facebook
Share on twitter
Share on linkedin

Containers, meet serverless: Getting started with Google Cloud Run

Tim Berry
Tim Berry

As cloud-native application development becomes standard practice, many developers are split between the seemingly opposing paradigms of serverless and containers. 

Serverless solutions offer the ultimate in abstraction, isolating microservices into component parts that can be managed and scaled independently. But there’s a trade-off: your services must be event-driven, and you must conform to your cloud vendor’s serverless framework.

Meanwhile, container solutions offer the ultimate in developer freedom, as they can package any runtime, programming language, or framework, while still providing an isolated unit of work. However, orchestrating containers so that they’re production-ready can take a significant amount of work (unless your side-gig is working as a Kubernetes administrator).

But what if I told you that there’s a way to combine both of these approaches?

Good news! There is. And I’m going to tell you about it. It’s Google Cloud Run.

What’s Google Cloud Run?

Google Cloud Run provides all the benefits of containers, running in a serverless environment. And getting started with Cloud Run couldn’t be easier.

From a Google Cloud Project, you’ll find Cloud Run in the Compute section of the menu. Cloud Run deployments are called Services. To create one, you just click Create Service.

You’ll need to give your service a name, so as tradition dictates, let’s start with hello (for Hello World).

Next, we need to choose an authentication method. Our Hello World app will be a public web service, so we’ll choose Allow unauthenticated invocations.

When we click Next, we’ll be asked to choose a container image. For this demo, click Select and choose the demo container. Or you can just enter the container image URL:

gcr.io/cloudrun/hello

Then click Create and watch the magic happen! Cloud Run services are always accessed via an HTTP endpoint, so Google’s global load balancer is automatically configured to serve your new service with an SSL protected URL. After a few moments, you’ll be shown the service URL. Click the link to see your Hello World app!

If you make any changes to your Service, you’ll get a new Revision. You can easily roll back to previous revisions, or even split traffic between different revisions to canary test new features.

Using containers give you the flexibility to run anything

Of course, the true test of any new technology is Will it run Doom? And of course, in this case, Cloud Run passes the test with flying colors thanks to a project called HTTP-Doom.

Cloud Run needs to find its images in Google Container Registry, so let’s grab the HTTP-Doom container image, quickly re-tag it, and push it to our project. You can run these commands from the Cloud Shell terminal inside your GCP project. Just replace <project-id> with the ID of your project:

docker pull mattipaksula/http-doom

docker tag mattipaksula/http-doom gcr.io/<project-id>/http-doom

docker push gcr.io/<project-id>/http-doom

Now we could go back through our project’s UI to launch our Doom service, but while we’re being all super-cool and hacker-like, let’s see how easy it is to launch it from the command line:

gcloud run deploy doom --image gcr.io/<project-id>/http-doom

Cloud Run will ask us three questions in a row, which we could have overridden with some defaults, but this is a learning exercise!

  • First, we’ll choose to use the fully managed version of Cloud Run when prompted. Cloud Run is also available for Anthos, but that’s a whole other blog post — or series of posts!
  • Next, choose a region when prompted. Feel free to pick one closest to you.
  • Finally, enter Y to allow unauthenticated invocations when asked. Again, this is just a long way of asking you if you want this to be a public web service.

When the command completes, you’ll be given the URL of your new Cloud Run service, or you can find it again in the Cloud Run section of the GCP console. Click on the link and behold the hyper-realism of Doom, rendered in your browser! Of course, the FPS sucks, but that’s not the point!

Containers with all the benefits of serverless

We’ve now seen how easy it is to run a containerized application, with production-ready scaling and load-balancing, without having to spin up any servers or worry about any complex container orchestration manifests.

And we’re also getting all the benefits of a true serverless solution. As well as being able to scale up to thousands of instances, if no one uses our Service, it will scale to zero.

Cloud Run is the easiest and most flexible way for a developer to get their containers into production today. And we’ve only just scratched the surface of what Cloud Run can do. Using things like private services, pub/sub triggers, and custom routing, Cloud Run becomes a first-class citizen in your microservices architecture.

Get a deep dive on Cloud Run

Join me for a deep dive into Google Cloud Run. In this 6-hour course, we’ll learn how to master deployments, integrate with other GCP services, and operate Cloud Run securely and reliably. You’ll learn by getting hands-on experience with practical Cloud Run applications and seeing how they fit into a modern cloud-native stack. 

Get a deep dive in Google Cloud Run from A Cloud Guru.

Next time you want to build a serverless application for the cloud you’ll no longer be constrained by vendor frameworks or drowned by YAML. Cloud Run is the better, more awesome way to deploy apps you’ve been waiting for!

Recommended

Get more insights, news, and assorted awesomeness around all things cloud learning.

Get Started
Who’s going to be learning?
Sign In
Welcome Back!
Thanks for reaching out!

You’ll hear from us shortly. In the meantime, why not check out what our customers have to say about ACG?

How many seats do you need?

  • $499 $399 USD per seat per year
  • Billed Annually
  • Renews in 12 months

Ready to accelerate learning?

For over 25 licenses, a member of our sales team will walk you through a custom tailored solution for your business.


$1,995.00

Checkout