Jun 4, 2024
Configuring storage for AKS – Creating and Configuring Containers

Configuring storage for AKS

AKS enables different storage options available for containers; you can leverage either local (non-persistent) storage or shared storage (persistent storage) for your containers through AKS. For persistent storage options, you can leverage Azure Managed Disks, which is primarily focused on premium storage solutions, such as for fast input/output (I/O) operations, as we discussed in Chapter 6, Understanding and Managing Storage. Azure File Shares is another option available and the default storage mechanism for enabling persistent storage on containers. This is typically cheaper to deploy and provides decent levels of performance for most workloads. For better performance, premium file shares can be used. Azure File Shares is also great for sharing data between containers and other services, whereas a managed disk will be restricted to a single Pod but is easier to deploy.

The following diagram illustrates the different storage options available:

Figure 11.50 – Kubernetes: Storage layers

In this exercise, we will configure shared storage using Azure File Shares in your AKS cluster. Proceed as follows:

  1. Sign in to the Azure portal at https://portal.azure.com.
  2. Create a storage account and a file share named fileshare01. Once created, note the primary storage account key.
  3. Launch Azure Cloud Shell and run the following commands. Replace the resource group name with your name and the AKS cluster name for the Name field:

Az login

Install-AzAksKubectl

Import-AzAksCredential -ResourceGroupName AZ104-Chapter11 -Name myfirstakscluster

  1. Modify the following script with your storage account name and storage account key, then paste it into Cloud Shell and press Enter:

kubectl create secret generic azure-secret –from-literal =azurestorageaccountname=storageaccountname –from-litera l=azurestorageaccountkey=storageaccountkey

  1. Navigate to the AKS cluster you created in the previous section. Click on Storage on the left menu, then ensure you are on thePersistent volume claims tab, and click Add, as illustrated in the following screenshot:

Figure 11.51 – Adding a persistent volume claim

  1. Click Add with YAML, as illustrated in the following screenshot:

Figure 11.52 – Add with YAML

  1. Paste or type the following YAML document into the window:

apiVersion: v1

kind: PersistentVolume

metadata:

name: azurefile

spec:

capacity:

storage: 5Gi

accessModes:

  • ReadWriteMany azureFile:

secretName: azure-secret

shareName: fileshare01

readOnly: false mountOptions:

  • dir_mode=0777
  • file_mode=0777
  • uid=1000
  • gid=1000
  • mfsymlinks
  • nobrl

Then, click Add, as illustrated in the following screenshot. Thiswill create your persistent volume:

Figure 11.53 – Adding a persistent volume using YAML

  1. Now, to create a persistent volume claim, click Add again, and paste the following YAML. Click Add:

apiVersion: v1

kind: PersistentVolumeClaim

metadata:

name: azurefile

spec:

accessModes:

  • ReadWriteMany storageClassName: “” resources:

requests: storage: 5Gi

  1. You now have a persistent volume claim. Click on the Persistent volume claims tab, as illustrated in the following screenshot:

Figure 11.54 – Persistent volume claims tab

  1. Note your persistent volumes by clicking on the Persistent volumes tab, as illustrated in the following screenshot:

Figure 11.55 – Persistent volumes tab

You have successfully added persistent storage to your AKS cluster. You now know the tasks involved to achieve this goal. In the next section, we will explore AKS scaling.

More Details

Leave a Reply

Your email address will not be published. Required fields are marked *