Dela via


Tutorial - Deploy Azure Container Storage on an AKS cluster

This tutorial introduces Azure Container Storage and demonstrates how to deploy and manage container-native storage for applications running on Azure Kubernetes Service (AKS). If you don't want to deploy Azure Container Storage now, you can skip this tutorial and proceed directly to Deploy an application in AKS. You won't need Azure Container Storage for the basic storefront application in this tutorial series.

Azure Container Storage simplifies the management of stateful applications in Kubernetes by offering container-native storage tailored to a variety of workloads, including databases, analytics platforms, and high-performance applications.

By the end of this tutorial, you will:

  • Understand how Azure Container Storage supports diverse workloads in Kubernetes.
  • Explore multiple storage backend options to tailor storage to your application's needs.
  • Deploy Azure Container Storage on your AKS cluster and create a generic ephemeral volume.

Innan du börjar

In previous tutorials, you created a container image, uploaded it to an ACR instance, and created an AKS cluster. Start with Tutorial 1 - Prepare application for AKS to follow along.

  • This tutorial requires using the Azure CLI version 2.35.0 or later. Portal and PowerShell aren't currently supported for Azure Container Storage. Kontrollera din version med az --version. Information om hur du installerar eller uppgraderar finns i Installera Azure CLI. Om du använder Bash-miljön i Azure Cloud Shell är den senaste versionen redan installerad.
  • You must have an existing Linux-based AKS cluster with at least 3 nodes with Storage optimized VM SKUs or GPU accelerated VM SKUs. See Tutorial 3 - Create an AKS cluster.
  • Du behöver Kubernetes kommandoradsklient, kubectl. Det är redan installerat om du använder Azure Cloud Shell, eller så kan du installera det lokalt genom att köra az aks install-cli-kommandot.

Install the Kubernetes extension

Lägg till eller uppgradera till den senaste versionen av k8s-extension genom att köra följande kommando.

az extension add --upgrade --name k8s-extension

Connect to the cluster and check node status

If you're not already connected to your cluster from the previous tutorial, run the following commands. If you're already connected, you can skip this section.

  1. Kör följande kommando för att ansluta till klustret.

    az aks get-credentials --resource-group myResourceGroup --name myAKSCluster
    
  2. Kontrollera anslutningen till klustret med hjälp av kubectl get kommandot . Det här kommandot returnerar en lista över klusternoderna.

    kubectl get nodes
    
  3. Följande utdataexempel visar noderna i klustret. Kontrollera att statusen för alla noder visar Klar:

    NAME                                STATUS   ROLES   AGE   VERSION
    aks-nodepool1-34832848-vmss000000   Ready    agent   80m   v1.30.9
    aks-nodepool1-34832848-vmss000001   Ready    agent   80m   v1.30.9
    aks-nodepool1-34832848-vmss000002   Ready    agent   80m   v1.30.9
    

Choose a backing storage option

Azure Container Storage uses storage pools to provision and manage persistent and generic volumes. It offers a variety of back-end storage options for your storage pools, each suited for specific workloads. Selecting the right storage type is critical for optimizing workload performance, durability, and cost efficiency. For this tutorial, we'll use Ephemeral Disk with local NVMe as backing storage to create a generic ephemeral volume. However, we'll also explore the other backing storage options that allow you to create persistent volumes.

Ephemeral Disk

Ephemeral Disk utilizes local storage resources on the AKS nodes (either local NVMe or temp SSD). It offers low sub-ms latency and high IOPS, but no data persistence if the VM restarts. Ephemeral Disk is best suited for applications such as Cassandra that prioritize speed over persistence, and is ideal for workloads with their own application-level replication.

You can use Ephemeral Disk to create either generic ephemeral volumes or persistent volumes, even though the data will be lost if the VM restarts.

Azure Disks

Ideal for databases like PostgreSQL and MongoDB, Azure Disks offer durability, scalability, and multi-tiered performance options, including Premium SSD and Ultra SSD.

Azure Disks allow for automatic provisioning of storage volumes and include built-in redundancy and high availability.

Azure Elastic SAN (preview)

