Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connection to replica set. #3

Open
rajat-soda opened this issue Mar 8, 2021 · 1 comment
Open

Connection to replica set. #3

rajat-soda opened this issue Mar 8, 2021 · 1 comment

Comments

@rajat-soda
Copy link

Hi @BillyFnh ,

The article is really great.. however while trying out the sample with 'hostPath' I am running into issues. The Mongo Replicaset is up .. but I am not able to access it using the connection string " mongodb://mongodb-0-service:27017,mongodb-1-service:27017,mongodb-2-service:27017/admin?replicaSet=rs0"
My K8s manifests are like this..

apiVersion: v1
kind: PersistentVolume
metadata:
  name: mongo-0-pv-volume
  labels:
    type: local
spec:
  storageClassName: manual
  capacity:
    storage: "2Gi"
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: "/data/db/mongo-0"
---
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  namespace: default
  name: mongo-0-pv-claim
spec:
  accessModes:
  - ReadWriteOnce
  storageClassName: manual
  resources:
    requests:
      storage: 1Gi
----
---
apiVersion: v1
kind: Service
metadata:
  namespace: default
  name: mongodb-0-service
  labels:
    run: mongodb-0-service
spec:
  ports:
  - port: 27017
    targetPort: 27017
    protocol: TCP
  selector:
    defacementComponent: mongodb-0
---
apiVersion: apps/v1
kind: Deployment
metadata:
  namespace: default
  name: mongodb-0
  labels:
    env: test
    defacementComponent: mongodb-0
spec:
  replicas: 1
  selector:
    matchLabels:
      defacementComponent: mongodb-0
  template:
    metadata:
      labels:
        defacementComponent: mongodb-0
    spec:
      terminationGracePeriodSeconds: 10
      affinity:
         podAntiAffinity:
           requiredDuringSchedulingIgnoredDuringExecution:
           - labelSelector:
               matchExpressions:
               - key: "app"
                 operator: In
                 values:
                 - mongo
             topologyKey: "kubernetes.io/hostname"
      containers:
        - image: mtlbillyfong/mongodb-replica-set:20200330-stable-1
          name: mongodb-0
          resources:
            requests:
              ephemeral-storage: "1Gi"
              cpu: "500m"
              memory: "1Gi"
            limits:
              ephemeral-storage: "2Gi"
              cpu: "700m"
              memory: "2Gi"
          env:
            - name: "MONGO_INITDB_ROOT_USERNAME"

Error that I am getting is

# mongo mongodb://mongodb-0-service:27017,mongodb-1-service:27017,mongodb-2-service:27017
MongoDB shell version v4.4.4
connecting to: mongodb://mongodb-0-service:27017,mongodb-1-service:27017,mongodb-2-service:27017/?compressors=disabled&gssapiServiceName=mongodb
Error: couldn't connect to server mongodb-2-service:27017, connection attempt failed: SocketException: Error connecting to mongodb-2-service:27017 (10.106.185.83:27017) :: caused by :: Connection timed out :
connect@src/mongo/shell/mongo.js:374:17
@(connect):2:6
exception: connect failed
exiting with code 1
@rajat-soda
Copy link
Author

rajat-soda commented Mar 8, 2021

rs.status()

