用于 Postgresql 数据库的 Kubernetes storageClass

Kubernetes storageClass for Postgresql database

Postgresql 数据库使用的 PersistentVolume 的首选 Kubernetes 存储类是什么?当我在 S3 (Minio)、NFS 和 HostPath 之间进行选择时,选择存储类时应考虑哪些因素?

您应该注意获取动态块存储。

主机路径是您想要的,但它不是动态的,这意味着它不能在节点周围移动。因此,如果您的节点出现故障,您就会遇到问题。

如果它由云供应商管理,则应该有一个涵盖此内容的预制存储 class,即 azure disk

NFS 和 S3 对数据库数据没有意义。从这个意义上说,你不是在处理 files/objects。

当您在 Kubernetes 中为 Postgresql 选择存储选项时,您应该考虑以下因素:

  1. NFS / Minio 不是数据库的首选存储,如果您的应用程序是 latency-sensitive。一个常见的用例是下载文件夹或 logging/backup 文件夹。
    但它让您可以灵活地设计 k8s 集群,并能够在未来轻松迁移到 cloud-based 解决方案(例如 AWS EFS 或 S3)。

  2. HostPath 是数据库的更好选择。但是

Kubernetes supports hostPath for development and testing on a single-node cluster. A hostPath PersistentVolume uses a file or directory on the Node to emulate network-attached storage.

In a production cluster, you would not use hostPath. Instead a cluster administrator would provision a network resource like a Google Compute Engine persistent disk, an NFS share, or an Amazon Elastic Block Store volume. Cluster administrators can also use StorageClasses to set up dynamic provisioning.

  1. 如您所说,non-cloud k8s 集群 Longhorn
  2. 有一个很好的选择

Longhorn is a lightweight, reliable, and powerful distributed block storage system for Kubernetes.
Longhorn implements distributed block storage using containers and microservices. Longhorn creates a dedicated storage controller for each block device volume and synchronously replicates the volume across multiple replicas stored on multiple nodes. The storage controller and replicas are themselves orchestrated using Kubernetes.

  1. 此外,检查这个 Bitnami PostgreSQL Helm chart

It offers a PostgreSQL Helm chart that comes pre-configured for security, scalability and data replication. It's a great combination: all the open source goodness of PostgreSQL (foreign keys, joins, views, triggers, stored procedures…) together with the consistency, portability and self-healing features of Kubernetes.