Designed for shared storage needs and general-purpose databases requiring scalability and high availability, Azure Elastic SAN is a good fit for workloads such as CI/CD pipelines or large-scale data processing.

Enable Azure Container Storage and create a storage pool

Run the following command to install Azure Container Storage on the cluster and create a Local NVMe storage pool.

az aks update -n myAKSCluster -g myResourceGroup --enable-azure-container-storage ephemeralDisk --storage-pool-option NVMe

The deployment should take less than 15 minutes.

Verify the storage pool status

When deployment completes, the components for your chosen storage pool type will be enabled, and you'll have a default storage pool.

Kör följande kommando för att hämta listan över tillgängliga lagringspooler:

kubectl get sp -n acstor

Kör följande kommando för att kontrollera statusen för en lagringspool:

kubectl describe sp <storage-pool-name> -n acstor

If the Message doesn't say StoragePool is ready, then your storage pool is still creating or ran into a problem.

Display the available storage classes

När lagringspoolen är redo att användas måste du välja en lagringsklass för att definiera hur lagring skapas dynamiskt när du skapar och distribuerar volymer.

Kör kubectl get sc för att visa tillgängliga lagringsklasser. Du bör se en lagringsklass med namnet acstor-<storage-pool-name>. Use this storage class in the next section to deploy a pod.

Deploy a pod with a generic ephemeral volume

Skapa en podd med Fio (flexibel I/O-testare) för benchmarking och arbetsbelastningssimulering, som använder en allmän tillfällig volym.

  1. Använd din favorittextredigerare för att skapa en YAML-manifestfil, code acstor-pod.yamltill exempel .

  2. Klistra in följande kod och spara filen.

    kind: Pod
    apiVersion: v1
    metadata:
      name: fiopod
    spec:
      nodeSelector:
        acstor.azure.com/io-engine: acstor
      containers:
        - name: fio
          image: nixery.dev/shell/fio
          args:
            - sleep
            - "1000000"
          volumeMounts:
            - mountPath: "/volume"
              name: ephemeralvolume
      volumes:
        - name: ephemeralvolume
          ephemeral:
            volumeClaimTemplate:
              metadata:
                labels:
                  type: my-ephemeral-volume
              spec:
                accessModes: [ "ReadWriteOnce" ]
                storageClassName: acstor-ephemeraldisk-nvme # replace with the name of your storage class if different
                resources:
                  requests:
                    storage: 1Gi
    

    If you change the storage size of the volume, make sure the size is less than the available capacity of a single node's ephemeral disk. Run kubectl get diskpool -n acstor to check the available capacity.

  3. Använd YAML-manifestfilen för att distribuera podden.

    kubectl apply -f acstor-pod.yaml
    

    Du bör se utdata som liknar följande:

    pod/fiopod created
    
  4. Check that the pod is running and that the ephemeral volume claim has been bound successfully to the pod:

    kubectl describe pod fiopod
    kubectl describe pvc fiopod-ephemeralvolume
    

You've now deployed a pod that's using local NVMe as its storage, and you can use it for your Kubernetes workloads.

Verify the available capacity of ephemeral disks before provisioning additional volumes:

kubectl describe node <node-name>

To learn more about Azure Container Storage, including how to create persistent volumes, see What is Azure Container Storage?

Rensa resurser

You won't need Azure Container Storage for the rest of this tutorial series, so we recommend deleting it now to avoid incurring unnecessary Azure charges.

  1. Delete the pod.

    kubectl delete pod fiopod
    
  2. Delete the storage pool.

    kubectl delete sp -n acstor <storage-pool-name>
    
  3. Delete the extension instance.

    az aks update -n myAKSCluster -g myResourceGroup --disable-azure-container-storage all
    

Nästa steg

In this tutorial, you deployed Azure Container Storage on your AKS cluster. Du har lärt dig att:

  • Enable Azure Container Storage on your AKS cluster.
  • Choose a backing storage type and create a storage pool.
  • Deploy a pod with a generic ephemeral volume.

In the next tutorial, you learn how to deploy an application to your cluster.