Azure Kubernetes Storage
Managing storage effectively is crucial for stateful applications running on Azure Kubernetes Service (AKS). AKS integrates with various Azure storage services to provide persistent storage for your containers.
Persistent Storage Concepts
In Kubernetes, storage is managed through PersistentVolumes (PVs) and PersistentVolumeClaims (PVCs).
- PersistentVolume (PV): A piece of storage in the cluster that has been provisioned by an administrator or dynamically provisioned using Storage Classes. It's a cluster resource.
- PersistentVolumeClaim (PVC): A request for storage by a user. Pods consume storage through PVCs.
- StorageClass: Provides a way for administrators to describe the "classes" of storage they offer. Different classes might map to quality-of-service levels, backup policies, or arbitrary policies determined by the cluster administrators.
Azure Storage Options for AKS
AKS supports several Azure storage solutions:
Azure Disks
Azure Disks provide persistent, block-level storage volumes for your AKS nodes. They are ideal for workloads requiring low latency and high throughput, such as databases or traditional applications.
Supported Disk Types:
- Standard SSD: Cost-effective SSD-backed storage.
- Premium SSD: High-performance SSD-backed storage.
- Standard HDD: Low-cost, high-capacity HDD-backed storage.
- Ultra Disk: For I/O intensive workloads requiring configurable performance.
Dynamic Provisioning with Storage Classes:
AKS automatically creates Storage Classes for Azure Disks. You can use these to dynamically provision PVs.
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: managed-premium
provisioner: disk.csi.azure.com
parameters:
skuName: Premium_LRS
reclaimPolicy: Delete
volumeBindingMode: Immediate
Azure Files
Azure Files provides fully managed file shares that are accessible via the industry-standard Server Message Block (SMB) protocol. This is useful for scenarios where you need shared access to data across multiple pods or for lifting and shifting existing file-based applications.
Supported Protocols:
- SMB 3.0
Dynamic Provisioning with Storage Classes:
You can create Storage Classes to provision Azure Files shares dynamically.
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: azurefile-csi-premium
provisioner: file.csi.azure.com
parameters:
skuName: Premium_LRS
reclaimPolicy: Delete
volumeBindingMode: Immediate
Azure NetApp Files (ANF)
Azure NetApp Files is a high-performance file storage service that can be used with AKS for demanding enterprise workloads like SAP HANA, Oracle, and custom applications that require extreme performance and low latency.
Key Features:
- High throughput and IOPS
- Low latency
- Support for NFS and SMB protocols
For ANF integration, you'll typically need to set up ANF volumes in Azure and then use a CSI driver to make them available to AKS. Refer to Azure documentation for detailed setup steps.
Configuring Persistent Volume Claims
Once you have a StorageClass defined or available, you can create a PersistentVolumeClaim to request storage.
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: my-pvc
spec:
accessModes:
- ReadWriteOnce # For Azure Disks
# - ReadWriteMany # For Azure Files
storageClassName: managed-premium # Or your chosen StorageClass
resources:
requests:
storage: 10Gi
Using PVCs in Pods
Mount your PVC into your pod's containers.
apiVersion: v1
kind: Pod
metadata:
name: my-app-pod
spec:
containers:
- name: my-app-container
image: nginx
ports:
- containerPort: 80
volumeMounts:
- mountPath: "/app/data"
name: persistent-storage
volumes:
- name: persistent-storage
persistentVolumeClaim:
claimName: my-pvc # Reference your PVC