Exercise Overview: This exercise focuses on utilizing dynamic volumes in Azure Kubernetes Service (AKS). You'll go through the process of creating a resource group, provisioning a service principal, setting up an AKS cluster, and implementing dynamic volumes using Azure Disk and Azure File.
- Azure Subscription
- Azure CLI
- SSH Key Pair
Solution
Creates an Azure Resource Group for organizing and managing resources.
az group create --location westeurope --resource-group demo-weu-rg
Generates a Service Principal for AKS with the necessary permissions.
az ad sp create-for-rbac --skip-assignment -n "spn-aks"
NOTE: Replace placeholders in --subscription
, --service-principal
, and --client-secret
with actual values.
Deploys an AKS cluster with specified configurations.
az aks create \
--location westeurope \
--subscription <Your-Subscription-ID> \
--resource-group demo-weu-rg \
--name <Your-AKS-Cluster-Name> \
--ssh-key-value $HOME/.ssh/id_rsa.pub \
--service-principal "<Your-Service-Principal-ID>" \
--client-secret "<Your-Client-Secret>" \
--network-plugin kubenet \
--load-balancer-sku standard \
--outbound-type loadBalancer \
--node-vm-size Standard_B2s \
--node-count 1 \
--tags 'ENV=Demo' 'OWNER=Corporation Inc.'
Retrieves and merges the AKS cluster's kubeconfig into the local environment.
az aks get-credentials \
--resource-group demo-weu-rg \
--name <Your-AKS-Cluster-Name> \
--admin
Implement a Persistent Volume Claim (PVC) for Azure Disk and mount it within a pod.
kubectl apply -f files/pvc-azure-managed-disk.yaml
kubectl apply -f files/pod-disk.yaml
Verify that the PVC is bound and the Pod is running.Ensure the PVC is in a Bound
state and the Pod is in a Running
state.
kubectl get pvc
kubectl get pods
Enter the Pod to verify if the Azure Disk is mounted correctly. Replace <pod-name>
with the actual name of your Pod.
kubectl exec -it <pod-name> -- /bin/bash
Inside the Pod, check if the Azure Disk is mounted:
df -h
Set up Persistent Volume Claims (PVCs) for Azure File and mount them in respective pods.
kubectl apply -f files/pvc-azurefile-001.yaml
kubectl apply -f files/pvc-azurefile-002.yaml
kubectl apply -f files/pod-file-001.yaml
kubectl apply -f files/pod-file-002.yaml
Verify that the PVCs are bound, and the Pods are running. Ensure the PVCs are in a Bound
state, and the Pods are in a Running
state.
kubectl get pvc
kubectl get pods
Enter the Pods to verify if the Azure Files are mounted correctly. Replace <pod-file-001-name>
and <pod-file-002-name>
with the actual names of your Pods.
kubectl exec -it <pod-file-001-name> -- /bin/bash
kubectl exec -it <pod-file-002-name> -- /bin/bash
Inside the Pods, check if the Azure Files are mounted
df -h
Deletes the resource group and associated resources.
az group delete -n demo-weu-rg --yes --no-wait