Unable to mount azure file shares as mongodb volume in azure container instances
Asked Answered
M

4

6

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'
Mendelian answered 17/1, 2020 at 7:49 Comment(3)
Please give out what do you deploy the Mongo DB to container instance and how do you mount the Azure File Share to the instance.Deviation
@CharlesXu Updated the question with AZ commands.Mendelian
Any more updates for the question? Does it solve your problem? If yes, please accept it.Deviation
D
4

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/.

Deviation answered 17/1, 2020 at 9:26 Comment(8)
Then what azure service can be used to obtain persistence data for Mongo DB setup.Mendelian
@Mendelian You can use the AKS and Azure File Share, it can obtain persistence data for Mongo DB setup.Deviation
@Mendelian Any more updates for the question? Does it solve your problem? If yes, please accept it.Deviation
Thanks for the answer, I was able to set up mongo DB with Azure file shares following the steps here: jussiroine.com/2019/02/…Mendelian
@Mendelian 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.Deviation
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 issueHeadset
@Headset Read the answer carefully. Mount to the existing path is no correct, it will overwrite the existing files which are needed.Deviation
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.Headset
T
4

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
Traitorous answered 16/8, 2020 at 9:14 Comment(3)
Glad it was helpful.Mendelian
@Duc - Is it possible to provide the Dockerfile for you image: mongo:latest?Headset
I use Official image for MongoDB, it's hereTraitorous
T
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

Traitorous answered 22/8, 2020 at 14:22 Comment(0)
S
0

I would say the reason this is not recommended lies more on the limitations on using Azure file share wit container instances:

  • You can only mount Azure Files shares to Linux containers. Review more about the differences in feature support for Linux and Windows container groups in the overview.
  • Azure file share volume mount requires the Linux container run as root .
  • Azure File share volume mounts are limited to CIFS support.

Specially the one related on having to run the container as root, which is agianst the best practices.

Unfortunately it looks like MS does not offer any other alternative: You will find a root image here

Substantiate answered 14/3 at 7:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.