是否可以通过Google Cloud Run运行Postgres(或任何数据库)? [英] Is it possible to run Postgres (or any DB) with Google Cloud Run?

查看:45
本文介绍了是否可以通过Google Cloud Run运行Postgres(或任何数据库)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

1.总结问题

Google Cloud Run宣传它是无状态容器".有没有办法运行任何东西,将状态保存在某个地方?

Google Cloud Run advertises that it is "stateless containers". Is there a way to run anything at all, have it save state somewhere?

我想在一个容器中运行Postgres,但只能按需启动它,在提出请求时启动PG容器.

I want to run Postgres in a container, but only have it up on demand, spin up the PG container when there is a request made.

使用相同的问题,将一个具有REST API(Web服务器)的容器连接到PG容器.

The same question goes for a container that will hold a REST API (web server), to connect to the PG container.

因此,当Web应用程序(托管在Firebase上)向REST API(容器)发出请求时,它将启动,然后从REST api查询的PG实例将启动(或可以简单地放置都将DB和REST API都放在一个容器中.)

So when the web app (hosted on Firebase), makes a request to the REST API (container), it would spin up, and then the PG instance that gets queried from the REST api would spin up (or can simply put both DB , REST API in one container).

对于开发人员实例,我不希望24x7x365几乎不做任何事情,只是希望在开发期间会加速工作,但是我想让其中的许多人是唯一的OPS成员,希望为开发人员实现自动化,包括我自己,并尽量减少帐单.

For a dev instance, I don't want something up 24x7x365 doing mostly nothing, just something that will spin up during development hours, but have a number of these, am the only OPS guy, want to automate it for developers, including myself and minimize billing.

这里最好的方法将不胜感激.

Any best approach here would be appreciated.

2.提供背景,包括您已经尝试过的内容

我已经创建了Docker容器并部署到Cloud Run

I have created Docker containers and deployed to Cloud Run

3.显示一些代码

yum install buildah podman -y

4.描述预期和实际结果,包括任何错误消息

我正在寻找一种解决方案,以最大程度地减少将包含托管和数据库/REST API(数据库必须为Postgres)的开发环境的费用.

I am looking for a solution to minimize billing for a dev environment that will include hosting and a database/REST API (database has to be Postgres).

我正在寻找可维护数据库状态的有状态云运行.

I'm looking for a stateful cloud run that will maintain the state of a database.

推荐答案

Cloud Run不适合托管数据库.分配给Cloud Run的传入请求的服务器实例可以来来去去,并且并非所有请求都将到达同一个实例,这意味着并非所有客户端都可以看到相同的数据.这就是无状态容器"的问题.

Cloud Run is not suitable for hosting a database. Server instances allocated for incoming requests to Cloud Run can come and go, and not all requests will go to the same instance, which means that not all clients will see the same data. That's the problem with "stateless containers".

如果要使用Cloud Run提供数据库访问,最好将其作为其他一些由云托管的数据库服务的代理.您可能会使用它来托管访问其他数据库服务(例如:Cloud Firestore,Cloud SQL)的REST API端点.但是,将数据库本身托管在docker映像中并没有任何意义,因为这些服务器实例可能会意外地来来去去,从而破坏存储在每个实例中的所有数据库状态.

If you want to use Cloud Run to provide database access, it would best be as a proxy to some other cloud-hosted database service. You might use to it host a REST API endpoint that accesses some other database service (for example: Cloud Firestore, Cloud SQL). But it doesn't make sense to host the database itself in your docker image, since those server instances can come and go unpredictably, destroying any database state stored in each instance.

这篇关于是否可以通过Google Cloud Run运行Postgres(或任何数据库)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