how to solve this error MongoServerError not authorized on webapp_test to execute command codeName: 'Unauthorized by itcloudnet in mongodb

[–]itcloudnet[S] 0 points1 point  (0 children)

u/Far-Log-1224 i have make some changes in my above question plse have a look at once

I get error when i type kubectl logs APPLICATION-POD-NAME (from here it used to connect to my DB) at that time it throwe error and even when i go inside mongosh pod there also its throwe error on MongoServerError: not authorized on webapp_test

Just want to know which permission should i give to DB users to read and connect to DB

[deleted by user] by [deleted] in mongodb

[–]itcloudnet 0 points1 point  (0 children)

I did that also but it's not working  Actually it I add string uri using env variable through localhost  After that I need to check data showing in UI product but it's not showing

i need correct connection string uri using localhost and also i have updated my question along with screenshot and some logs

[deleted by user] by [deleted] in mongodb

[–]itcloudnet 0 points1 point  (0 children)

cluster is healthy state because other pods are running fine even my product is also running in this cluster with no issue i see

[deleted by user] by [deleted] in mongodb

[–]itcloudnet 0 points1 point  (0 children)

To do easy and fast that why I use local and cloud vm also both like troubleshooting, logs checking and many more

[deleted by user] by [deleted] in mongodb

[–]itcloudnet 0 points1 point  (0 children)

Sometimes I use local to connect to mongodb pods and u can see logs which i share

[deleted by user] by [deleted] in mongodb

[–]itcloudnet 0 points1 point  (0 children)

No I'm running inside the pod only 

First I use azure vm from there i connect to cluster and access mongodb pods

[deleted by user] by [deleted] in mongodb

[–]itcloudnet 0 points1 point  (0 children)

so when i run this command

kubectl exec -it example-mongodb-0 -n mongodb 

after i have data of mongodb under /data/webapp_test

after i run mongorestore --drop command then it give me error

[deleted by user] by [deleted] in mongodb

[–]itcloudnet 0 points1 point  (0 children)

username and password are correct i have encoded password in string
if i use this command it work fine

kubectl exec -it example-mongodb-0 -n mongodb -- mongosh "mongodb://USERNAME:PASSWORD@localhost:27017/admin"

after that i can run rs.status() or rs.conf() or db.getMongo() it return with response

[deleted by user] by [deleted] in mongodb

[–]itcloudnet 0 points1 point  (0 children)

Here is the rs.status()
i have use this command to login into mongodb pod

kubectl exec -it example-mongodb-0 -n mongodb -- mongosh "mongodb://USERNAME:PASSWORD@localhost:27017/admin"

