Mehran
Mehran

Reputation: 16821

Can GCP's Cloud Run be used for non-HTTP services?

I'm new to GCP and trying to make heads and tails of it. So far, I've experienced with GKE and Cloud Run.

In GKE, I can create a Workload (deployment) for a service of any kind under any port I like and allocate resources to it. Then I can create a load balancer and open the ports from the pods to the Internet. The load balancer has an IP that I can use to access the underlying pods.

On the other hand, when I create a Could Run service, I'll give it a docker image and a port and once the service is up and running, it exposes an HTTPS URL! The port that I specify in Cloud Run is the docker's internal port and if I want to access the URL, I have to do that through port 80.

Does this mean that Cloud Run is designed only for HTTP services under port 80? Or maybe I'm missing something?

Upvotes: 13

Views: 4683

Answers (2)

m.spyratos
m.spyratos

Reputation: 4219

To keep this question relevant, I would like to add some updates since the accepted answer was posted. In the end of 2021 Google announced new CPU allocation controls. As mentioned on Use Cloud Run "always-on" CPU allocation for background work:

With this release, users can now alter this behavior so the CPU is always allocated and available even when there are no incoming requests (so long as the container instance is up). Setting the CPU to be always allocated can be useful for running background tasks and other asynchronous processing tasks.

Along with this, you also have the option to not allow public incoming traffic, if that's what you are interested in.

Upvotes: 1

Steren
Steren

Reputation: 7909

Technically "no", Cloud Run cannot be used for non-HTTP services. See Cloud Run's container runtime contract.

But also "sort of":

  1. The URL of a Cloud Run service can be kept "private" (and they are by default), this means that nobody but some specific identities are allowed to invoked the Cloud Run service. See this page to learn more)
  2. The container must listen for requests on a certain port, and it does not have CPU outside of request processing. However, it is very easy to wrap your binary into a lightweight HTTP server. See for example the Shell sample that Uses a very small Go HTTP sevrer to invoke an arbitrary shell script.

Upvotes: 11

Related Questions