当前位置 : 主页 > 编程语言 > 其它开发 >

基础设施即代码(IAC),Zalando Postgres Operator 简介

来源:互联网 收集:自由互联 发布时间:2022-05-15
Postgres Operator 在由 Patroni 提供支持的 Kubernetes (K8s) 上提供易于运行的高可用性 PostgreSQL 集群。它仅通过 Postgres 清单 (CRD) 进行配置,以轻松集成到自动化 CI/CD 管道中,而无需直接访问

image

Postgres Operator 在由 Patroni 提供支持的 Kubernetes (K8s) 上提供易于运行的高可用性 PostgreSQL 集群。它仅通过 Postgres 清单 (CRD) 进行配置,以轻松集成到自动化 CI/CD 管道中,而无需直接访问 Kubernetes API,从而促进基础设施即代码(infrastructure as code)而不是手动操作。

  • Patroni: https://github.com/zalando/patroni
  • PostgreSQL: https://www.postgresql.org/
Operator 功能
  • Postgres 集群变化的滚动更新,包括快速的小版本更新
  • 无需重新启动 pod 即可调整实时卷大小(AWS EBS、PVC)
  • 使用 PGBouncer 进行数据库连接池
  • 支持 PG13 的快速升级。支持所有集群全局升级
  • 恢复和克隆 Postgres 集群(包括主要版本升级)
  • 此外,可以配置到 S3 存储桶的逻辑备份
  • 来自 S3 WAL 存档的备用集群
  • 可针对非云环境进行配置
  • K8s 上的基本凭证和用户管理,简化应用程序部署
  • 支持自定义 TLS 证书
  • 创建和编辑 Postgres 集群清单的 UI
  • 在 Amazon AWS、Google Cloud、OpenShift 和 Kind 本地运行良好
  • 支持 AWS EBS gp2 到 gp3 迁移,支持 iops 和吞吐量配置
PostgreSQL 功能
  • 支持 PostgreSQL 14,从 9.6+ 开始
  • 通过 Patroni 流式复制集群
  • 通过 Spilo 使用 pg_basebackup / WAL-E 进行时间点恢复(Point-In-Time-Recovery)
    • Spilo: https://github.com/zalando/spilo
    • pg_basebackup: https://www.postgresql.org/docs/11/app-pgbasebackup.html
    • WAL-E: https://github.com/wal-e/wal-e
  • 预加载库:bg_mon, pg_stat_statements, pgextwlist, pg_auth_mon
    • bg_mon: https://github.com/CyberDem0n/bg_mon
    • pg_stat_statements: https://www.postgresql.org/docs/14/pgstatstatements.html
    • pgextwlist: https://github.com/dimitri/pgextwlist
    • pg_auth_mon: https://github.com/RafiaSabih/pg_auth_mon
  • 包括。 流行的 Postgres 扩展,例如 decoderbufs, hypopg, pg_cron, pg_partman, pg_stat_kcache, pgq, plpgsql_check, postgis, set_user 和 timescaledb
    • decoderbufs: https://github.com/debezium/postgres-decoderbufs
    • hypopg: https://github.com/HypoPG/hypopg
    • pg_cron: https://github.com/citusdata/pg_cron
    • pg_partman: https://github.com/pgpartman/pg_partman
    • pg_stat_kcache: https://github.com/powa-team/pg_stat_kcache
    • pgq: https://github.com/pgq/pgq
    • plpgsql_check: https://github.com/okbob/plpgsql_check
    • postgis: https://postgis.net/
    • set_user: https://github.com/pgaudit/set_user
    • timescaledb: https://github.com/timescale/timescaledb

Postgres Operator 在 Zalando 开发并已在生产中使用了三年多。

使用 Spilo 12 或更旧的镜像

如果您已经在旧版本中使用带有 Spilo 12 Docker 镜像的 Postgres operator,则需要注意备份路径的更改。我们将主版本引入备份路径,以平滑现在支持的主版本升级。

  • 主版本升级: https://github.com/zalando/postgres-operator/blob/master/docs/administrator.md#minor-and-major-version-upgrade

