How can we create azure-disk based persistent volume claim and use them from a POD in Kubernetes?

10/2/2019

I am unable to find an example where the secret regarding Azure storage account can be passed during POD creation or PVC creation. An example will really help.I followed the examples here, but it didn't work.

-- Nipun Talukdar
azure
azure-aks
azure-kubernetes
kubernetes

2 Answers

10/2/2019

To use the Azure Disk as the persistent volumes, there are two forms, one is the dynamic disk and another is the static disk. You can follow the steps in Dynamic and Static to create persistent volumes based on the Azure Disk as you need.

-- Charles Xu
Source: StackOverflow

10/2/2019

create pvc:

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: azure-managed-disk
spec:
  accessModes:
  - ReadWriteOnce
  storageClassName: managed-premium
  resources:
    requests:
      storage: 5Gi

if you are using a really old AKS\or not AKS, you'd also need to create storage class:

apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: managed-premium
parameters:
  cachingmode: ReadOnly
  kind: Managed
  storageaccounttype: Premium_LRS
provisioner: kubernetes.io/azure-disk
reclaimPolicy: Delete
volumeBindingMode: Immediate

use pvc:

kind: Pod
apiVersion: v1
metadata:
  name: mypod
spec:
  containers:
  - name: mypod
    image: nginx:1.15.5
    resources:
      requests:
        cpu: 100m
        memory: 128Mi
      limits:
        cpu: 250m
        memory: 256Mi
    volumeMounts:
    - mountPath: "/mnt/azure"
      name: volume
  volumes: // this is where you reference the pvc
  - name: volume
    persistentVolumeClaim:
      claimName: azure-managed-disk
-- 4c74356b41
Source: StackOverflow