Docker – How to mount azurefile persistentVolume in a Kubernetes pod with non-root user rights

azuredockerkubernetespermissionsstorage

I'm running a Kubernetes 1.8.4 cluster on Azure (populated with acs-engine v0.10).

I need to run a Redis pod with data persistency, so I'm using persistentVolume / persistentVolumeClaim with azurefile storageClass so that Redis can save to that volume.

Problem is that Redis container is running with redis:redis user and that Kubernetes mounts the volume with a root:root ownership and 0700 access mode.

=> So Redis can't write to that volume and dies.

Normally I'd fix this with mountOptions, but I fear this option is not supported for AzureFiles as per Kubernetes documentation:

Note: Not all Persistent volume types support mount options.

Did anybody ever managed to mount AzureFiles volumes in a Kubernetes pod with non-root access ? If so, I'd love to know how 🙂

TIA!

Best Answer

After reviewing this providential CloudBees blog post, it turned out that mountOptions are supported for azurefile, it's just that I needed to create a dedicated StorageClass and consume it via a PersistentVolumeClaim.

---
kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
  name: redis-sc
  annotations:
  labels:
    kubernetes.io/cluster-service: 'true'
provisioner: kubernetes.io/azure-file
parameters:
reclaimPolicy: 'Delete'
mountOptions:
  - "uid=999,gid=999"
Related Topic