1

为什么我想要我的数据库的多个副本?

  1. 冗余:我的应用程序代码有 > 1 个副本。为什么?如果一个节点发生故障,另一个节点可以在负载均衡器后面运行时填补它的位置。
  2. 负载:负载均衡器可以将流量分配到应用程序的多个实例。
  3. A/B 测试。我可以让一个节点为应用程序的一个版本提供服务,而另一个节点为不同的应用程序提供服务。
  4. 维护。我可以关闭一个实例进行维护,并在停机时间为 0 的情况下保持另一个实例。

所以,我想如果可能的话,我也想对后备数据库做同样的事情。

我意识到许多 nosql 数据库更好地配置为多个实例,但我对关系数据库感兴趣。

我和这样这样的操作员一起玩过,但发现文档有问题,无法让它们启动并运行,并且发现社区有点缺乏。在生产中依赖这种东西让我很紧张。Mysql 运算符甚至有一个注释,说它不用于生产用途。

我看到原生 k8s statefulsets 具有扩展性,但这些文档根本不特定于 dbs。我认为复杂之处在于 dbs 需要通过卷持久地写入磁盘,并且如果您有多个实例,则必须以某种方式同步和路由数据。

那么,这对我自己来说是不是微不足道的事情?或者,我最好有一个在集群中使用单副本数据库映像的开发环境以节省计费,以及一个使用完全托管数据库的生产环境,像这样负责扩展/HA为了我?然后我会使用 kustomize 来管理 yaml 差异。

编辑

我实际上找到了一个很好的 postgres 运算符。跟踪文档一次,一切正常,它来自postgres docs

4

1 回答 1

2

I have created this community wiki answer to summarize the topic and to make pertinent information more visible.

As Turing85 well mentioned in the comment:

Do NOT share a pvc to multiple db instances. Even if you use the right backing volume (it must be an object-based storage in order to be read-write many), with enough scaling, performance will take a hit (after all, everything goes to one file system, this will stress the FS). The proper way would be to configure clustering. All major relational databases (mssql, mysql, postgres, oracle, ...) do support clustering. To be on the secure side, however, I would recommend to buy a scalable database "as a service" unless you know exactly what you are doing.

The good solution might be to use a single replica StatefulSet for development, to avoid billing and use a fully managed cloud based sql solution in prod. Unless you have the knowledge or a suffiiciently professional operator to deploy a clustered dbms.

Another solution may be to use a different operator as Aaron did:

I actually found a postgres operator that worked great. Followed the docs one time through and it all worked, and it's from postgres: https://www.kubegres.io/doc/getting-started.html

See also this similar question.

于 2021-08-31T13:57:38.387 回答