5

I am trying to set up a mongo DB instance using azure container instances and mounting the same on Azure file share.

We are getting the following error:

[initandlisten] WiredTiger error (1) [1579245437:724939][1:0x7f9419c67b00], connection: __posix_open_file, 667: /data/db/WiredTiger.wt: handle-open: open: Operation not permitted Raw: [1579245437:724939][1:0x7f9419c67b00], connection: __posix_open_file, 667: /data/db/WiredTiger.wt: handle-open: open: Operation not permitted
W  STORAGE  [initandlisten] Failed to start up WiredTiger under any compatibility version.
F  STORAGE  [initandlisten] Reason: 1: Operation not permitted
F  -        [initandlisten] Fatal Assertion 28595 at src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp 789
[initandlisten] 

***aborting after fassert() failure

AZ Commands I am using the following commands to create the storage account, file share, and container instance:

az storage account create -g $resourcegroup -n $storageaccount --sku Standard_LRS

az storage share create --name $mongofileshare --account-name $storageaccount

az container create --resource-group $resourcegroup --name $containername --image mongo:latest --dns-name-label $DNSName --ports 27017 --protocol TCP --environment-variables 'MONGO_INITDB_ROOT_USERNAME=admin' 'MONGO_INITDB_ROOT_PASSWORD=*******' --location westeurope --azure-file-volume-account-name $storageaccount --azure-file-volume-account-key '**********' --azure-file-volume-share-name 'mongofileshare' --azure-file-volume-mount-path '/data/db'
Charles Xu
  • 29,862
  • 2
  • 22
  • 39
Santhosh
  • 671
  • 12
  • 36

3 Answers3

3

Many Thanks to @Charles Xu and @Santhosh above, you save my day. Here I summarize their solution with my working yaml for AKS, mongoDB and Azure Fileshare:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: mongo-db
spec:
  replicas: 1
  selector:
    matchLabels:
      app: mongo-db
  template:
    metadata:
      labels:
        app: mongo-db
    spec:
      nodeSelector:
        "beta.kubernetes.io/os": linux
      containers:
      - name: mongo-db
        image: mongo:latest
        command: ["mongod"] # Note here
        args: ["--dbpath=/data/mongoaz"] # Note here 
        ports:
        - containerPort: 27017
          name: redis
        resources:
          requests:
            cpu: 250m
          limits:
            cpu: 500m
        volumeMounts:
        - name: db-vol
          mountPath: /data/mongoaz
      volumes:
      - name: db-vol
        persistentVolumeClaim:
          claimName: my-db-pvc
Duc Trung Mai
  • 2,141
  • 1
  • 24
  • 23
2

The reason that caused the error you got is that mount the Azure File Share to the container instance will cover all the files in the mount point. The caution is shown here:

Mounting an Azure Files share to a container instance is similar to a Docker bind mount. Be aware that if you mount a share into a container directory in which files or directories exist, these files or directories are obscured by the mount and are not accessible while the container runs.

So it's not recommended to mount the Azure File Share to the existing directory which contains the files used to initialize the Mongo DB. The recommend directory will like path /var/logs/.

Charles Xu
  • 29,862
  • 2
  • 22
  • 39
  • Then what azure service can be used to obtain persistence data for Mongo DB setup. – Santhosh Jan 17 '20 at 10:39
  • 1
    @Santhosh You can use the [AKS and Azure File Share](https://learn.microsoft.com/en-us/azure/aks/azure-files-volume), it can obtain persistence data for Mongo DB setup. – Charles Xu Jan 20 '20 at 01:26
  • @Santhosh Any more updates for the question? Does it solve your problem? If yes, please accept it. – Charles Xu Jan 23 '20 at 06:19
  • Thanks for the answer, I was able to set up mongo DB with Azure file shares following the steps here: https://jussiroine.com/2019/02/an-adventure-in-containers-and-command-line-tools-running-mongodb-in-azure/ – Santhosh Jan 28 '20 at 11:28
  • @Santhosh Yeah, you can see the steps does not mount to the path `/data/db`, it's the MongoDB path already in the image, and use the custom path `/data/mongoaz` instead. Then use the command to change it. So I think what I said is right and show you the reason that why does the error comes out. And you can accept it as the answer and if you want, you can add the link in my answer. – Charles Xu Jan 29 '20 at 01:16
  • 1
    I still face this issue. I change the volume to /var/lib/mongodb still its an issue for me. I tried your Suggestion on another post to put the startup command into commandline and not docker compose, still the same issue – maniB Oct 22 '20 at 14:39
  • @maniB Read the answer carefully. Mount to the existing path is no correct, it will overwrite the existing files which are needed. – Charles Xu Oct 23 '20 at 01:42
  • A saw the same problem on a jenkins image that I was trying to run. On further investigation I found that AZ File can't be used in certain cases as its not POSIX compliant. Use AZ Disk instead. – maniB Oct 23 '20 at 13:06
0

Update:

If you can use Helm, it'll much easier. Check Bitnami chart for MongoDB here:

https://github.com/bitnami/charts/tree/master/bitnami/mongodb

There will be no such this headache problem

Duc Trung Mai
  • 2,141
  • 1
  • 24
  • 23