How to Create a PVC from Azure Files for Use in AKS

 

Creating a Persistent Volume Claim (PVC) from Azure Files for Azure Kubernetes Service (AKS)

In this guide, we'll walk through the process of creating a Persistent Volume Claim (PVC) from Azure Files to use with Azure Kubernetes Service (AKS). This will help you effectively manage storage for your applications.

Prerequisites

  • Set Up Azure CLI
  • Azure file share created (in this case: azurestorageaccountname=technexusdevops)
  • AKS cluster is created (in this case: nginx-cluster)

Steps to Create the PVC

1. Connect to the AKS Cluster

Download the cluster credentials to interact with it using kubectl:

      az aks get-credentials --resource-group 1-c6aa5250-playground-sandbox --name nginx-cluster
    
2. Create the Secret for Azure File Share

Link your file share with Kubernetes using Azure File. First, create a secret to store your Azure Storage account credentials:

Create the Secret

Run the following command to create a secret for your Azure Storage account:

      kubectl create secret generic sanginx-storage-secret \
  --from-literal=azurestorageaccountname=technexusdevops \
  --from-literal=azurestorageaccountkey=$(az storage account keys list \
  --resource-group 1-c6aa5250-playground-sandbox \
  --account-name technexusdevops \
  --query '[0].value' -o tsv)
    
Output:
        secret/sanginx-storage-secret created
      

Create Persistent Volume (PV)

Create a file named nginx-pv.yaml with the following content:

    apiVersion: v1
kind: PersistentVolume
metadata:
  name: nginx-pv
spec:
  capacity:
    storage: 5Gi
  accessModes:
    - ReadWriteMany
  azureFile:
    secretName: sanginx-storage-secret
    shareName: technexusdevops-fileshare
    readOnly: false
  persistentVolumeReclaimPolicy: Retain
  

Create Persistent Volume Claim (PVC)

Create a file named nginx-pvc.yaml with this content:

    apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: nginx-pvc
spec:
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 5Gi
  

Deploy NGINX Application

Create a deployment file nginx-deployment.yaml:

    apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
        - name: nginx
          image: nginx
          volumeMounts:
            - mountPath: "/usr/share/nginx/html"
              name: azurefile
      volumes:
        - name: azurefile
          persistentVolumeClaim:
            claimName: nginx-pvc
  

Expose NGINX Deployment Using a LoadBalancer Service

Create a file named nginx-service.yaml with the following content:

    apiVersion: v1
kind: Service
metadata:
  name: nginx-service
spec:
  type: LoadBalancer
  selector:
    app: nginx
  ports:
    - protocol: TCP
      port

Comments

Popular posts from this blog

Access Modes in Azure Kubernetes Service (AKS)

Deploy Apache Web Server Using Docker: A Step-by-Step Guide