AKS Mongo data not persistent with Azure file shares

9/24/2018

UPDATE Finally this is nothing to do with Azure File Share. It is actually the same case with Azure Disk and NFS or HostPath

I have mounted an Azure file Shares volume to a mongoDb pod with the mountPath /data. Everything seems to work as expected. When I exec into the pod, I can see mongo data in /data/db. But on the Azure File Shares I can only see the folders /db and /dbconfig, not the files. Any idea ? I have granted the permission 0777 to the volume.

This is my yaml files

StorageClass

kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
  name: azurefile
provisioner: kubernetes.io/azure-file
mountOptions:
  - dir_mode=0777
  - file_mode=0777
  - uid=999
  - gid=999
parameters:
  storageAccount: ACCOUNT_NAME
  skuName: Standard_LRS

PVC

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: azurefile
spec:
  accessModes:
    - ReadWriteMany
  storageClassName: azurefile
  resources:
    requests:
      storage: 20Gi

Mongo deployement file

apiVersion: apps/v1beta2
kind: Deployment
metadata:
  name: mongo
  labels:
    app: mongo
  namespace: development
spec:
  replicas: 1
  selector:
    matchLabels:
      app: mongo
  template:
    metadata:
      labels:
        app: mongo
    spec:
      containers:
        - name: mongo
          image: "mongo"
          imagePullPolicy: IfNotPresent
          ports:
          - containerPort: 27017
            protocol: TCP
          volumeMounts:
          - mountPath: /data
            name: mongovolume
            subPath: mongo
      imagePullSecrets:
        - name: secret-acr
      volumes:
        - name: mongovolume
          persistentVolumeClaim:
            claimName: azurefile

Kubernetes version

Client Version: version.Info{Major:"1", Minor:"10", GitVersion:"v1.10.3", GitCommit:"2bba0127d85d5a46ab4b778548be28623b32d0b0", GitTreeState:"clean", BuildDate:"2018-05-21T09:17:39Z", GoVersion:"go1.9.3", Compiler:"gc", Platform:"windows/amd64"}
Server Version: version.Info{Major:"1", Minor:"10", GitVersion:"v1.10.6", GitCommit:"a21fdbd78dde8f5447f5f6c331f7eb6f80bd684e", GitTreeState:"clean", BuildDate:"2018-07-26T10:04:08Z", GoVersion:"go1.9.3", Compiler:"gc", Platform:"linux/amd64"}
-- Aristo
azure-aks
docker
kubernetes
mongodb
volume

2 Answers

10/4/2018

This setup doesn't work with Azure Files nor with Azure Disks. I am working on one of the projects where I faced similar kind of issue and took Azure support but they don't have any specific resolution for the same.

Root cause provided by Azure Support : The data/files which doesn't remain persistent are the ones which has ownership of mongodb.

-- Sahil Davawala
Source: StackOverflow

10/5/2018

Solved the problem by changing mongo image for docker.io/bitnami/mongodb:4.0.2-debian-9. With this image, mongo data is written on the file share and the data is now persistant

-- Aristo
Source: StackOverflow