'Create PV in AKS with terraform Using the default storage class

I want to create with terraform a PVC in AKS cluster using the default storage class that comes with the AKS cluster. Here the doc

If I do kubectl get sc i´m getting:

enter image description here

But not sure how to use terraform code to refere them. Was trying with:

resource "kubernetes_persistent_volume" "volume" {
  metadata {
    name = "${var.pv_name}"
  }
  spec {
    capacity {
      storage = "50Gi"
    }
    access_modes = ["ReadWriteOnce"]
    persistent_volume_source {
      azure_disk {
        caching_mode  = "None"
        disk_name     = "managed-premium"
        kind          = "Managed"
      }
    }
  }
}

but It´s saying: The argument "data_disk_uri" is required, but no definition was found.

I get that, it´s indicating that I should enter the URL of the disk from Azure portal, But in this case I didn´t created a disk in azure, using the storage class provided by AKS. Has somebody was able to create this in AKS before?



Solution 1:[1]

You can not create the PV with storage class only, because A StorageClass provides a way for administrators to describe the "classes" of storage they offer. Each StorageClass has a provisioner that determines what volume plugin is used for provisioning PVs. This field must be specified.

The Volume Plugin would be Azure Disk, Azure Files, AWSElasticBlockStore and many more you can refer the document for available volume plugin for Storage Class.

Each StorageClass contains the fields provisioner, parameters, and reclaimPolicy, which are used when a PersistentVolume belonging to the class needs to be dynamically provisioned.

apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: standard
provisioner: kubernetes.io/aws-ebs
parameters:
  type: gp3
reclaimPolicy: Retain
allowVolumeExpansion: true
mountOptions:
  - debug
volumeBindingMode: Immediate

The default storage class provisions a standard SSD Azure disk. A persistent volume claim (PVC) is used to automatically provision storage based on a storage class. In this case, a PVC can use one of the pre-created storage classes to create a standard or premium Azure managed disk.

So , Based on above Statement you need to create volume plugin like Azure DIsk, There is no option to Create PV in AKS with storage class without any volume plugin

Reference : https://kubernetes.io/docs/concepts/storage/storage-classes/

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 RahulKumarShaw-MT