refer to driver parameters for more detailed usage
- Create storage class using Azure file management API(by default)
kubectl create -f https://raw.githubusercontent.com/kubernetes-sigs/azurefile-csi-driver/master/deploy/example/storageclass-azurefile-csi.yaml- Create storage class using Azure file data plane API to get better file operation performance
kubectl create -f https://raw.githubusercontent.com/kubernetes-sigs/azurefile-csi-driver/master/deploy/example/storageclass-azurefile-large-scale.yamlset
useDataPlaneAPI: "true"in storage classparameterswhen creating > 100 file shares in parallel to prevent storage resource provider throttling
- Use
kubectl create secretto createazure-secretwith existing storage account name and key
kubectl create secret generic azure-secret --from-literal azurestorageaccountname=NAME --from-literal azurestorageaccountkey="KEY" --type=Opaque- create storage class referencing
azure-secret
kubectl create -f https://raw.githubusercontent.com/kubernetes-sigs/azurefile-csi-driver/master/deploy/example/storageclass-azurefile-secret.yaml- Create a statefulset with volume mount
kubectl create -f https://raw.githubusercontent.com/kubernetes-sigs/azurefile-csi-driver/master/deploy/example/statefulset.yaml
- Execute
df -hcommand in the container
kubectl exec -it statefulset-azurefile-0 -- df -h
Filesystem Size Used Avail Use% Mounted on ... //f571xxx.file.core.windows.net/pvc-54caa11f-9e27-11e9-ba7b-0601775d3b69 1.0G 64K 1.0G 1% /mnt/azurefile ...
make sure cluster identity could access to the file share
- Download Azure file CSI storage class, edit
resourceGroup,storageAccount,shareNamein storage class
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: azurefile-csi
provisioner: file.csi.azure.com
parameters:
resourceGroup: EXISTING_RESOURCE_GROUP_NAME # optional, only set this when storage account is not in the same resource group as agent node
storageAccount: EXISTING_STORAGE_ACCOUNT_NAME
shareName: SHARE_NAME
reclaimPolicy: Delete
volumeBindingMode: Immediate
mountOptions:
- dir_mode=0777
- file_mode=0777
- mfsymlinks
- cache=strict # https://linux.die.net/man/8/mount.cifs
- nosharesock # reduce probability of reconnect race
- actimeo=30 # reduce latency for metadata-heavy workload
- nobrl # disable sending byte range lock requests to the server and for applications which have challenges with posix locks- Create storage class and PVC
kubectl create -f storageclass-azurefile-existing-share.yaml
kubectl create -f https://raw.githubusercontent.com/kubernetes-sigs/azurefile-csi-driver/master/deploy/example/pvc-azurefile-csi.yaml- Create a PV, download
pv-azurefile-csi.yamlfile and editshareNameinvolumeAttributes
wget https://raw.githubusercontent.com/kubernetes-sigs/azurefile-csi-driver/master/deploy/example/pv-azurefile-csi.yaml
#edit pv-azurefile-csi.yaml
kubectl create -f pv-azurefile-csi.yaml- Create a PVC
kubectl create -f https://raw.githubusercontent.com/kubernetes-sigs/azurefile-csi-driver/master/deploy/example/pvc-azurefile-csi-static.yaml- make sure pvc is created and in
Boundstatus after a while
kubectl describe pvc pvc-azurefilekubectl create -f https://raw.githubusercontent.com/kubernetes-sigs/azurefile-csi-driver/master/deploy/example/nginx-pod-azurefile.yaml- Execute
df -hcommand in the container
kubectl exec -it nginx-azurefile -- df -hFilesystem Size Used Avail Use% Mounted on ... //f571xxx.file.core.windows.net/pvc-54caa11f-9e27-11e9-ba7b-0601775d3b69 1.0G 64K 1.0G 1% /mnt/azurefile ...
In the above example, there is a /mnt/azurefile directory mounted as cifs filesystem.
- inline volume does not support nfs protocol
- to avoid performance issue, use persistent volume instead of inline volume when numerous pods are accessing the same volume
secretNamespaceparameter is not required since the secret must be in the same namespace as pod
- in below SMB protocol example, create
azure-secretwith existing storage account name and key in the same namespace as pod, both secret and pod are indefaultnamespace
kubectl create secret generic azure-secret --from-literal azurestorageaccountname=NAME --from-literal azurestorageaccountkey="KEY" --type=Opaque- download
nginx-pod-azurefile-inline-volume.yamlfile and editshareName,secretName
wget https://raw.githubusercontent.com/kubernetes-sigs/azurefile-csi-driver/master/deploy/example/nginx-pod-azurefile-inline-volume.yaml
#edit nginx-pod-azurefile-inline-volume.yaml
kubectl create -f nginx-pod-azurefile-inline-volume.yaml