Storage Peristent

Storage option in Kubernetes that allows data to persist beyond the life of a Pod.

Persistent Storage allows data to survive container or pod terminations, enabling applications like databases to maintain their data over time. This contrasts with the ephemeral storage that is lost when a container or pod is terminated.

Mechanisms:

  • Persistent Storage utilizes Persistent Volumes (PVs) and Persistent Volume Claims (PVCs) to abstract storage resources from the underlying storage infrastructure.

Characteristics:

  • Persistent Volume (PV): Represents a piece of storage in the cluster.
  • Persistent Volume Claim (PVC): A request for storage by a user, acting as a mechanism to consume PVs.
  • Storage Classes: In Azure Kubernetes Service (AKS), storage classes define the type of storage provisioned, leveraging Azure Disk, Azure Files, Azure Blob Storage, or Azure NetApp Files.

Azure Storage Classes:

  • Azure Disk:
    • default: Standard storage class used by AKS, utilizes Azure Standard SSD.
    • managed premium: Employs Azure Premium SSDs.
  • Azure File:
    • azurefile: Uses standard Azure File Storage.
    • azurefile-premium: Uses premium Azure File Storage.
  • Blob Storage:
    • blob.csi.azure.com: Integrates Azure Blob Storage using the Blob CSI driver.
  • Azure NetApp Files:
    • netapp.io/azurenetapp-csi: Utilizes Azure NetApp Files as a storage class.

Use Cases:

  • Data Persistence: Essential for applications that require stable, reliable data storage like databases.
  • Stable Working Directory: When used as a working directory, it ensures data persistence across container restarts.

Configuration Examples:

  • Pod Configuration with PVC:

Here, a PVC named mypvc is used to mount persistent storage at /app/data in the container.

apiVersion: v1
kind: Pod
metadata:
 name: myapp-pod
spec:
 containers:
 - name: myapp-container
   image: myapp:1.0
   volumeMounts:
   - name: mypersistentvolume
     mountPath: /app/data
 volumes:
 - name: mypersistentvolume
   persistentVolumeClaim:
     claimName: mypvc
  • Persistent Volume Claim (PVC) Configuration:

This PVC requests 10GiB of storage from the managed-premium storage class (Azure Premium SSD).

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
 name: mypvc
spec:
 accessModes:
   - ReadWriteOnce
 storageClassName: managed-premium # Azure Premium SSD
 resources:
   requests:
     storage: 10Gi # 10GiB of storage
  • Pod with Working Directory and Mounted Volume:

Specifies /app as the working directory of the container and mounts persistent storage at /app/data.

apiVersion: v1
kind: Pod
metadata:
 name: myapp-pod
spec:
 containers:
 - name: myapp-container
   image: myapp:1.0
   workingDir: /app
   volumeMounts:
   - name: mypersistentvolume
     mountPath: /app/data
 volumes:
 - name: mypersistentvolume
   persistentVolumeClaim:
     claimName: mypvc
Last modified July 21, 2024: update (e2ae86c)