<p><a href="https://i.stack.imgur.com/NgtfV.png" rel="nofollow noreferrer">Click here to get error screen</a></p>

<p>I am deploying MongoDb to Azure AKS with Azure File Share as Volume (using persistent volume &amp; persistent volume claim). If I am increasing replicas more than one then CrashLoopBackOff is occurring. Only one Pod is getting created, other are getting failed.</p>

<p><strong>My Docker file to Create MongoDb image.</strong></p>

<pre><code>FROM ubuntu:16.04

RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv EA312927

RUN echo "deb http://repo.mongodb.org/apt/ubuntu $(cat /etc/lsb-release | grep DISTRIB_CODENAME | cut -d= -f2)/mongodb-org/3.2 multiverse" | tee /etc/apt/sources.list.d/mongodb-org-3.2.list

RUN apt-get update &amp;&amp; apt-get install -y mongodb-org

EXPOSE 27017

ENTRYPOINT ["/usr/bin/mongod"]
</code></pre>

<p><strong>YAML file for Deployment</strong> </p>

<pre><code>kind: Deployment
apiVersion: extensions/v1beta1
metadata:
  name: mongo
  labels:
    name: mongo
spec:
  replicas: 3
  template:
    metadata:
      labels:
        app: mongo
    spec:      
      containers:
      - name: mongo
        image: &lt;my image of mongodb&gt;
        ports:
        - containerPort: 27017
          protocol: TCP
          name: mongo 
        volumeMounts:
        - mountPath: /data/db
          name: az-files-mongo-storage
      volumes:
      - name: az-files-mongo-storage
        persistentVolumeClaim:
          claimName: mong-pvc
      ---
apiVersion: v1
kind: Service
metadata:
  name: mongo
spec:
  ports:
  - port: 27017
    targetPort: 27017
  selector:
    app: mongo
</code></pre>

<p>For your issue, you can take a look at another <a href="https://stackoverflow.com/questions/44497009/mongod-error-98-unable-to-lock-file-data-db-mongod-lock-resource-temporarily/44498179">issue</a> for the same error. So it seems you cannot initialize the same volume when another has already done it for mongo. From the error, I will suggest you just use the volume to store the data. You can initialize in the Dockerfile when creating the image. Or you can use the create volumes for every pod through the <a href="https://learn.microsoft.com/en-us/azure/aks/concepts-clusters-workloads#statefulsets" rel="nofollow noreferrer">StatefulSets</a> and it's more recommended.</p>

<p><strong>Update:</strong></p>

<p>The yam file below will work for you:</p>

<pre><code>apiVersion: v1
kind: Service
metadata:
  name: mongo
spec:
  ports:
  - port: 27017
    targetPort: 27017
  selector:
    app: mongo
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: mongo
spec:
  selector:
    matchLabels:
      app: mongo 
  serviceName: mongo
  replicas: 3 
  template:
    metadata:
      labels:
        app: mongo 
    spec:
      terminationGracePeriodSeconds: 10
      containers:
      - name: mongo
        image: charlesacr.azurecr.io/mongodb:v1
        ports:
        - containerPort: 27017
          name: mongo
        volumeMounts:
        - name: az-files-mongo-storage
          mountPath: /data/db
  volumeClaimTemplates:
    - metadata:
        name: az-files-mongo-storage
      spec:
        accessModes:
          - ReadWriteOnce
        storageClassName: az-files-mongo-storage
        resources:
          requests:
            storage: 5Gi
</code></pre>

<p>And you need to create the StorageClass before you create the statefulSets. The yam file below:</p>

<pre><code>apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: az-files-mongo-storage
provisioner: kubernetes.io/azure-file
mountOptions:
  - dir_mode=0777
  - file_mode=0777
  - uid=1000
  - gid=1000
parameters:
  skuName: Standard_LRS
</code></pre>

<p>Then the pods work well and the screenshot below:</p>

<p><a href="https://i.stack.imgur.com/794s8.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/794s8.png" alt="enter image description here"></a></p>
