<p>I have a requirement where I need to mount 20+ azure blob containers on AKS. Manually if I do it can be achieved by me writing 40+ files for pv and pvc. I have created a DevOps pipeline where I will have all the pv and pvc details in multiple variable files and want to pass them to yaml files which create the pv and pvc.</p>
<pre><code>variables:
  volume_name: container1-pv
  pvc_name: container1-pvc
  config_map_name: container1-cm
  deployment: log_container1
  volume_handle: container1handle
</code></pre>
<p>I will create multiple sets of these variables to mount them.</p>
<p>now I want to pass these variable to the pv yaml file.</p>
<pre><code>kind: PersistentVolume
apiVersion: v1
metadata:
  name: container1-pv # this is where I want to substitute the variable
spec:
  capacity:
    storage: 100Gi
  accessModes:
    - ReadWriteMany
  persistentVolumeReclaimPolicy: Retain  # If set as &quot;Delete&quot; container would be removed after pvc deletion
  mountOptions:
    - -o allow_other
    - --file-cache-timeout-in-seconds=30
  csi:
    driver: blob.csi.azure.com
    readOnly: false
    # make sure this volumeid is unique in the cluster
    # `#` is not allowed in self defined volumeHandle
    volumeHandle: container1-hande # one more place to substitute 
    volumeAttributes:
      containerName: container1 # one more place to substitute 
    nodeStageSecretRef:
      name: azure-secret
      namespace: logs
</code></pre>
<p>The command I am giving in ADO to create the pv.</p>
<pre><code>kubectl create -f Pv/logs-pv.yml -n diag-logs
</code></pre>
<p>Please advise how to achieve this.</p>

yasin mohammed
<p>You can use the <strong>Helm</strong> <strong>template</strong> option to loop through the <strong>single file</strong> which stores your data and you can create the <strong>YAML</strong> file.</p>
<p>Helm template</p>
<pre><code>{{- $volumes := .Values.variables }}
{{- range $volumes }}
---
apiVersion: v1
kind: PersistentVolume
metadata:
  name: {{ .pvc_name }}
  labels:
    name: {{ .volume_name }}
spec:
  name: {{ .volume_name }}
  csi:
    volumeHandle: {{ .volume_name }}
    volumeAttributes:
      containerName: {{ .deployment }}
{{- end }}
</code></pre>
<p>values.yaml</p>
<pre><code>variables:
  - volume_name: container1-pv
    pvc_name: container1-pvc
    config_map_name: container1-cm
    deployment: log_container1
    volume_handle: container1handle
  - volume_name: container2-pv
    pvc_name: container2-pvc
    config_map_name: container2-cm
    deployment: log_container2
    volume_handle: container2handle
</code></pre>
