如何在Kubernetes上设置Mongo副本? [英] How do you set-up Mongo replica set on Kubernetes?

查看:315
本文介绍了如何在Kubernetes上设置Mongo副本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Kubernetes上设置一个Mongo副本。我想要三个副本。这意味着我需要启动3个实例。



我应该启动三个pod,每个podo都使用Mongo,并将服务指向主要的?或者我应该使用复制控制器吗?

解决方案

此答案已过期。我写了一个详细的分步教程这里使用更多的最新方法。我强烈建议您阅读全文。



简而言之,您运行一个sidecar应用程序为您配置副本集,并使用每个实例的服务或者ping荚IP地址的K8s API。



示例:这只适用于Google Cloud。您将需要对其他平台进行修改,特别是围绕卷:


  1. 按照 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 (这样做三次)


  2. 通过服务连接到副本集。


    • mongodb:// mongo-1,mongo-2,mongo-3:27017 / dbname_?


  3. 您还可以使用原始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:

  1. 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)
  2. Connect to the replica set via services.
    • mongodb://mongo-1,mongo-2,mongo-3:27017/dbname_?
  3. You can also use the raw pod IP addresses instead of creating a service per pod

这篇关于如何在Kubernetes上设置Mongo副本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