在 kubernetes/docker 群中部署 mariadb galera 集群

Deploy mariadb galera cluster in kubernetes/docker swarm

我正在尝试在 kubernetes 或 docker swarm 中部署 可扩展 mariadb galera 集群。由于每个 pod 或容器都需要自己的 galera 配置,我应该如何创建我的部署以便我能够在没有任何手动工作的情况下扩展它?我认为我们不能使用 ConfigMap,因为 10 节点集群必须有 10 个 configmap!

节点的mariadb galera配置示例:

wsrep_cluster_address="gcomm://ip_1,ip_2,ip_3"    
wsrep_node_address="ip_1"    
wsrep_node_name="node_1"
wsrep_cluster_name="mariadb-cluster"

对于每个节点具有不同配置的应用程序,最佳部署方式是什么?

注意:我可以创建 pods/containers 并自己进行配置(将新节点加入集群),但我认为这是不正确的方式,我需要它是自动可扩展的。

您几乎肯定想使用 StatefulSet to deploy this in Kubernetes. Among other things, this has the property that each Pod will get its own PersistentVolumeClaim for storage, and that the names of individual Pods are predictable and sequential. You should create a matching headless Service,这样每个 Pod 都会有一个匹配的 DNS 名称。

这解决了谜语的几个部分:

# You pick this
wsrep_cluster_name="mariadb-cluster"

# You know what all of these DNS names will be up front
wsrep_cluster_address="gcomm://galera-0.galera.default.svc.cluster.local,...,galera-9.galera.default.svc.cluster.local"

对于wsrep_node_nameMariaDB documentation表示默认为主机名。在 Kubernetes 中,主机名默认为 Pod 名称,Pod 名称是由 StatefulSet 管理的顺序 galera-n for pods 之一,因此您无需手动设置。

wsrep_node_address 比较棘手。这里 the documentation indicates that there are heuristics to guess it (with a specific caveat that it might not be reliable for containers). You can't know an individual pod's IP address before it's created. You can in principle use the downward API 将 pod 的 IP 地址注入到环境变量中。我首先希望启发式方法能够猜测 pod IP 地址,并且效果很好(这是无头服务最终会解决的问题)。

在 ConfigMap 中留下上面的块,它在所有副本中都是全局的。其他剩余的每个 Galera 节点值应该可以自动猜测。