Ability to use a statically created azure file share that was previously created in Azure File using persistent volume claim
What happened: Following https://docs.microsoft.com/en-us/azure/aks/azure-files-dynamic-pv#create-a-persistent-volume-claim I want to create PVC that bounds to a existing Azure File Share in a storage account. I know that the doc want to mount the azure file inside the pod, but I want to use a PVC inside the pod. What you expected to happen: I have already created a storage account, file share named "aksfileshare", PV and PVC. But I get permission issues when I try to use the PVC in a pod.
I have come close to something andyzhangx posted HERE but setting the storageClassName: "" throws error while deploying the PVC stating that the storageClassName does not match the PV storage class name. How to reproduce it (as minimally and precisely as possible):
kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
name: azurefilestorageclass
provisioner: kubernetes.io/azure-file
mountOptions:
- dir_mode=0777
- file_mode=0777
- uid=1000
- gid=1000
parameters:
skuName: Premium_LRS
resourceGroup: someresourcegroupname
storageAccount: somestorageaccountname
apiVersion: v1
kind: Secret
metadata:
name: test-storagesecret
namespace: testing
type: Opaque
data:
azurestorageaccountname: someaccountname_base64
azurestorageaccountkey: someaccountkey_base64
apiVersion: v1
kind: PersistentVolume
metadata:
name: pvazurefile
annotations:
pv.beta.kubernetes.io/gid: "1000"
pv.beta.kubernetes.io/uid: "1000"
spec:
capacity:
storage: 100Gi
accessModes:
- ReadWriteOnce
claimRef:
namespace: testing
name: static-pvc
storageClassName: azurefilestorageclass
azureFile:
secretName: test-storagesecret
shareName: aksfileshare
readOnly: false
mountOptions:
- dir_mode=0777
- file_mode=0777
- uid=1000
- gid=1000
- mfsymlinks
- nobrl
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: static-pvc
namespace: testing
annotations:
createdby: ServiceFabric
spec:
accessModes:
- ReadWriteMany
volumeName: pvazurefile
storageClassName: azurefilestorageclass
resources:
requests:
storage: 100Gi
Anything else we need to know?: When I start the pod with the volume claim I get this in the describ pod
Mounting command: systemd-run
Mounting arguments: --description=Kubernetes transient mount for /var/lib/kubelet/pods/xxxxxxxxxxx-xxxxxxxxx-xxxxxxxxxx/volumes/kubernetes.io~azure-file/pvazurefile--scope -- mount -t cifs -o dir_mode=0777,file_mode=0777,gid=1000,mfsymlinks,nobrl,uid=1000,username=someaccountname,password=someaccountkey
,vers=3.0 //somestorageaccountname.file.core.windows.net/aksfileshare /var/lib/kubelet/pods/xxxxxxxxxxxxxxxx/volumes/kubernetes.io~azure-file/pvazurefile
Output: Running scope as unit run-reab3259b77bd462185cbe8649b3a15c4.scope.
mount error(13): Permission denied
I was able to SSH into that node and run the mount -t cift ..... command and confirm the storage account user and password works. When I change directory into /var/lib/kubelet/pods/xxxxxxxxxxxxxxxx/volumes/kubernetes.io~azure-file/ the pvazurefile directory does not exist. Environment:
- Kubernetes version (use
kubectl version): 1.16.9 - Size of cluster (how many worker nodes are in the cluster?) 8
- General description of workloads in the cluster (e.g. HTTP microservices, Java app, Ruby on Rails, machine learning, etc.)
- Others:
you can use storage class directly if your cluster identity could access that storage account:
---
kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
name: azurefile
provisioner: kubernetes.io/azure-file
reclaimPolicy: Retain
parameters:
skuName: Standard_LRS
resourceGroup: EXISTING_RESOURCE_GROUP_NAME
storageAccount: EXISTING_STORAGE_ACCOUNT_NAME
shareName: SHARE_NAME
and the create a PVC using that azurefile storage class
Thanks Andy! I will try and update! I think the "shareName" in the StorageClass is the key!
Hi Andy, this is working! Thanks again!
Some questions if you do not mind. I am able to get this working, but I am wondering how the new PVC get the password to the storage account if it is bypassing the PV? I have removed the secret from the namespace.
The storage account is created in the AKS resource group and not in the shadow resource group. I assume that the nodes in the shadow RG have identity to access to everything in the AKS RG?
Below are the working set.
kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
name: azurefilestorageclass
provisioner: kubernetes.io/azure-file
mountOptions:
- dir_mode=0777
- file_mode=0777
- uid=1000
- gid=1000
parameters:
skuName: Premium_LRS
resourceGroup: someresourcegroupname
storageAccount: somestorageaccountname
shareName: aksfileshare
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: pvc-staticname
namespace: somenamespace
spec:
accessModes:
- ReadWriteMany
storageClassName: azurefilestorageclass
resources:
requests:
storage: 100Gi
it would create azure-storage-account-{storage-account-name}-secret in default namespace using cluster identity.