Using Azure Disk storage classes to create dynamic PVs

As part of a StatefulSet, volumeClaimTemplates can provide persistent storage using PersistentVolumes provisioned by a PersistentVolume provisioner of your choice. In this recipe, we will use the Azure storage class to dynamically create PVs for your application:

  1. Add the azure-zrs storage class line under the volumeClaimTemplates section of your application deployment manifest, similar to the following example:  
...
volumeClaimTemplates:
- metadata:
name: datadir
annotations:
volume.beta.kubernetes.io/storage-class: azure-zrs
spec:
accessModes: [ "ReadWriteOnce" ]
resources:
requests:
storage: 1G
...
  1. In this recipe, we will deploy Redis Statefulset using the azure-zrs storage class. Review the YAML manifest under the src/chapter5/azure directory in the example repository before we execute it:
$ cat azure/redis-statefulset.yml
  1. Create the Redis StatefulSet:
$ kubectl apply -f redis-statefulset.yml
  1. Verify that pods have been created. In this recipe, our example has StatefulSet with three replicas. As a result, you should see three replicas running, similar to the following output:
$ kubectl get pods
NAME READY STATUS RESTARTS AGE
rd-0 1/1 Running 0 6m24s
rd-1 1/1 Running 0 4m14s
rd-2 1/1 Running 0 2m13s
  1. List the PVCs and PVs created. You should expect to see three PVCs and three PVs created, similar to our example output here:
$ kubectl get pvc, pv
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
datadir-rd-0 Bound pvc-afaafb97-d376-11e9-88a2-a2c82783dcda 1Gi RWO azure-zrs 4m31s
datadir-rd-1 Bound pvc-fc9f3a35-d376-11e9-88a2-a2c82783dcda 1Gi RWO azure-zrs 2m22s
datadir-rd-2 Bound pvc-453d185d-d377-11e9-88a2-a2c82783dcda 1Gi RWO azure-zrs 20s
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
pvc-453d185d-d377-11e9-88a2-a2c82783dcda 1Gi RWO Delete Bound default/datadir-rd-2 azure-zrs 22s
pvc-afaafb97-d376-11e9-88a2-a2c82783dcda 1Gi RWO Delete Bound default/datadir-rd-0 azure-zrs 4m42s
pvc-fc9f3a35-d376-11e9-88a2-a2c82783dcda 1Gi RWO Delete Bound default/datadir-rd-1 azure-zrs 2m38s

Now you know how to dynamically create persistent volumes as part of your application deployment on AKS clusters.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.227.190.211