Mohammad
Mohammad

Reputation: 1013

Possible to deploy or use several containers as one service in Google Cloud Run?

I am testing Google Cloud Run by following the official instruction:

https://cloud.google.com/run/docs/quickstarts/build-and-deploy

Is it possible to deploy or use several containers as one service in Google Cloud Run? For example: DB server container, Web server container, etc.

Upvotes: 8

Views: 9417

Answers (2)

guillaume blaquiere
guillaume blaquiere

Reputation: 75735

Short Answer NO. You can't deploy several container on the same service (as you could do with a Pod on K8S).

However, you can run several binaries in parallel on the same container -> This article has been written by a Googler that work on Cloud Run.

In addition, keep in mind

  • Cloud Run is a serverless product. It scales up and down (to 0) as it wants (but especially according with the traffic). If the startup duration is long and a new instance of your service is created, the query will take time to be served (and your use will wait)
  • You pay as you use, I means, you are billed only when HTTP requests are processed. Out of processing period, the CPU allocated to the instance is close to 0.
    • That implies that Cloud Run serves container that handle HTTP requests. You can't run a batch processing out of any HTTP request, in background.
  • Cloud Run is stateless. You have an ephemeral and in memory writable directory (/tmp) but when the instance goes down, all the data goes down. You can't run a DB server container that store data. You can interact with external services (Cloud SQL, Cloud Storage,...) but store only transient file locally

EDIT 1

Things change with the time... The googler who wrote the article is a Xoogler (Ex Googler) now, and a sidecar feature exists now in Cloud Run.

Upvotes: 7

sllopis
sllopis

Reputation: 2368

To answer your question directly, I do not think it is possible to deploy a service that has two different containers: DB server container, and Web server container. This does not include scaling (service is automatically scaled to a certain number of container instances).

However, you can deploy a container (a service) that contains multiple processes, although it might not be considered as best practices, as mentioned in this article.

Cloud Run takes a user's container and executes it on Google infrastructure, and handles the instantiation of instances (scaling) of that container, seamlessly based on parameters specified by the user.

To deploy to Cloud Run, you need to provide a container image. As the documentation points out:

A container image is a packaging format that includes your code, its packages, any needed binary dependencies, the operating system to use, and anything else needed to run your service.

In response to incoming requests, a service is automatically scaled to a certain number of container instances, each of which runs the deployed container image. Services are the main resources of Cloud Run.

Each service has a unique and permanent URL that will not change over time as you deploy new revisions to it. You can refer to the documentation for more details about the container runtime contract.

As a result of the above, Cloud Run is primarily designed to run web applications. If you are after a microservice architecture, which consists of different servers running each in unique containers, you will need to deploy multiple services. I understand that you want to use Cloud Run as database server, but perhaps you may be interested in Google's database solutions, like Cloud SQL, Datastore, BigTable or Spanner.

Upvotes: 4

Related Questions