Creating a Storage Class in Microsoft Azure

Introduction

Azure volumes can be:

  • Azure Disks

  • Azure Files

  • Azure NetApp Files

  • Azure Blobs.

To provide a PersistentVolume, you can use only:

As noted in the Volumes section, the choice of Disks or Files is often determined by the need for concurrent access to the data or the performance tier.

Prerequisites

Steps to create Disk and Network Volumes

The main focus of the next steps is preparing your cluster to support Disk Volumes.

1. Create a file named csi_rwo.yaml.

2. Copy and paste the content below into the csi_rwo.yaml file:

apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: bns-disk-sc
provisioner: disk.csi.azure.com
parameters:
  skuName: <insert a valid SKU type>
reclaimPolicy: Delete
volumeBindingMode: WaitForFirstConsumer
allowVolumeExpansion: true

The complete list of valid SKU types is available on the Microsoft documentation website.

3. Save the file and exit from edit mode

4. Apply the file to Kubernetes using the following command:

kubectl apply -f csi_rwo.yaml
// OUTPUT
storageclass.storage.k8s.io/bns-disk-sc created

Testing the Storage Class

1. Create a file named claim_rwo.yaml and paste the content below inside it.

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: test-claim-volume
spec:
  accessModes:
  - ReadWriteOnce
  storageClassName: bns-disk-sc
  resources:
    requests:
      storage: 5Gi

2. Apply the claim:

kubectl apply -f claim_rwo.yaml

3. Now it's time to create a pod that uses the claim. Create a new file named pod.yaml and paste the content below inside it:

kind: Pod
apiVersion: v1
metadata:
  name: nginx
spec:
  containers:
    - name: myfrontend
      image: mcr.microsoft.com/oss/nginx/nginx:1.15.5-alpine
      volumeMounts:
      - mountPath: "/mnt/azure"
        name: test-claim-volume
  volumes:
    - name: test-claim-volume
      persistentVolumeClaim:
        claimName: test-claim-volume

4. Apply the file

kubectl apply -f pod.yaml

5. Make sure everything worked out:

kubectl get pvc
// OUTPUT
NAME                STATUS   VOLUME                                     CAPACITY   ACCESS MODES   STORAGECLASS   AGE
test-claim-volume   Bound    pvc-8ad14dec-2c8b-41b5-aec0-d953f0c03764   5Gi        RWO            bns-disk-sc    3m7s

6. Now let's check if the pod is running:

kubectl get pods

7. Cleanup the resources:

kubectl delete -f claim_rwo.yaml
kubectl delete -f pod.yaml

The volume type disk will be automatically provisioned by Azure using the defined storage class.

Last updated

Was this helpful?