Kubernetes上的Mongodb错误“所有Map到新配置中的此节点,副本集为”

sr4lhrrt  于 2022-11-02  发布在  Kubernetes
关注(0)|答案(1)|浏览(172)

我正在使用statefulset将mognodb部署到kubernetes。
我有两个豆荚叫:
mongo-replica-0.mongo:27017和mongo-replica-1.mongo:27017(添加.mongo是因为kube服务)
启动pod后,我从kube作业运行此命令

mongo "mongodb://mongo-replica-0.mongo:27017" -u $MONGO_INITDB_ROOT_USERNAME -p $MONGO_INITDB_ROOT_PASSWORD --eval "rs.initiate({ _id: 'rs0', members: [{ _id: 0, host: 'mongo-replica-0.mongo:27017' }, { _id: 1, host: 'mongo-replica-1.mongo:27017' },] })"

我收到此错误:
“errmsg”:“主机mongo-replica-0.mongo:27017和mongo-replica-1.mongo:27017都Map到新配置中的此节点,版本为{version:1,术语:0},用于副本集rs 0
如何启动副本集?

tkclm6bt

tkclm6bt1#

我需要将服务的IP设置为null,会话关联设置为null,使服务成为headless。当mongo最初试图与sthe服务交互时,它看到了服务的IP,并认为它在引用自己。
地形设定:

resource "kubernetes_service" "mongodb-service" {
  metadata {
    name      = "mongo"
    namespace = kubernetes_namespace.atlas-project.id
    labels = {
      "name" = "mongo"
    }
  }
  spec {

    selector = {
      app = "mongo"
    }
    cluster_ip       = null
    session_affinity = null
    port {
      port        = 27017
      target_port = 27017
    }

    type = "LoadBalancer"
  }
  lifecycle {
    ignore_changes = [spec[0].external_ips]
  }
}

相关问题