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

查看:24
本文介绍了是否可以使用 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(网络服务器)的容器,以连接到 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天全站免登陆