Persistent volumes with Azure disks
A persistent volume represents a piece of storage that has been provisioned for use with Kubernetes pods. A persistent volume can be used by one or many pods and can be dynamically or statically provisioned. For more information on Kubernetes persistent volumes, see Kubernetes persistent volumes.
This document details using persistent volumes with Azure disks in an Azure Kubernetes Service (AKS) cluster.
An Azure disk can only be mounted with Access mode type ReadWriteOnce, which makes it available to only a single AKS node. If needing to share a persistent volume across multiple nodes, consider using Azure Files.
Built in storage classes
A storage class is used to define how a unit of storage is dynamically created with a persistent volume. For more information on Kubernetes storage classes, see Kubernetes Storage Classes.
Each AKS cluster includes two pre-created storage classes, both configured to work with Azure disks. The
default storage class provisions a standard Azure disk. The
managed-premium storage class provisions a premium Azure disk. If the AKS nodes in your cluster use premium storage, select the
Use the kubectl get sc command to see the pre-created storage classes.
NAME PROVISIONER AGE default (default) kubernetes.io/azure-disk 1h managed-premium kubernetes.io/azure-disk 1h
Create persistent volume claim
A persistent volume claim (PVC) is used to automatically provision storage based on a storage class. In this case, a PVC can use one of the pre-created storage classes to create a standard or premium Azure managed disk.
Create a file named
azure-premimum.yaml, and copy in the following manifest.
Take note that the
managed-premium storage class is specified in the annotation, and the claim is requesting a disk
5GB in size with
apiVersion: v1 kind: PersistentVolumeClaim metadata: name: azure-managed-disk annotations: volume.beta.kubernetes.io/storage-class: managed-premium spec: accessModes: - ReadWriteOnce resources: requests: storage: 5Gi
Create the persistent volume claim with the kubectl apply command.
kubectl apply -f azure-premimum.yaml
Using the persistent volume
Once the persistent volume claim has been created, and the disk successfully provisioned, a pod can be created with access to the disk. The following manifest creates a pod that uses the persistent volume claim
azure-managed-disk to mount the Azure disk at the
Create a file named
azure-pvc-disk.yaml, and copy in the following manifest.
kind: Pod apiVersion: v1 metadata: name: mypod spec: containers: - name: myfrontend image: nginx volumeMounts: - mountPath: "/mnt/azure" name: volume volumes: - name: volume persistentVolumeClaim: claimName: azure-managed-disk
Create the pod with the kubectl apply command.
kubectl apply -f azure-pvc-disk.yaml
You now have a running pod with your Azure disk mounted in the
/mnt/azure directory. This configuration can be seen when inspecting your pod via
kubectl describe pod mypod.
Learn more about Kubernetes persistent volumes using Azure disks.