0

I am learning kubernetes(AKS),

I am playing around azure. I have a scenario where I need to create multiple file share in azure storage account and I am able to create with set of commands but the twist is I need to create those dynamically as per requirement .

Example: I have two application both need azure storage account, instead of creating two different storage account I can create two file share under same storage account. Here I want to create file share dynamically as the application started to deploy. Because I might need 2nd application or may be I can start third application. So instead of creating multiple file share before I want to create those as per requirement.

After googling I found this article, but here also share name must be created in storage account already.

My question is, Is it achievable? If yes?

Update

YML for storageClass and PersistentVolumeClaim

---
kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
  name: mystorageclass
provisioner: kubernetes.io/azure-file
mountOptions:
  - dir_mode=0777
  - file_mode=0777
  - uid=1000
  - gid=1000
parameters:
  skuName: Standard_LRS
  storageAccount: mystrg
  location: eastus

---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: mypvc
spec:
  accessModes:
    - ReadWriteMany
  storageClassName: mystorageclass
  resources:
    requests:
      storage: 5Gi

storageClass created successfully but PersistentVolumeClaim status is pending with error resource storageAccount not found. It tries to find storageAccount under resource-group which is created by kubernetes?

Hitesh Ghuge
  • 793
  • 2
  • 10
  • 39

1 Answers1

2

The short answer is Yes. When you use the persistent volume in AKS dynamic created from the Azure File Share, you can create the storage account before, then you can use that storage account in the storage class like this:

kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
  name: azurefile
provisioner: kubernetes.io/azure-file
mountOptions:
  - dir_mode=0777
  - file_mode=0777
  - uid=1000
  - gid=1000
parameters:
  skuName: Standard_LRS
  storageAccount: azureaksstore
  location: eastus

And when you create the PVC with this SC, Azure will create the file share in this storage account for you. It shows like below in the storage account:

enter image description here

For more details, see Dynamically create and use a persistent volume with Azure Files in Azure Kubernetes Service (AKS).

Charles Xu
  • 29,862
  • 2
  • 22
  • 39
  • I have created `storageClass` and tried to claim with PVC, it fails by saying resource `storage` not found under `resource group`. Do I need to specify which resource group need to use? – Hitesh Ghuge Jul 15 '19 at 09:49
  • @HiteshGhuge No, I said it in the answer. You need to create the storage account first and then use the quote the storage account name in the SC yaml file. – Charles Xu Jul 15 '19 at 09:51
  • Yes... I have created `storage account` under `resource-group`. but when I debug the error it tries to find resource `storage` under another `resource-group` which is created by `kubernetes` – Hitesh Ghuge Jul 15 '19 at 10:05
  • 1
    @HiteshGhuge You should create the storage account in the group which the AKS cluster created. For me, it's `MC_charlesContainer_azureaks_eastus`.Take a look at [here](https://learn.microsoft.com/en-us/azure/aks/faq#why-are-two-resource-groups-created-with-aks). – Charles Xu Jul 16 '19 at 01:13
  • Yes.. it was searching in that group only... works by creating `storage account` in resource group `MC_myresource_myaks_eastus`. And another way is create `PersistentVolume` with same `share-file` and pass to `PVC`. works like champ – Hitesh Ghuge Jul 16 '19 at 04:39
  • If I want to create another `PV/PVC` do I need to create another `storageClass` or existing `storageClass` will work? – Hitesh Ghuge Jul 17 '19 at 05:45
  • @HiteshGhuge No, you just need to create the PV/PVC. Unless you need to change something different from the existing SC. – Charles Xu Jul 17 '19 at 06:09