skip to Main Content

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.

variables:
  volume_name: container1-pv
  pvc_name: container1-pvc
  config_map_name: container1-cm
  deployment: log_container1
  volume_handle: container1handle

I will create multiple sets of these variables to mount them.

now I want to pass these variable to the pv yaml file.

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 "Delete" 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

The command I am giving in ADO to create the pv.

kubectl create -f Pv/logs-pv.yml -n diag-logs

Please advise how to achieve this.

2

Answers


  1. Chosen as BEST ANSWER

    I added a sed command to replace as I was not able to get values.yaml to reference.

    cat pv.yaml | sed ... | sed ... >> /tmp/pv.yaml
    kubctl apply -f /tmp/pv.yaml
    

  2. You can use the Helm template option to loop through the single file which stores your data and you can create the YAML file.

    Helm template

    {{- $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 }}
    

    values.yaml

    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
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search