how to enable authentication in MongoDB in GKE service

2/11/2020

For our Database we have opted for self deployed mongodb and configured it as a service over GKE's managed mongoDB Atlas database. however, how to enable authentication as we do in classical deployment? to make use of user authentication.

neither we are able to login to the official mongo image, nor use editor to set the Authentication Flag to True

Tried copying the mongoDB config file to local machine to make required changes and replacing it in the image back again, kubectl copy require tar archive utility which mongo official image doesn't have.

-- epsan
authentication
google-kubernetes-engine
kubernetes
mongodb

1 Answer

2/11/2020

We can use kubernetes provided args flag to start mongo server with authentication enabled, so user based authentication can be utilised for restricting the access to DB.

in MongoDB Deployment manifest just pass "--auth"

      containers:
      - name: mongo
        image: mongo
        args: ["--auth"]

as usual access the db using connection string: mongodb://USR:PWD@IP:PORT

from Robo 3t put load balancer service IP and mongo standard port: 27017

-- epsan
Source: StackOverflow