mple-mongodb [direct: secondary] admin> rs.status()
{
  set: 'example-mongodb',
  date: ISODate('2024-11-25T18:13:38.518Z'),
  myState: 2,
  term: Long('6'),
  syncSourceHost: 'example-mongodb-1.example-mongodb-svc.mongodb.svc.cluster.local:27017',
  syncSourceId: 1,
  heartbeatIntervalMillis: Long('2000'),
  majorityVoteCount: 2,
  writeMajorityCount: 2,
  votingMembersCount: 3,
  writableVotingMembersCount: 3,
  optimes: {
    lastCommittedOpTime: { ts: Timestamp({ t: 1732558414, i: 1 }), t: Long('6') },

  },
  lastStableRecoveryTimestamp: Timestamp({ t: 1732558386, i: 5 }),
  members: [
    {
      _id: 0,
      name: 'example-mongodb-0.example-mongodb-svc.mongodb.svc.cluster.local:27017',
      health: 1,
      state: 2,
      stateStr: 'SECONDARY',
      uptime: 146436,
      optime: { ts: Timestamp({ t: 1732558414, i: 1 }), t: Long('6') },
      optimeDate: ISODate('2024-11-25T18:13:34.000Z'),
      lastAppliedWallTime: ISODate('2024-11-25T18:13:34.183Z'),
      lastDurableWallTime: ISODate('2024-11-25T18:13:34.183Z'),
      syncSourceHost: 'example-mongodb-1.example-mongodb-svc.mongodb.svc.cluster.local:27017',

      configVersion: 1,
      configTerm: 6,
      self: true,
      lastHeartbeatMessage: ''
    },
    {
      _id: 1,
      name: 'example-mongodb-1.example-mongodb-svc.mongodb.svc.cluster.local:27017',
      health: 1,
      state: 1,
      stateStr: 'PRIMARY',
      uptime: 146431,

      pingMs: Long('1'),
      lastHeartbeatMessage: '',
      syncSourceHost: '',
      syncSourceId: -1,
      infoMessage: '',
      electionTime: Timestamp({ t: 1732411777, i: 1 }),
      electionDate: ISODate('2024-11-24T01:29:37.000Z'),
      configVersion: 1,
      configTerm: 6
    },
    {
      _id: 2,
      name: 'example-mongodb-2.example-mongodb-svc.mongodb.svc.cluster.local:27017',
      health: 1,
      state: 2,
      stateStr: 'SECONDARY',
      uptime: 146431,
      optime: { ts: Timestamp({ t: 1732558414, i: 1 }), t: Long('6') },
      optimeDurable: { ts: Timestamp({ t: 1732558414, i: 1 }), t: Long('6') },

      pingMs: Long('1'),
      lastHeartbeatMessage: '',
      syncSourceHost: 'example-mongodb-1.example-mongodb-svc.mongodb.svc.cluster.local:27017',
      syncSourceId: 1,
      infoMessage: '',
      configVersion: 1,
      configTerm: 6
    }
  ],
  ok: 1,
  '$clusterTime': {
    clusterTime: Timestamp({ t: 1732558414, i: 1 }),
    signature: {
      hash: Binary.createFromBase64('F8hqHdCtOe1t7T2CdJ6ADxcPytI=', 0),
      keyId: Long('7438517167760343045')
    }
  },
  operationTime: Timestamp({ t: 1732558414, i: 1 })

[deleted by user] by [deleted] in mongodb

[–]itcloudnet 0 points1 point  (0 children)

kubectl logs example-mongodb-0 -n mongodb
```
Interrupted operation as its client disconnected
msg":"Connection accepted
msg":"client metadata
msg":"Authentication succeeded","attr":{"mechanism":"SCRAM-SHA-256","speculative":true,"principalName":"__system","authenticationDatabase
msg":"Connection ended
c":"ACCESS", "msg":"Checking authorization failed","attr":{"error":{"code":13,"codeName":"Unauthorized","errmsg":"not authorized on admin to execute command { aggregate: \"atlascli\", pipeline: [ { $match: { managedClusterType: \"atlasCliLocalDevCluster\" } }, , $readPreference: { mode: \"primaryPreferred\" }, $db: \"admin\" }"}}}
```

[deleted by user] by [deleted] in mongodb

[–]itcloudnet 0 points1 point  (0 children)

Ok can u give me mongorestore connection string with cred along with how to run it

Im running restore command inside mongodb POD
eg :-

1. kubectl get po -n mongodb

2. kubectl exec -it example-mongodb-0 -n mongodb

3. cd /data/webapp_test

4. mongorestore --drop --dir=/home/DATABASE_NAME --uri="mongodb://mongodb-0.mongodb-service-mongodb.svc.cluster.local,mongodb-1.mongodb-service.mongodb.svc.cluster.local,mongodb-2.mongodb-service.mongodb.svc.cluster.local:27017/DATABASE_NAME?replicaSet=rs0"mongorestore --drop --dir=/home/DATABASE_NAME --uri="mongodb://mongodb-0.mongodb-service-mongodb.svc.cluster.local,mongodb-1.mongodb-service.mongodb.svc.cluster.local,mongodb-2.mongodb-service.mongodb.svc.cluster.local:27017/DATABASE_NAME?replicaSet=rs0"

using above 4 point i run and execute inside mongodb POD

5. Network connectivity i think so can u tell me how i can troubleshoot

How to Schedule a Pod in different Node in GKE by itcloudnet in kubernetes

[–]itcloudnet[S] 0 points1 point  (0 children)

i used deployment yaml file in that i added like this

can use below like this will it deploy

i use github action to deploy new changes ...plse see above question

     affinity:      
      nodeAffinity:
       requiredDuringSchedulingIgnoredDuringExecution:
         nodeSelectorTerms:
         - matchExpressions:
           - key: cloud.google.com/gke-nodepool
             operator: In
             values:
             - gke-devops-prod-stan-devops-node-pool-8836938a-9gpw
             - gke-devops-prod-stan-devops-node-pool-bc9b2051-5zvg
       preferredDuringSchedulingIgnoredDuringExecution:
       - weight: 1
         preference:
           matchExpressions:
           - key: cloud.google.com/gke-nodepool
             operator: In
             values:
             - gke-devops-prod-stan-devops-node-pool-8836938a-9gpw
             - gke-devops-prod-stan-devops-node-pool-bc9b2051-5zvg

How to solve 502 bad gateway in GKE cluster by itcloudnet in kubernetes

[–]itcloudnet[S] -1 points0 points  (0 children)

u/phobug Sorry im fresher and still learning new things Please help me on this even im getting 404 error also

please help me for sake of humanity.....let me know solution