rs0:PRIMARY> rs.status()
{
        "set" : "rs0",
        "date" : ISODate("2021-03-08T03:28:12.970Z"),
        "myState" : 1,
        "term" : NumberLong(2),
        "syncingTo" : "",
        "syncSourceHost" : "",
        "syncSourceId" : -1,
        "heartbeatIntervalMillis" : NumberLong(2000),
        "majorityVoteCount" : 2,
        "writeMajorityCount" : 2,
        "optimes" : {
                "lastCommittedOpTime" : {
                        "ts" : Timestamp(1615174090, 1),
                        "t" : NumberLong(2)
                },
                "lastCommittedWallTime" : ISODate("2021-03-08T03:28:10.573Z"),
                "readConcernMajorityOpTime" : {
                        "ts" : Timestamp(1615174090, 1),
                        "t" : NumberLong(2)
                },
                "readConcernMajorityWallTime" : ISODate("2021-03-08T03:28:10.573Z"),
                "appliedOpTime" : {
                        "ts" : Timestamp(1615174090, 1),
                        "t" : NumberLong(2)
                },
                "durableOpTime" : {
                        "ts" : Timestamp(1615174090, 1),
                        "t" : NumberLong(2)
                },
                "lastAppliedWallTime" : ISODate("2021-03-08T03:28:10.573Z"),
                "lastDurableWallTime" : ISODate("2021-03-08T03:28:10.573Z")
        },
        "lastStableRecoveryTimestamp" : Timestamp(1615174040, 1),
        "lastStableCheckpointTimestamp" : Timestamp(1615174040, 1),
        "electionCandidateMetrics" : {
                "lastElectionReason" : "stepUpRequestSkipDryRun",
                "lastElectionDate" : ISODate("2021-03-07T14:57:48.407Z"),
                "electionTerm" : NumberLong(2),
                "lastCommittedOpTimeAtElection" : {
                        "ts" : Timestamp(1615129063, 1),
                        "t" : NumberLong(1)
                },
                "lastSeenOpTimeAtElection" : {
                        "ts" : Timestamp(1615129063, 1),
                        "t" : NumberLong(1)
                },
                "numVotesNeeded" : 2,
                "priorityAtElection" : 1,
                "electionTimeoutMillis" : NumberLong(10000),
                "priorPrimaryMemberId" : 0,
                "numCatchUpOps" : NumberLong(0),
                "newTermStartDate" : ISODate("2021-03-07T14:57:49.345Z"),
                "wMajorityWriteAvailabilityDate" : ISODate("2021-03-07T14:57:49.564Z")
        },
        "members" : [
                {
                        "_id" : 0,
                        "name" : "10.110.249.195:27017",
                        "health" : 1,
                        "state" : 2,
                        "stateStr" : "SECONDARY",
                        "uptime" : 44988,
                        "optime" : {
                                "ts" : Timestamp(1615174090, 1),
                                "t" : NumberLong(2)
                        },
                        "optimeDurable" : {
                                "ts" : Timestamp(1615174090, 1),
                                "t" : NumberLong(2)
                        },
                        "optimeDate" : ISODate("2021-03-08T03:28:10Z"),
                        "optimeDurableDate" : ISODate("2021-03-08T03:28:10Z"),
                        "lastHeartbeat" : ISODate("2021-03-08T03:28:12.011Z"),
                        "lastHeartbeatRecv" : ISODate("2021-03-08T03:28:11.996Z"),
                        "pingMs" : NumberLong(0),
                        "lastHeartbeatMessage" : "",
                        "syncingTo" : "10.96.135.26:27017",
                        "syncSourceHost" : "10.96.135.26:27017",
                        "syncSourceId" : 1,
                        "infoMessage" : "",
                        "configVersion" : 194403
                },
                {
                        "_id" : 1,
                        "name" : "10.96.135.26:27017",
                        "health" : 1,
                        "state" : 1,
                        "stateStr" : "PRIMARY",
                        "uptime" : 45181,
                        "optime" : {
                                "ts" : Timestamp(1615174090, 1),
                                "t" : NumberLong(2)
                        },
                        "optimeDate" : ISODate("2021-03-08T03:28:10Z"),
                        "syncingTo" : "",
                        "syncSourceHost" : "",
                        "syncSourceId" : -1,
                        "infoMessage" : "",
                        "electionTime" : Timestamp(1615129068, 1),
                        "electionDate" : ISODate("2021-03-07T14:57:48Z"),
                        "configVersion" : 194403,
                        "self" : true,
                        "lastHeartbeatMessage" : ""
                },
                {
                        "_id" : 2,
                        "name" : "10.106.185.83:27017",
                        "health" : 1,
                        "state" : 2,
                        "stateStr" : "SECONDARY",
                        "uptime" : 45091,
                        "optime" : {
                                "ts" : Timestamp(1615174090, 1),
                                "t" : NumberLong(2)
                        },
                        "optimeDurable" : {
                                "ts" : Timestamp(1615174090, 1),
                                "t" : NumberLong(2)
                        },
                        "optimeDate" : ISODate("2021-03-08T03:28:10Z"),
                        "optimeDurableDate" : ISODate("2021-03-08T03:28:10Z"),
                        "lastHeartbeat" : ISODate("2021-03-08T03:28:12.011Z"),
                        "lastHeartbeatRecv" : ISODate("2021-03-08T03:28:11.996Z"),
                        "pingMs" : NumberLong(0),
                        "lastHeartbeatMessage" : "",
                        "syncingTo" : "10.96.135.26:27017",
                        "syncSourceHost" : "10.96.135.26:27017",
                        "syncSourceId" : 1,
                        "infoMessage" : "",
                        "configVersion" : 194403
                }
        ],
        "ok" : 1,
        "$clusterTime" : {
                "clusterTime" : Timestamp(1615174090, 1),
                "signature" : {
                        "hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
                        "keyId" : NumberLong(0)
                }
        },
        "operationTime" : Timestamp(1615174090, 1)
}
rs0:PRIMARY>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant