Skip to content

Latest commit

 

History

History
125 lines (112 loc) · 5.58 KB

e2e_usage.md

File metadata and controls

125 lines (112 loc) · 5.58 KB

CSI driver example

refer to driver parameters for more detailed usage

Azure File Dynamic Provisioning

Option#1: create storage account by CSI driver

  • 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.yaml

set useDataPlaneAPI: "true" in storage class parameters when creating > 100 file shares in parallel to prevent storage resource provider throttling

Option#2: bring your own storage account (only for SMB protocol)

  • Use kubectl create secret to create azure-secret with 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 application

  • 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 -h command 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
...

AzureFile Static Provisioning(use an existing Azure file share)

Option#1: storage class

make sure cluster identity could access to the file share

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

Option#2: PV/PVC

  • Create a PV, download pv-azurefile-csi.yaml file and edit shareName in volumeAttributes
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 Bound status after a while
kubectl describe pvc pvc-azurefile

Create an application

kubectl create -f https://raw.githubusercontent.com/kubernetes-sigs/azurefile-csi-driver/master/deploy/example/nginx-pod-azurefile.yaml
  • Execute df -h command in the container
kubectl exec -it nginx-azurefile -- 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
...

In the above example, there is a /mnt/azurefile directory mounted as cifs filesystem.

Option#3: Inline volume

  • 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
  • secretNamespace parameter is not required since the secret must be in the same namespace as pod
  • in below SMB protocol example, create azure-secret with existing storage account name and key in the same namespace as pod, both secret and pod are in default namespace
kubectl create secret generic azure-secret --from-literal azurestorageaccountname=NAME --from-literal azurestorageaccountkey="KEY" --type=Opaque
  • download nginx-pod-azurefile-inline-volume.yaml file and edit shareName, 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