如何在Kubernetes上设置Mongo副本? [英] How do you set-up Mongo replica set on Kubernetes?
问题描述
我应该启动三个pod,每个podo都使用Mongo,并将服务指向主要的?或者我应该使用复制控制器吗?
此答案已过期。我写了一个详细的分步教程这里使用更多的最新方法。我强烈建议您阅读全文。
简而言之,您运行一个sidecar应用程序为您配置副本集,并使用每个实例的服务或者ping荚IP地址的K8s API。
示例:这只适用于Google Cloud。您将需要对其他平台进行修改,特别是围绕卷:
- 按照 https://github.com/leportlabs/mongo-k8s-sidecar.git
-
git clone https://github.com/leportlabs/mongo-k8s-sidecar.git
-
cd mongo-k8s-sidecar / example /
-
make add-replica ENV = GoogleCloudPlatform
(这样做三次)
-
- 通过服务连接到副本集。
-
mongodb:// mongo-1,mongo-2,mongo-3:27017 / dbname_?
-
- 您还可以使用原始pod IP地址,而不是为每个pod创建一个服务
I'd like to set-up a Mongo replica set on Kubernetes. I'd like to have three replicas. This means I'd need to start 3 instances.
Should I start three pods, with Mongo in each one, and use the service the point to the primary? Or should I used a replication controller somehow?
This answer is out of date. I wrote a detailed step-by-step tutorial here using more up to date methods. I highly recommend reading it all.
In a nutshell, you run a sidecar app to configure the replica set for you, and either use a service per instance or ping the K8s API for the pod IP addresses.
Example: This will only work in Google Cloud. You will need to make modifications for other platforms, particularly around the volumes:
- Follow the example in https://github.com/leportlabs/mongo-k8s-sidecar.git
git clone https://github.com/leportlabs/mongo-k8s-sidecar.git
cd mongo-k8s-sidecar/example/
make add-replica ENV=GoogleCloudPlatform
(do this three times)
- Connect to the replica set via services.
mongodb://mongo-1,mongo-2,mongo-3:27017/dbname_?
- You can also use the raw pod IP addresses instead of creating a service per pod
这篇关于如何在Kubernetes上设置Mongo副本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!