新的 operator 配置可以设置兼容性标志 enable_spilo_wal_path_compat 以使 Spilo 在当前路径中查找 wal 段,但也可以在旧格式路径中查找。 这是以潜在的性能成本为代价的,应该在几天后禁用。

最新的 Spilo 镜像是:registry.opensource.zalan.do/acid/spilo-14:2.1-p4

最旧的 Spilo 镜像是:registry.opensource.zalan.do/acid/spilo-12:1.6-p5

入门

为了快速获得第一印象,请按照入门教程的说明进行操作。

  • 入门教程: https://github.com/zalando/postgres-operator/blob/master/docs/quickstart.md
支持的 Postgres 和应用程序设置

image

概念

Postgres operator 在 Kubernetes (K8s) 上管理 PostgreSQL 集群:

  1. operator 监视 PostgreSQL 集群清单的添加、更新和删除,并相应地更改正在运行的集群。 例如,当用户提交新清单时,operator 会获取该清单并生成一个新的 Postgres 集群以及所有必要的实体,例如 K8s StatefulSets 和 Postgres 角色。 有关清单可能包含的设置,请参阅此 Postgres 集群清单。
    • operator: https://coreos.com/blog/introducing-operators.html
    • Postgres 集群清单: https://github.com/zalando/postgres-operator/blob/master/manifests/complete-postgres-manifest.yaml
  2. operator 还监视其自身配置的更新,并在必要时更改正在运行的 Postgres 集群。例如,如果 pod 中的 Docker 镜像发生变化,则 operator 执行滚动更新,这意味着它会与新的 Docker 镜像一一重新生成每个托管 StatefulSet 的 pod。
    • 自身配置: https://github.com/zalando/postgres-operator/blob/master/manifests/configmap.yaml
  3. 最后,operator 定期将每个 Postgres 集群的实际状态与集群清单中定义的所需状态同步。
  4. operator 的目标是解放双手,因为配置只能通过清单进行。 这可以轻松集成到自动化部署管道中,而无需直接访问 K8s。
作用域

Postgres Operator 的 scope 是提供、修改配置和清理使用 Patroni 的 Postgres 集群,基本上是为了在 K8s 上轻松方便地运行基于 Patroni 的集群。配置和修改包括一侧的 K8s 资源,但也包括集群启动并运行后的数据库和角色配置。我们尽量把工作留给 K8s 和 Patroni,尤其是集群引导和高可用性。不过,operator 需要参与一些总体编排,比如滚动更新以改善用户体验。

在当前状态下,监控或调整 Postgres 不在 operator 的作用域内。但是,通过全局可配置的 sidecar,我们提供了足够的灵活性来补充其他工具,如 ZMON、Prometheus 或更多 Postgres 特定选项。

  • ZMON: https://opensource.zalando.com/zmon/
  • Prometheus: https://prometheus.io/
所涉实体概述

这是一张图,它总结了 operator 在提交新的 Postgres cluster CRD 时将创建的内容:

image

如果没有对单个集群 pod 内部的概述,这张图是不完整的,所以让我们放大一下:

image

这两张图应该可以帮助您了解 operator 提供的功能类型的基础知识。

状态

该项目目前正在积极开发中。然而,Zalando 已经在内部使用它,以便在 K8s 上运行大量 Postgres 集群,用于 staging 环境和越来越多的 production 集群。在这种环境中,operator 被部署到多个 K8s 集群中,用户通过我们的 CI/CD 基础设施部署清单或依靠精简的用户界面来创建清单。

  • https://jobs.zalando.com/tech/blog/postgresql-in-a-time-of-kubernetes/

请将发现的任何问题报告给 https://github.com/zalando/postgres-operator/issues。

