Error while initializing user mongodb , Kubernetes

11/9/2019

I am using mongo db on gke kubernetes engine , it was working perfectly before i update the pod image version, I tried to delete the volumeClaim and the disk , but the problem is the same this is my pod and my init script this is the logs , and yaml file :

    2019-11-09T00:51:03.806+0000 E  QUERY    [js] uncaught exception: Error: couldn't add user: 
    Error preflighting normalization: U_STRINGPREP_PROHIBITED_ERROR :
    _getErrorWithCode@src/mongo/shell/utils.js:25:13
    DB.prototype.createUser@src/mongo/shell/db.js:1370:11 
    @(shell):1:1
    2019-11-09T00:51:03.808+0000 E  -        [main] Error saving history file: FileOpenFailed: 
    Unable to open() file /home/mongodb/.dbshell: No such file or directory 
    2019-11-09T00:51:03.814+0000 I  NETWORK  [conn2] end connection 127.0.0.1:56832 (0 
    connections now open)

apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: mongo-pro
  namespace: production
spec:
  serviceName: "mongo-local"
  replicas: 1
  selector:
    matchLabels:
      app: mongo-local-pro
  template:
    metadata:
      labels:
        app: mongo-local-pro
    spec:
      containers:
        - name: mongo-pro
          image: hasnimehdi2020/mongo:1.0.0
          volumeMounts:
            - name: mongostorageprox
              mountPath: /data/
          env:
            - name: MONGO_INITDB_ROOT_USERNAME
              valueFrom:
                secretKeyRef:
                  name: mongosecretspro
                  key: MONGO_USER
            - name: MONGO_INITDB_DATABASE
              value: "database"
            - name: MONGO_INITDB_ROOT_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: mongosecretspro
                  key: MONGO_PASSWORD
      imagePullSecrets:
        - name: dockerhub
  volumeClaimTemplates:
    - metadata:
        name: mongostorageprox
      spec:
        accessModes: ["ReadWriteOnce"]
        resources:
          requests:
            storage: 10Gi

And finally this is my init script

if [ "$MONGO_INITDB_ROOT_USERNAME" ] && [ "$MONGO_INITDB_ROOT_PASSWORD" ]; then
  "${mongo[@]}" "$MONGO_INITDB_DATABASE" <<-EOJS
  db.createUser({
     user: $(_js_escape "$MONGO_INITDB_ROOT_USERNAME"),
     pwd: $(_js_escape "$MONGO_INITDB_ROOT_PASSWORD"),
     roles: [ "readWrite", "dbAdmin" ]
     })
EOJS
fi

echo ======================================================
echo created $MONGO_INITDB_ROOT_USERNAME in database $MONGO_INITDB_DATABASE
echo ======================================================
-- Mehdi Gasserini
docker
google-kubernetes-engine
kubernetes
mongodb

0 Answers