<p>Creating a mongodb from the below <strong>minikube</strong> deployment, I am not able to authenticate from the command line.</p>
<p>Basically I'd just want to list all databases because I suspect there is an issue with the connectivity to mongo-express.</p>
<p>I exec into the pod using <code>kubectl exec -it mongodb-deployment-6b46455744-gfkzw -- /bin/bash</code>,</p>
<p><code>mongo</code> to start up the cli</p>
<p><code>db.auth(&quot;username&quot;, &quot;password&quot;)</code> gives <code>MongoServerError: Authentication failed.</code></p>
<p>even though <code>printenv</code> gives</p>
<pre><code>MONGO_INITDB_ROOT_PASSWORD=password
MONGO_INITDB_ROOT_USERNAME=username
</code></pre>
<p>any help?</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: mongodb-deployment
  labels:
    app: mongodb
spec:
  replicas: 1
  selector:
    matchLabels:
      app: mongodb
  template:
    metadata:
      labels:
        app: mongodb
    spec:
      containers:
      - name: mongodb
        image: mongo
        ports:
        - containerPort: 27017
        env:
        - name: MONGO_INITDB_ROOT_USERNAME
          valueFrom:
            secretKeyRef:
              name: mongodb-secret
              key: mongo-root-username
        - name: MONGO_INITDB_ROOT_PASSWORD
          valueFrom: 
            secretKeyRef:
              name: mongodb-secret
              key: mongo-root-password
        - name: ME_CONFIG_MONGODB_ENABLE_ADMIN
          value: &quot;true&quot;
---
apiVersion: v1
kind: Service
metadata:
  name: mongodb-service
spec:
  selector:
    app: mongodb
  ports:
    - protocol: TCP
      port: 27017
      targetPort: 27017
</code></pre>

<p>managed to connect using</p>
<pre><code>mongosh --port 27017  --authenticationDatabase \
    &quot;admin&quot; -u &quot;myUserAdmin&quot; -p
</code></pre>
<p>from <a href="https://docs.mongodb.com/manual/tutorial/authenticate-a-user/#std-label-authentication-auth-as-user" rel="nofollow noreferrer">https://docs.mongodb.com/manual/tutorial/authenticate-a-user/#std-label-authentication-auth-as-user</a> and docker hub page.</p>
