I wish to create Persistent Volumes across multiple zones.
There are two lists inside the data object, one for az's and the other for vol id's.
The structure is:
persistentVolume:
az:
- eu-west-2a
- eu-west-2b
- eu-west-2c
storageClassName: postgres
storage: 10Gi
accessModes: ReadWriteOnce
volumeID:
- vol-123
- vol-456
- vol-789
fsType: ext4
The Helm config:
{{- $fullName := include "postgres.fullname" $ -}}
{{- range .Values.persistentVolume }}
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: {{ $fullName }}
labels:
type: {{ $fullName }}
az: {{ .az }}
spec:
storageClassName: {{ .Values.persistentVolume.storageClassName }}
capacity:
storage: {{ .Values.persistentVolume.storage }}
accessModes:
- {{ .Values.persistentVolume.accessModes }}
awsElasticBlockStore:
volumeID: {{ .volumeID }}
fsType: {{ .Values.persistentVolume.fsType }}
{{- end }}
But this error with:
template: postgres/templates/pv.yaml:10:11: executing "postgres/templates/pv.yaml" at <.az>: can't evaluate field az in type interface {}
Any tips or pointers would be much appreciated :-)
It is not possible to do what you want with the current structure you have, but if you are willing to change your values.yaml a bit:
persistentVolume:
az:
- region: eu-west-2a
volumeID: vol-123
- region: eu-west-2b
volumeID: vol-456
- region: eu-west-2c
volumeID: vol-789
storageClassName: postgres
storage: 10Gi
accessModes: ReadWriteOnce
fsType: ext4
then you could do (simplified example, but I am sure you will get the idea):
{{- $storageClassName := .Values.persistentVolume.storageClassName }}
{{- $volumes := .Values.persistentVolume }}
{{- range $volumes.az }}
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: test
labels:
type: test
az: {{ .region }}
spec:
storageClassName: {{ $storageClassName }}
awsElasticBlockStore:
volumeID: {{ .volumeID }}
{{- end }}
Note the {{- $storageClassName := .Values.persistentVolume.storageClassName }}. You need to do this because helm has the notion of "scope", which you can read a lot more in the docs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With