本文介绍 Kubernetes 支持数据库等有状态应用的常见解决方案:StatefulSet。
在构建机器学习向量管理层时,我们面临的一个重要问题:如何持久化数据以避免数据丢失?
在阅读了许多数据库企业发布的博客后,我们认为 StatefulSet[1] 是实现这个目标的可行方法。
我们研究了不同的数据库,包括 Cockroach、MySQL、MongoDB、Cassandra、PostgreSQL、Dgraph 和 Redis。我们还研究了 Kafka 和 Zookeeper,因为它们都需要持久化状态。我们选择这些数据库是基于两方面:
- 它们是业界广泛使用的数据库解决方案,并可以部署在 Kubernetes 上。其中一些是云原生数据库,如 Cockroach。
- 这些有状态应用是不同类型的,比如 MySQL 是关系型数据库,MongoDB 是非关系型数据库。研究不同类型的数据库让我们对使用 StatefulSet 方案更加自信。
下面列出了一些关于如何使用 StatefulSet 在 Kubernetes 中部署不同数据库或有状态应用程序的文章。
Cockroach
- 3 ways to master stateful apps in Kubernetes[2],
Kubernetes 有两种方法管理状态:DaemonSet 和 StatefulSet,但是 Cockroach 强烈建议使用 StatefulSet。
- How to Run CockroachDB on Kubernetes[3]Deploy a Local Cluster with Kubernetes[4]
MySQL
- Run a Replicated Stateful Application[5]
- Kubernetes StatefulSet — Example & Best Practices[6]
这篇文章介绍了使用 Kubernetes StatefulSet 部署 MySQL 的端到端流程。
MongoDB
- Running MongoDB on Kubernetes with StatefulSets[7]
- How to Run MongoDB on Kubernetes[8]
Cassandra
- Deploying Cassandra with a StatefulSet[9]
PostgreSQL
- Deploying PostgreSQL as a StatefulSet in Kubernetes[10]
Dgraph[11]
Redis
- Deploying Redis Cluster on Kubernetes[12]
Kafka
- Set-up Kafka Cluster Using Kubernetes StatefulSet[13]
Zookeeper
- Running Zookeeper, A Distributed System Coordinator[14]
基于上述文章,我们将开始使用 StatefulSet,看看它是否能够满足我们的应用场景。
参考引用
1.StatefulSet: kubernetes.io/zh-cn/docs/…
2.3 ways to master stateful apps in Kubernetes:www.cockroachlabs.com/blog/kubern…
3.How to Run CockroachDB on Kubernetes:www.cockroachlabs.com/blog/runnin…
4.Deploy a Local Cluster with Kubernetes:www.cockroachlabs.com/docs/stable…
5.Run a Replicated Stateful Application:kubernetes.io/docs/tasks/…
6.Kubernetes StatefulSet — Example & Best Practices:loft.sh/blog/kubern…
7.Running MongoDB on Kubernetes with StatefulSets:kubernetes.io/blog/2017/0…
8.How to Run MongoDB on Kubernetes:kubernetes.io/blog/2017/0…
9.Deploying Cassandra with a StatefulSet:kubernetes.io/docs/tutori…
10.Deploying PostgreSQL as a StatefulSet in Kubernetes:www.bmc.com/blogs/kuber…
11.Dgraph:dgraph.io/docs/deploy…
12.Deploying Redis Cluster on Kubernetes:www.containiq.com/post/deploy…
13.Set-up Kafka Cluster Using Kubernetes StatefulSet:medium.com/@knoldus/se…
14.Running Zookeeper, A Distributed System Coordinator:kubernetes.io/docs/tutori…