简体   繁体   English

kube.netes 集群中 postgres 的横向扩展

[英]Horizontal scaling of postgres in kubernetes cluster

I have the following requirements for my application to be deployed in Kube.netes Cluster.我对要部署在 Kube.netes 集群中的应用程序有以下要求。 I am trying to come up with an architecture that resembles my other microservice deployment and not complicated.我正在尝试提出一种类似于我的其他微服务部署但并不复杂的架构。

  • The database server nodes should have reserved capacity数据库服务器节点应具有预留容量
  • When CPU utilization goes above 60% a new database instance should spawn当 CPU 使用率超过 60% 时,应该会产生一个新的数据库实例
  • The application and the database will reside in the same cluster应用程序和数据库将驻留在同一个集群中
  • Need to support high consistency (NOT eventual consistency)需要支持高一致性(不是最终一致性)

I am thinking about having multiple replicas that will connect to the same volume (NAS in my case).我正在考虑让多个副本连接到同一个卷(在我的例子中是 NAS)。 The postgres instances will sit behind a service like my application microservices. postgres 实例将位于像我的应用程序微服务这样的服务后面。 Application will connect to the service and does not need to know which Postgres instance it is talking with.应用程序将连接到该服务,并且不需要知道它正在与哪个 Postgres 实例通信。 This simplifies my architecture a great deal as I don't have to worry about setting up Postgres replication.这大大简化了我的架构,因为我不必担心设置 Postgres 复制。

One issue in this architecture is what happens to data if a Postgres instance goes down after a write request is received.此架构中的一个问题是,如果 Postgres 实例在收到写请求后出现故障,数据会发生什么情况。 I can introduce a message broker with consumer acknowledgement to handle this scenario, but that has some performance implication.我可以引入一个带有消费者确认的消息代理来处理这种情况,但这对性能有一定的影响。

A sample Postgres K8s deployment configuration is shown below.示例 Postgres K8s 部署配置如下所示。 I will need to add service etc.我将需要添加服务等。

What are some pitfall of this architecture?这种架构有哪些缺陷? Have anyone implemented something similar?有没有人实施过类似的东西?

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: postgres
spec:
  replicas: 3
  template:
    metadata:
      labels:
        app: postgres
    spec:
      containers:
        - name: postgres
          image: postgres:latest
          imagePullPolicy: "IfNotPresent"
          ports:
            - containerPort: 5432
          envFrom:
            - configMapRef:
                name: postgres-config
          volumeMounts:
            - mountPath: /var/lib/postgresql/data
              name: postgredb
      volumes:
        - name: postgredb
          persistentVolumeClaim:
            claimName: postgres-pv-claim

It is not completely clear to me, but it sounds like you are talking about Shared Disk Failover我不太清楚,但听起来你在谈论共享磁盘故障转移

To answer your question, the pitfalls are:要回答您的问题,陷阱是:

  • Your NAS is a single point of failure您的 NAS 是单点故障
  • Your replicas are standby replicas, so they cannot be used to scale您的副本是备用副本,因此它们不能用于扩展

I think in order to get scalability and not just fault tolerance, you would need to use replication.我认为为了获得可伸缩性而不仅仅是容错,您需要使用复制。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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