简体   繁体   中英

Google Cloud Run Container Networking

I have a system of apps/services in docker containers that, when I bring them up using docker-compose, talk to each other using a bridge network.

Workers start up and register themselves with a manager. The manager assigns the workers work to do. In order to do this, the workers need to know where the manager is, and the manager needs to know where the workers are.

I want to deploy them all to Google Cloud Run.

At the moment, in docker via docker-compose, they talk to each other using their container names. For example the worker might call: http://manager:5000/register?name=worker1&port=5000 to register on startup, and then the manager can call http://worker1:5000 to send work. All thanks to the fact that they're connected to the same bridge network.

How does this work with Google Cloud Run? As far as I can see, when you create a service linked with a container, you get a permanent URL to communicate with your app once it has started. The app in the container doesn't know what the URL is.

Can I use the service names to communicate with each other in the same way as a docker bridge network?

In fact, you can't orchestrate in the same way the workers. Indeed, the Cloud Run services reply to an HTTP request. When an instance is spawn, there is no registration to a manager.

If you want to perform several task in parallel, perform several HTTP requests.

If you want a strong isolation between the different instances of a same service, set the concurrency param to 1 (only 1 HTTP request is processed in the same time by an instance of the service).

For information, you can have up to 100 instances for a same service.

So, deploy a manager service, and a worker service. The manager service perform HTTP request to worker with the right param for doing the right job.

Take care of the job duration. For now, the timeout can be set up to 900 seconds (15min) maximum

About the naming, the pattern is the following: https://<service-name>-<project-hash>.run.app/

Cloud Run currently does not support hostname based service discovery for other services in your project.

Currently, your best bet is to configure service URLs that your app depends on using environment variables or something like that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM