title: Mongo kubernetes securing
body: <p>I'm trying to create username/password for my mongodb on kubernetes. But seems MONGO_INITDB_ROOT_USERNAME/PASSWORD is not work or work incorrect as I cannot login with this credentials:</p>
  
  <pre><code>   apiVersion: apps/v1beta1
  kind: StatefulSet
  metadata:
    name: mongotest
  spec:
    revisionHistoryLimit: 3
    selector:
      matchLabels:
        app: mongotest 
    replicas: 1
    podManagementPolicy: Parallel
    updateStrategy:
      type: RollingUpdate
    template:
      metadata:
        labels:
          app: mongotest
      spec:
        hostname: mongotest
        containers:
        - name: mongotest
          image: mongo
          imagePullPolicy: Always
          restartPolicy: Always
          env:
            - name: "MONGO_DATA_DIR"
              value: "/data/db"
            - name: "MONGO_LOG_DIR"
              value: "/data/logs"  
            - name: MONGO_INITDB_ROOT_USERNAME
              value: test
            - name: MONGO_INITDB_ROOT_PASSWORD
              value: test
            - name: MONGO_INITDB_DATABASE
              value: admin
          lifecycle:
            postStart:
              exec:
                command:
                - /bin/sh
                - -c
                - &gt;
                  mongo --eval 'db.auth('test', 'test');db = db.getSiblingDB("admin"); db.createUser({ user: "admin", pwd: "test", roles: [{ role: "root", db: "admin" }]});'
          ports:
          - name: port27017
            containerPort: 27017
  </code></pre>