相关视频
  • "照看您的 PostGIS 群" talk by Felix Kunde, FOSS4G 2021: video | slides
    • https://www.youtube.com/watch?v=T96FvjSv98A
    • https://docs.google.com/presentation/d/1IICz2RsjNAcosKVGFna7io-65T2zBbGcBHFFtca24cc/edit?usp=sharing
  • "Zalando K8S上的PostgreSQL:生产两年" talk by Alexander Kukushkin, FOSSDEM 2020: video | slides
    • https://fosdem.org/2020/schedule/event/postgresql_postgresql_on_k8s_at_zalando_two_years_in_production/
    • https://fosdem.org/2020/schedule/event/postgresql_postgresql_on_k8s_at_zalando_two_years_in_production/attachments/slides/3883/export/events/attachments/postgresql_postgresql_on_k8s_at_zalando_two_years_in_production/slides/3883/PostgreSQL_on_K8s_at_Zalando_Two_years_in_production.pdf
  • "Zalando 的 Postgres 即服务" talk by Jan Mußler, DevOpsDays Poznań 2019: video
    • https://www.youtube.com/watch?v=FiWS5m72XI8
  • "在 Kubernetes 上构建您自己的 PostgreSQL 即服务" talk by Alexander Kukushkin, KubeCon NA 2018: video | slides
    • https://www.youtube.com/watch?v=G8MnpkbhClc
    • https://static.sched.com/hosted_files/kccna18/1d/Building your own PostgreSQL-as-a-Service on Kubernetes.pdf
  • "PostgreSQL 和 Kubernetes:没有供应商锁定的 DBaaS" talk by Oleksii Kliukin, PostgreSQL Sessions 2018: video | slides
    • https://www.youtube.com/watch?v=q26U2rQcqMw
    • https://speakerdeck.com/alexeyklyukin/postgresql-and-kubernetes-dbaas-without-a-vendor-lock
  • "使用 Patroni 在 Kubernetes 上实现 PostgreSQL 高可用" talk by Oleksii Kliukin, Atmosphere 2018: video | slides
    • https://www.youtube.com/watch?v=cFlwQOPPkeg
    • https://speakerdeck.com/alexeyklyukin/postgresql-high-availability-on-kubernetes-with-patroni
  • "蓝象点播:Postgres + Kubernetes" talk by Oleksii Kliukin and Jan Mussler, FOSDEM 2018: video | slides (pdf)
    • https://fosdem.org/2018/schedule/event/blue_elephant_on_demand_postgres_kubernetes/
    • https://www.postgresql.eu/events/fosdem2018/sessions/session/1735/slides/59/FOSDEM 2018_ Blue_Elephant_On_Demand.pdf
  • "Kube-Native Postgres" talk by Josh Berkus, KubeCon 2017: video
    • https://www.youtube.com/watch?v=Zn1vd7sQ_bc
相关文章
  • "Zalando Operator for PostgreSQL 入门" by Daniel Westermann on dbi services blog, Mar. 2021.
    • https://blog.dbi-services.com/getting-started-with-the-zalando-operator-for-postgresql/
  • "Zalando 使用 Postgres Operator for Kubernetes 的经验" by Nikolay Bogdanov on flant blog, Feb. 2021.
    • https://blog.flant.com/our-experience-with-postgres-operator-for-kubernetes-by-zalando/
  • "如何设置连续备份和监控" by Pål Kristensen on GitHub, Mar. 2020.
    • https://github.com/zalando/postgres-operator/issues/858#issuecomment-608136253
  • "Postgres on Kubernetes 使用 Zalando operator" by Vito Botta on has_many :code, Feb. 2020.
    • https://vitobotta.com/2020/02/05/postgres-kubernetes-zalando-operator/
  • "在 Google Kubernetes Engine 中运行 PostgreSQL" by Kenneth Rørvik on Repill Linpro blog, Sep. 2019.
    • https://www.redpill-linpro.com/techblog/2019/09/28/postgres-in-kubernetes.html
  • "Zalando Postgres Operator:一年后" by Sergey Dudoladov on Open Source Zalando, Nov. 2018
    • https://opensource.zalando.com/blog/2018/11/postgres-operator/
更多
  • Zalando Postgres Operator 快速上手
上一篇:Fabric2.2中的Raft共识模块源码分析
下一篇:没有了
网友评论