Unable to connect to statefulset mongo with 3 replicas

49 Views Asked by At

I created statefulset with 3 replicas for mongodb. All the pods are running and replicaset also initialted. Below is the output of rs.status():

{
    "set" : "rs0",
    "date" : ISODate("2023-04-14T09:34:50.180Z"),
    "myState" : 1,
    "term" : NumberLong(1),
    "syncingTo" : "",
    "syncSourceHost" : "",
    "syncSourceId" : -1,
    "heartbeatIntervalMillis" : NumberLong(2000),
    "optimes" : {
        "lastCommittedOpTime" : {
            "ts" : Timestamp(1681464881, 1),
            "t" : NumberLong(1)
        },
        "readConcernMajorityOpTime" : {
            "ts" : Timestamp(1681464881, 1),
            "t" : NumberLong(1)
        },
        "appliedOpTime" : {
            "ts" : Timestamp(1681464881, 1),
            "t" : NumberLong(1)
        },
        "durableOpTime" : {
            "ts" : Timestamp(1681464881, 1),
            "t" : NumberLong(1)
        }
    },
    "lastStableCheckpointTimestamp" : Timestamp(1681464871, 1),
    "members" : [
        {
            "_id" : 0,
            "name" : "mongo-0.mongo.default.svc.cluster.local:27017",
            "health" : 1,
            "state" : 1,
            "stateStr" : "PRIMARY",
            "uptime" : 10093,
            "optime" : {
                "ts" : Timestamp(1681464881, 1),
                "t" : NumberLong(1)
            },
            "optimeDate" : ISODate("2023-04-14T09:34:41Z"),
            "syncingTo" : "",
            "syncSourceHost" : "",
            "syncSourceId" : -1,
            "infoMessage" : "",
            "electionTime" : Timestamp(1681456109, 1),
            "electionDate" : ISODate("2023-04-14T07:08:29Z"),
            "configVersion" : 1,
            "self" : true,
            "lastHeartbeatMessage" : ""
        },
        {
            "_id" : 1,
            "name" : "mongo-1.mongo.default.svc.cluster.local:27017",
            "health" : 1,
            "state" : 2,
            "stateStr" : "SECONDARY",
            "uptime" : 8792,
            "optime" : {
                "ts" : Timestamp(1681464881, 1),
                "t" : NumberLong(1)
            },
            "optimeDurable" : {
                "ts" : Timestamp(1681464881, 1),
                "t" : NumberLong(1)
            },
            "optimeDate" : ISODate("2023-04-14T09:34:41Z"),
            "optimeDurableDate" : ISODate("2023-04-14T09:34:41Z"),
            "lastHeartbeat" : ISODate("2023-04-14T09:34:49.490Z"),
            "lastHeartbeatRecv" : ISODate("2023-04-14T09:34:48.485Z"),
            "pingMs" : NumberLong(0),
            "lastHeartbeatMessage" : "",
            "syncingTo" : "mongo-0.mongo.default.svc.cluster.local:27017",
            "syncSourceHost" : "mongo-0.mongo.default.svc.cluster.local:27017",
            "syncSourceId" : 0,
            "infoMessage" : "",
            "configVersion" : 1
        },
        {
            "_id" : 2,
            "name" : "mongo-2.mongo.default.svc.cluster.local:27017",
            "health" : 1,
            "state" : 2,
            "stateStr" : "SECONDARY",
            "uptime" : 8792,
            "optime" : {
                "ts" : Timestamp(1681464881, 1),
                "t" : NumberLong(1)
            },
            "optimeDurable" : {
                "ts" : Timestamp(1681464881, 1),
                "t" : NumberLong(1)
            },
            "optimeDate" : ISODate("2023-04-14T09:34:41Z"),
            "optimeDurableDate" : ISODate("2023-04-14T09:34:41Z"),
            "lastHeartbeat" : ISODate("2023-04-14T09:34:49.490Z"),
            "lastHeartbeatRecv" : ISODate("2023-04-14T09:34:48.533Z"),
            "pingMs" : NumberLong(0),
            "lastHeartbeatMessage" : "",
            "syncingTo" : "mongo-0.mongo.default.svc.cluster.local:27017",
            "syncSourceHost" : "mongo-0.mongo.default.svc.cluster.local:27017",
            "syncSourceId" : 0,
            "infoMessage" : "",
            "configVersion" : 1
        }
    ],
    "ok" : 1,
    "operationTime" : Timestamp(1681464881, 1),
    "$clusterTime" : {
        "clusterTime" : Timestamp(1681464881, 1),
        "signature" : {
            "hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
            "keyId" : NumberLong(0)
        }
    }
}

Now I'm trying to take the backup of this database with below command:

mongodump --authenticationDatabase=admin --uri mongodb://admin1:[email protected],mongo-1.mongo.default,mongo-2.mongo.default/?replicaSet=rs0?readPreference=secondary&authSource=admin&ssl=false

But I'm getting error: Failed: can't create session: could not connect to server: server selection error: server selection timeout, current topology: { Type: ReplicaSetNoPrimary, Servers: [] }

Can someone help me what's going on please? I'm blocked on this.

I checked statefulset logs also, no errors. Not sure what's wrong there.

Note: I'm running the mongodump command from a different pod created with: kubectl run mongodump --image=mongo

0

There are 0 best solutions below