Azure StorageClass in Azure Kubernetes Service (AKS)

From Microsoft

In AKS data storage capability is provided by Azure storage. You can use it via Azure Disk or Azure Files.

  • Azure Disks — Mounted as ReadWriteOnce, so are only available to a single pod. For storage volumes that can be accessed by multiple pods simultaneously, use Azure Files.

Azure storage redundancy helps you to store multiple copies of data as per your requirement. You requirement depends on your disaster management planning. This redundancy of data can be categorized on following types at a very high level -

Primary region redundancy -

  1. Locally redundant storage (LRS)

Secondary region redundancy -

  1. Geo-redundant storage (GRS)

According to that following skuName are available in Azure —

  • Standard_LRS — standard locally redundant storage (LRS)

***** ***************** Note *********************************
1. All redundancy mentioned above is not available in all regions.
2. Use Dynamic provisioning always to support your volume management in K8s. 3. A persistent volume claim (PVC) lets you dynamically create storage as needed.
4. You can take backups of these vol individually.

************************************************************

In Azure Kubernetes service free service account by default following storage class are available.

NAME                PROVISIONER                AGE
azurefile kubernetes.io/azure-file 20h
azurefile-premium kubernetes.io/azure-file 20h
default (default) kubernetes.io/azure-disk 20h
managed-premium kubernetes.io/azure-disk 20h

There may be a requirement to create a new storage class. Kubernetes allows you to create new Azure specific class. For more details make sure you go through the documentation. (https://kubernetes.io/docs/concepts/storage/storage-classes/#azure-file)

Lets define a new storage class for Geo redundant storage -

#The default value for fileMode and dirMode is 0777 for Kubernetes #version 1.13.0 and above, you can modify as per your need
kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
name: azurefile-zrs
provisioner: kubernetes.io/azure-file
mountOptions:
- dir_mode=0755
- file_mode=0755
- uid=0
- gid=0
- mfsymlinks
- cache=strict
parameters:
skuName: Standard_LRS

Create it via -

kubectl apply -f new_sc.yaml

Describe it -

ubuntu@bastion:~/elk/eck-helm-chart/templates$ kubectl describe sc azurefile-zrs
Name: azurefile-zrs
IsDefaultClass: No
Annotations: kubectl.kubernetes.io/last-applied-configuration={"apiVersion":"storage.k8s.io/v1","kind":"StorageClass","metadata":{"annotations":{},"name":"azurefile-zrs"},"mountOptions":["dir_mode=0777","file_mode=0777","uid=0","gid=0","mfsymlinks","cache=strict"],"parameters":{"skuName":"Standard_ZRS"},"provisioner":"kubernetes.io/azure-file"}
Provisioner: kubernetes.io/azure-file
Parameters: skuName=Standard_ZRS
AllowVolumeExpansion: <unset>
MountOptions:
dir_mode=0755
file_mode=0755
uid=0
gid=0
mfsymlinks
cache=strict
ReclaimPolicy: Delete
VolumeBindingMode: Immediate
Events: <none>

Use PVC to claim it.

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

Use it -

kubectl apply -f new-pvc.yaml

In case your location is not valid then you may face error :)

kubectl describe pvc azurefile-zrs-pvc
Name: azurefile-zrs-pvc
Namespace: default
StorageClass: azurefile-zrs
Status: Pending
Volume:
Labels: <none>
Annotations: volume.beta.kubernetes.io/storage-provisioner: kubernetes.io/azure-file
Finalizers: [kubernetes.io/pvc-protection]
Capacity:
Access Modes:
VolumeMode: Filesystem
Mounted By: <none>
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Warning ProvisioningFailed 46s persistentvolume-controller Failed to provision volume with StorageClass "azurefile-zrs": could not get storage key for storage account : Failed to create storage account fb530c4b69d6a419bbf9f1e, error: storage.AccountsClient#Create: Failure sending request: StatusCode=0 -- Original Error: autorest/azure: Service returned an error. Status=400 Code="LocationNotValid" Message="Supplied location southcentralus is not valid."
Warning ProvisioningFailed 38s persistentvolume-controller Failed to provision volume with StorageClass "azurefile-zrs": could not get storage key for storage account : Failed to create storage account f6b3fcb41047543759393d9, error: storage.AccountsClient#Create: Failure sending request: StatusCode=0 -- Original Error: autorest/azure: Service returned an error. Status=400 Code="LocationNotValid" Message="Supplied location southcentralus is not valid."
Warning ProvisioningFailed 23s persistentvolume-controller Failed to provision volume with StorageClass "azurefile-zrs": could not get storage key for storage account : Failed to create storage account f6f42c7889e7542f2b53b87, error: storage.AccountsClient#Create: Failure sending request: StatusCode=0 -- Original Error: autorest/azure: Service returned an error. Status=400 Code="LocationNotValid" Message="Supplied location southcentralus is not valid."
Warning ProvisioningFailed 8s persistentvolume-controller Failed to provision volume with StorageClass "azurefile-zrs": could not get storage key for storage account : Failed to create storage account fe4937d82e85d43b4a5b33d, error: storage.AccountsClient#Create: Failure sending request: StatusCode=0 -- Original Error: autorest/azure: Service returned an error. Status=400 Code="LocationNotValid" Message="Supplied location southcentralus is not valid."

If you are successful then use it in your pod spec.

Best Practice:

Happy Learning !

In quest of understanding How Systems Work !

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store