Managing Persistent Storage in Azure Kubernetes Service (AKS)

This tutorial series guides you through setting up and managing persistent storage for your stateful applications running on Azure Kubernetes Service (AKS). Persistent storage ensures that your data survives pod restarts and rescheduling.

Understanding Storage Concepts in Kubernetes

Kubernetes introduces several abstractions for managing storage:

Tutorials in this Series

1. Provisioning Storage with Azure Disk

Learn how to provision persistent storage using Azure Managed Disks. This is suitable for single-node access scenarios.

Read more about Azure Disk

2. Using Azure Files for Shared Storage

Discover how to use Azure Files for network file shares, enabling multiple pods to access the same storage simultaneously.

Read more about Azure Files

3. Dynamic Provisioning with Storage Classes

Understand how to leverage Storage Classes for on-demand provisioning of storage, allowing dynamic creation of PVs and PVCs.

Read more about Storage Classes

4. Snapshotting and Restoring Data

Explore techniques for creating snapshots of your persistent volumes and restoring them to recover data or create new volumes.

Read more about Snapshotting

Note: Always choose the storage solution that best fits your application's requirements for performance, access modes, and cost.

Provisioning Azure Disk

Azure Disk provides high-performance, persistent block storage. It can be attached to a single node at a time.

To use Azure Disk, you'll typically create a PersistentVolumeClaim that requests a specific type of Azure Disk (e.g., Premium SSD).


apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: azure-disk-pvc
spec:
  accessModes:
    - ReadWriteOnce # Can be mounted read-write by a single node
  storageClassName: managed-premium # Or managed-standard
  resources:
    requests:
      storage: 10Gi
            

This PVC will then be bound to a PersistentVolume backed by an Azure Managed Disk.

Using Azure Files

Azure Files offers fully managed cloud file shares that are accessible via the industry-standard Server Message Block (SMB) protocol. It supports multi-node access.

You can create an Azure File share and then reference it in a PersistentVolume, or use dynamic provisioning.


apiVersion: v1
kind: PersistentVolume
metadata:
  name: azure-files-pv
spec:
  capacity:
    storage: 50Gi
  accessModes:
    - ReadWriteMany # Can be mounted read-write by many nodes
  persistentVolumeReclaimPolicy: Retain
  storageClassName: azurefile-csi
  csi:
    driver: file.csi.azure.com
    volumeHandle: /myakscluster.file.core.windows.net/myshare
    volumeAttributes:
      shareName: myshare
      protocol: smb
            

Tip: For shared access to data across multiple pods, Azure Files is generally the preferred solution.

Dynamic Provisioning with Storage Classes

Storage Classes simplify storage management by allowing Kubernetes to automatically provision Persistent Volumes when a Persistent Volume Claim is created.

AKS provides default Storage Classes:

You can also create custom Storage Classes to define specific configurations.

Snapshotting and Restoring Data

Data protection is crucial. Azure Kubernetes Service integrates with Azure's snapshot capabilities.

To snapshot a volume, you typically use the Kubernetes VolumeSnapshot API. This requires enabling the CSI (Container Storage Interface) driver for snapshots and deploying the VolumeSnapshotter controller.

A VolumeSnapshot object references the PVC you want to snapshot:


apiVersion: snapshot.storage.k8s.io/v1
kind: VolumeSnapshot
metadata:
  name: my-snapshot
spec:
  volumeSnapshotClassName: azuredisk-csi-v1 # Or appropriate snapshot class
  source:
    persistentVolumeClaimName: azure-disk-pvc
            

Once a snapshot is created, you can use it to provision a new PersistentVolumeClaim, effectively restoring the data.

Explore the linked Azure documentation for detailed examples and advanced configurations.