【问题标题】:Mongodb on Kubernetes error "all map to this node in new configuration with" for replicasetMongodb on Kubernetes error \"all map to this node in new configuration with\" for replicaset
【发布时间】:2022-10-14 05:17:02
【问题描述】:

我正在使用 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 都映射到新配置中的该节点,副本集 rs0 为 {version: 1, term: 0}

如何启动我的副本集?

【问题讨论】:

    标签: mongodb kubernetes replicaset kubernetes-statefulset


    【解决方案1】:

    我需要将服务的 IP 设置为 null 并将会话亲和性设置为 null 以使服务无头。 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]
      }
    }
    

    【讨论】:

      猜你喜欢
      • 2022-12-02
      • 2022-12-01
      • 2022-12-19
      • 2022-12-26
      • 2014-03-10
      • 1970-01-01
      • 1970-01-01
      • 2022-11-20
      • 2022-11-09
      相关资源
      最近更新 更多